The grammar
exp → id | exp exp
is ambiguous because there are two different parse trees for id id id
. In general, CFGs with productions of the form S → SS will be ambiguous as long as the S nonterminal is reachable from the start symbol. Since no ambiguous grammar is LALR(1), the parser will find either a shift/reduce or reduce/reduce conflict.
To fix this, try changing your grammar to
exp → id | id exp
This grammar is unambiguous, which should resolve the issue.
Hope this helps!