我正在与野牛语法首次广泛合作。我有我的语法设置和一个测试套件来关联结果。野牛语法偶尔会通过,偶尔会失败
有时,测试套件通过:
Reducing stack by rule 101 (line 613):
$1 = nterm mathenv()
-> $$ = nterm closedTerm()
Stack now 0 5 3
Entering state 120
Reading a token: Next token is token ENDMATH()
Reducing stack by rule 28 (line 517):
$1 = nterm closedTerm()
-> $$ = nterm compoundTerm()
Stack now 0 5 3
Entering state 119
Reducing stack by rule 12 (line 333):
$1 = nterm compoundTerm()
-> $$ = nterm compoundTermList()
Stack now 0 5 3
Entering state 198
Next token is token ENDMATH()
Shifting token ENDMATH()
Entering state 325
... continues to completion ...
偶尔,它不:
Reducing stack by rule 101 (line 613):
$1 = nterm mathenv()
-> $$ = nterm closedTerm()
Stack now 0 5 3
Entering state 120
Reading a token: Next token is token MN()
Reducing stack by rule 28 (line 517):
$1 = nterm closedTerm()
-> $$ = nterm compoundTerm()
Stack now 0 5 3
Entering state 119
Reducing stack by rule 12 (line 333):
$1 = nterm compoundTerm()
-> $$ = nterm compoundTermList()
Stack now 0 5 3
Entering state 198
Next token is token MN()
Shifting token MN()
Entering state 11
... errors eventually ...
Now at end of input.
Line: 9 Error: syntax error at token
ENDMATH
是正确的令牌转移到,但有时,MN
被确定。每当我运行我的测试时,都会得到不一致的结果。这种“随机”歧义是否正常?什么可能导致它?我应该定义一些%precedence
规则吗?
截至y.output上,我看到几个矛盾的状态,像
State 0 conflicts: 3 shift/reduce
State 120 conflicts: 2 shift/reduce
State 127 conflicts: 2 shift/reduce
State 129 conflicts: 2 shift/reduce
State 154 conflicts: 1 shift/reduce
State 207 conflicts: 3 shift/reduce
State 265 conflicts: 109 shift/reduce
State 266 conflicts: 109 shift/reduce
State 267 conflicts: 109 shift/reduce
State 268 conflicts: 109 shift/reduce
State 269 conflicts: 109 shift/reduce
State 342 conflicts: 2 shift/reduce
State 390 conflicts: 109 shift/reduce
State 391 conflicts: 109 shift/reduce
State 396 conflicts: 1 shift/reduce
State 397 conflicts: 1 shift/reduce
是否可取消除所有这些冲突?注意,状态120被列为具有冲突,并且是在该随机错误发生之前的状态。
词法分析器确定哪些标记被识别 - 解析器只使用这些标记。如果您从词法分析器中获得不一致的令牌,那么这对于词法分析器来说是一个问题,并且分析器是无关紧要的。 – 2014-09-21 22:03:57