This grammar has given me conflict despite specifying precedence of operators. Even in the Dragon book it's been resolved in such a way(the way implemented as first 7 lines below) but it still gets conflict! Below is the code implemented in yacc
%right THEN_KW
%right ELSE_KW
%left XOR_KW OR_KW
%right '='
%left AND_KW ALSO_KW
%left EQ_KW LT_KW GT_KW LE_KW GE_KW
%left PLUS_KW MINUS_KW
%left MULT_KW DIV_KW MOD_KW
%right NOT_KW
arthlogicexpr -> operand | arthlogicexpr arthop arthlogicexpr
arthop -> '+' | '-' | '*' | '/' |'%'
operand -> variable
variable -> IDENTIFIER
erro in parser.output is :
state 141
78 arthlogicexpr: arthlogicexpr . arthop arthlogicexpr
78 | arthlogicexpr arthop arthlogicexpr .
'+' shift, and go to state 103
'-' shift, and go to state 104
'*' shift, and go to state 105
'/' shift, and go to state 106
'%' shift, and go to state 107
'+' [reduce using rule 78 (arthlogicexpr)]
'-' [reduce using rule 78 (arthlogicexpr)]
'*' [reduce using rule 78 (arthlogicexpr)]
'/' [reduce using rule 78 (arthlogicexpr)]
'%' [reduce using rule 78 (arthlogicexpr)]
$default reduce using rule 78 (arthlogicexpr)
arthop go to state 109
more info about other states :
state 103
79 arthop: '+' .
$default reduce using rule 79 (arthop)
state 104
80 arthop: '-' .
$default reduce using rule 80 (arthop)
state 105
81 arthop: '*' .
$default reduce using rule 81 (arthop)
state 106
82 arthop: '/' .
$default reduce using rule 82 (arthop)
state 107
83 arthop: '%' .
$default reduce using rule 83 (arthop)