以下简单语法来解析在降低/减少冲突的逻辑表达式的结果:
%token AND OR
%token NUMBER VARIABLE
%%
logical_expr
: logical_expr AND logical_term
| logical_expr OR logical_term
| logical_term
;
logical_term
: VARIABLE
| comparison
| '(' logical_expr ')'
;
comparison
: expr '<' expr
| expr '>' expr
;
expr
: expr '+' term
| expr '-' term
| term
;
term
: NUMBER
| VARIABLE
| '(' expr ')'
;
%%
从野牛状态报告有:
state 2
4 logical_term: VARIABLE .
13 term: VARIABLE .
')' reduce using rule 4 (logical_term)
')' [reduce using rule 13 (term)]
'<' reduce using rule 13 (term)
'>' reduce using rule 13 (term)
'+' reduce using rule 13 (term)
'-' reduce using rule 13 (term)
$default reduce using rule 4 (logical_term)
我猜问题是,它不能找出如何解析“(A)+ 1 <2”。 怎样才能消除歧义这个语法? 可能吗?