The below grammar and the semantic rules are fed to a yacc tool (which is an LALR (1) parser generator) for parsing and evaluating arithmetic

The below 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?
Code:
 E -> number   Eval           number val 
     E         E .val         E .VAL           E .val 
    E # E      E .val         E .VAL           E .val 
     ;
A. It detects recursion and eliminates recursion
B. It detects reduce-reduce conflict and resolves
C. It detects shift-reduce conflict and resolves the conflict in favor of a shift over a reduce action
D. It detects shift-reduce conflict and resolves the conflict in favor of a reduce over a shift action
 
Answer: c
Explanation: 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.
 

Tìm kiếm

Back
Top