编译原理 语法分析器 求LR分析表
编程语言语法的描述
program ? compoundstmt
stmt ? ifstmt | whilestmt | assgstmt | compoundstmt
compoundstmt ? { stmts }
stmts ? stmt stmts | ?
ifstmt ? if ( boolexpr ) then stmt else stmt
whilestmt ? while ( boolexpr ) stmt
assgstmt ? ID = arithexpr ;
boolexp ? arithexpr boolop arithexpr
boolop ? < | > | <= | >= | ==
arithexpr ? multexpr arithexprprime
arithexprprime ? + multexpr arithexprprime | - multexpr arithexprprime | ?
multexpr ? simpleexpr multexprprime
multexprprime ? * simpleexpr multexprprime | / simpleexpr multexprprime | ?
simpleexpr ? ID | NUM | ( arithexpr )
[解决办法]
yacc + lex,没事的话可以试试
你有兴趣的话,antlr来做也很简单
手工做语法树确实比较累
[解决办法]