如何debug bison和flex写的程序
|
具体的code请参见:http://www.voidcn.com/article/p-rodfeair-bkh.html 只不过有两步需要修改: bison -y -d parser.l --> bison -y -d -t parser.l gcc y.tab.o lex.yy.o -o plusmins.exe -->gcc -g lex.yy.o y.tab.o -o plusminis.exe 以下是debug的屏幕输出: gdb plusminis.exe ---------------------------- ------------------------- Reading a token: s 使用bison -y -d -t -v parser.l产生的状态机parser.output State 8 conflicts: 2 shift/reduce
State 9 conflicts: 2 shift/reduce
Grammar
0 $accept: program $end
1 program: program expr 'n'
2 | /* empty */
3 expr: INTEGER
4 | expr '+' expr
5 | expr '-' expr
Terminals,with rules where they appear
$end (0) 0
'n' (10) 1
'+' (43) 4
'-' (45) 5
error (256)
INTEGER (258) 3
Nonterminals,with rules where they appear
$accept (7)
on left: 0
program (8)
on left: 1 2,on right: 0 1
expr (9)
on left: 3 4 5,on right: 1 4 5
state 0
0 $accept: . program $end
$default reduce using rule 2 (program)
program go to state 1
state 1
0 $accept: program . $end
1 program: program . expr 'n'
$end shift,and go to state 2
INTEGER shift,and go to state 3
expr go to state 4
state 2
0 $accept: program $end .
$default accept
state 3
3 expr: INTEGER .
$default reduce using rule 3 (expr)
state 4
1 program: program expr . 'n'
4 expr: expr . '+' expr
5 | expr . '-' expr
'n' shift,and go to state 5
'+' shift,and go to state 6
'-' shift,and go to state 7
state 5
1 program: program expr 'n' .
$default reduce using rule 1 (program)
state 6
4 expr: expr '+' . expr
INTEGER shift,and go to state 3
expr go to state 8
state 7
5 expr: expr '-' . expr
INTEGER shift,and go to state 3
expr go to state 9
state 8
4 expr: expr . '+' expr
4 | expr '+' expr .
5 | expr . '-' expr
'+' shift,and go to state 6
'-' shift,and go to state 7
'+' [reduce using rule 4 (expr)]
'-' [reduce using rule 4 (expr)]
$default reduce using rule 4 (expr)
state 9
4 expr: expr . '+' expr
5 | expr . '-' expr
5 | expr '-' expr .
'+' shift,and go to state 7
'+' [reduce using rule 5 (expr)]
'-' [reduce using rule 5 (expr)]
$default reduce using rule 5 (expr)
refs: http://www.gnu.org/software/bison/manual/html_node/Understanding.html ???????? http://epaperpress.com/lexandyacc/pry1.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
