Direction: Consider the following expression grammar. The semantic rules for expression evaluation are stated next to each grammar production.
E → number | E.val = number.val |
| E ‘+’ E | E(1).val = E(2).val + E(3).val |
| E ‘×’ E | E (1).val = E(2).val × E(3).val |
-
The above grammar and the semantic rules are fed to a yacc tool (which is an LALR (1) parser generator) for parsing and evaluating arithmetic expressions. Which one of the following is true about the action of yacc for the given grammar?
-
- It detects recursion and eliminates recursion
- It detects reduce-reduce conflict and resolves
- It detects shift-reduce conflict and resolves the conflict in favour of a shift over a reduce action
- It detects shift reduce conflict, and resolves the conflict in favour of a reduce over a shift action
- It detects recursion and eliminates recursion
Correct Option: C
Yacc tool is used to create a LALR(1) parser. This parser can detect the conflicts but to resolve the conflicts it actually prefers shift over reduce action.