reduce-reduce-conflict

bison shift instead of reduce. With reduce/reduce errors

拥有回忆 提交于 2019-12-21 22:32:40
问题 In my language i can write a = 1 b = 2 if true { } else { } if true { } **Here is the problem** else {} My grammer doesnt support newlines between statements. An else can only be used with an if. When i add optionalNL in my rule IfExpr: IF rval optionalNL codeBlock optionalNL ELSE codeBlock | IF rval optionalNL codeBlock The optionalNL before the else causes 3 reduce/reduce. Reason is it can reduce using the 2nd rule in IfExpr or reduce to exprLoop where it allows many newlines between

Simple ambiguous grammar with reduce-reduce conflict

独自空忆成欢 提交于 2019-12-11 03:24:43
问题 The following simple grammar to parse a logical expression results in a reduce/reduce conflict: %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 ')' ; %% The status report from bison has: state 2 4 logical_term: VARIABLE .

bison shift instead of reduce. With reduce/reduce errors

天涯浪子 提交于 2019-12-04 17:38:26
In my language i can write a = 1 b = 2 if true { } else { } if true { } **Here is the problem** else {} My grammer doesnt support newlines between statements. An else can only be used with an if. When i add optionalNL in my rule IfExpr: IF rval optionalNL codeBlock optionalNL ELSE codeBlock | IF rval optionalNL codeBlock The optionalNL before the else causes 3 reduce/reduce. Reason is it can reduce using the 2nd rule in IfExpr or reduce to exprLoop where it allows many newlines between expressions. No matter what i do (i tried writing %prec before optionalNL and ELSE) it always reduces to