저는 처음으로 Bison 문법으로 광범위하게 연구하고 있습니다. 문법을 설정하고 결과를 연관시키는 약간의 테스트 슈트가 있습니다.때때로 Bison 문법이 가끔 가끔씩 실패합니다.
때때로, 테스트 스위트는 전달합니다
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)는 충돌이있는 것으로서 나열되고,이 랜덤 에러가 발생하기 바로 직전의 상태이다.
렉서는 인식되는 토큰을 결정합니다. 파서는 단지 토큰을 사용합니다. 렉서에서 일치하지 않는 토큰을 얻는다면 그것은 렉서의 문제점이며 파서는 부적합합니다. –