Home » Compiler Design » Compiler design miscellaneous » Question

Compiler design miscellaneous

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

  1. 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?
    1. It detects recursion and eliminates recursion
    2. It detects reduce-reduce conflict and resolves
    3. It detects shift-reduce conflict and resolves the conflict in favour of a shift over a reduce action
    4. It detects shift reduce conflict, and resolves the conflict in favour of a reduce over a shift action
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.



Your comments will be displayed only after manual approval.