逻辑表达式解析器已完成

逻辑表达式解析器写好啦。

期间看了看《编译原理》书的第二章, 学习了如何手写Lexer和Parser(之前写的是用ANTLR生成的)。

然后生成了抽象语法树之后就处理、化简一下。

然后后序遍历这棵树, 生成逆波兰表达式。

之后就枚举各个变量的值, 输出真值表。

然后根据真值表, 可以很轻易写出主析取范式、主合取范式了。

源代码在https://github.com/twd2/LogicCalc, 发布在https://github.com/twd2/LogicCalc/releases/tag/v0.1, 选择了静态编译, 应该不需要运行库。

然而, fb在昨天随手就写了个: https://github.com/foreverbell/logic-expression

发表评论?

2 条评论。

  1. :mrgreen: :mrgreen: :mrgreen: 夜夜的模拟赛 发题解啊

回复给 sxb_201 ¬
取消回复

注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)

本文链接:https://twd2.me/archives/7747QrCode