Bison 解析器:冲突处理与状态管理
1. 纯解析器与线程程序
纯解析器在线程程序中很有用,每个线程可能从不同的源解析输入。
2. y.output 文件
Bison 可以创建一个日志文件,传统上命名为 y.output,现在更多地命名为 name.output,它显示解析器中的所有状态以及状态之间的转换。使用 --report=all 标志生成日志文件。
以下是第 1 章中 Bison 语法日志的一部分:
state 3
10 term: NUMBER .
$default reduce using rule 10 (term)
state 4
11 term: ABS . term
NUMBER shift, and go to state 3
ABS shift, and go to state 4
term go to state 9
state 5
2 calclist: calclist calc . EOL
EOL shift, and go to state 10
每个状态中的点表示解析器到达该状态时解析规则的进度。例如,当解析器处于状态 4 时,如果看到 NUMBER 标记,它会将 NUMBER 移到栈上并切换到状态 3;如果看到 ABS ,则移至状态 4;其他标记则为错误。若后续归约使栈顶为 term <
超级会员免费看
订阅专栏 解锁全文
3

被折叠的 条评论
为什么被折叠?



