Bison : shift-reduce conflicts even though %left %right directive

75 Views Asked by At

I know that most of the shift/reduce conflicts can be solved by using %left or %right directives. But even with that, I am getting conflicts. Following is a block of my grammar:

expression:    variable '=' expression
          |    expression operator expression
          |    '-' expression    %prec UMINUS
          |    '(' expression ')'
          |    value_holder
;

operator:    relational_operator
        |    arithmetic_operator
;

relational_operator:    LESS
                   |    GREATER
                   |    LESS_OR_EQUAL
                   |    GREATER_OR_EQUAL
                   |    EQUAL
                   |    NOT_EQUAL
;

arithmetic_operator:    '+'
                   |    '-'
                   |    '*'
                   |    '/'
                   |    '%'
;

I have precedence and associativity directives like following:

%right '='

%left EQUAL NOT_EQUAL
%left LESS LESS_OR_EQUAL GREATER GREATER_OR_EQUAL

%left '+' '-'
%left '*' '/'
%left '%'

%right UMINUS

Still it's giving 11 shift-reduce errors. Here is the state 84 which is giving these errors.

State 84

33 expression: expression . operator expression
33           | expression operator expression .

EQUAL             shift, and go to state 56
NOT_EQUAL         shift, and go to state 57
LESS              shift, and go to state 58
LESS_OR_EQUAL     shift, and go to state 59
GREATER           shift, and go to state 60
GREATER_OR_EQUAL  shift, and go to state 61
'+'               shift, and go to state 62
'-'               shift, and go to state 63
'*'               shift, and go to state 64
'/'               shift, and go to state 65
'%'               shift, and go to state 66

EQUAL             [reduce using rule 33 (expression)]
NOT_EQUAL         [reduce using rule 33 (expression)]
LESS              [reduce using rule 33 (expression)]
LESS_OR_EQUAL     [reduce using rule 33 (expression)]
GREATER           [reduce using rule 33 (expression)]
GREATER_OR_EQUAL  [reduce using rule 33 (expression)]
'+'               [reduce using rule 33 (expression)]
'-'               [reduce using rule 33 (expression)]
'*'               [reduce using rule 33 (expression)]
'/'               [reduce using rule 33 (expression)]
'%'               [reduce using rule 33 (expression)]
$default          reduce using rule 33 (expression)

operator             go to state 68
relational_operator  go to state 69
arithmetic_operator  go to state 70

I am unable to figure out why the directives are not working.

If needed, this is the parser file : parser.y

Edit : file parser.y has been removed.

0

There are 0 best solutions below