## Parsres

 Question 1
An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if
 A the SLR(1) parser for G has S-R conflicts B the LR(1) parser for G has S-R conflicts C the LR(0) parser for G has S-R conflicts D the LALR(1) parser for G has reduce-reduce conflicts
Compiler-Design       Parsres       Gate-2008
Question 1 Explanation:
LALR(1) parser is obtained by minimising the LR(1) parser and hence they both uses LR(1) items. Now consider if LR(1) parser has SR conflict, for ex:
Consider a state in LR(1) parser:
S-> x.yA, a
A-> x. , y
This has both shift and reduce conflict on symbol “y”.
Since LR(1) already has SR conflict , so resulting LALR(1) (after merging) will also have SR conflict.
Now if LR(1) doesn’t have SR conflict then it is guaranteed that the LALR(1) will never have SR conflict. The reason behind this is, as we merge those state only which has same set of canonical items except look ahead and the LR(1) canonical items has DFA (means from one state to other state the transition is from unique symbol) , so after merging also we will never see any shift conflict, only reduce-reduce may occur.
Hence An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if the LR(1) parser for G has S-R conflicts.
 Question 2
Consider the following expression grammar. The seman­tic rules for expression calculation 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?
 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
Compiler-Design       Parsres       Gate-2005
Question 2 Explanation:
Yacc favours shift move in case of SR conflict.
There are 2 questions to complete.