Parsing: GATE CS Previous Year Questions

Parsing · Compiler Design

58 questions · asked in 25 of 27 years (2000–2026)

MCQ 46 · MSQ 5 · NAT 71-mark 39 · 2-mark 19

2000Questions per year2026

Questions 46–50 of 58

Q46GATE 20051 markMCQ−0.33 if wrong
Consider the context-free grammar
E→E+EE\rightarrow E+E
E→(E∗E)E\rightarrow (E *E)
E→idE\rightarrow \text{id}
where E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of non-terminals is {E}.
For the terminal string id + id + id + id, how many parse trees are possible?

Q47GATE 20051 markMCQ−0.33 if wrong
Consider the context-free grammar
E→E+EE\rightarrow E+E
E→(E∗E)E\rightarrow (E *E)
E→idE\rightarrow \text{id}
where E is the starting symbol, the set of terminals is {id,(,+,),∗}\{id, (,+,),*\}, and the set of nonterminals is {E}. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?

Q48GATE 20051 markMCQ−0.33 if wrong
Consider the following expression grammar. The semantic 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

Assume the conflicts of this question are resolved usinf yacc tool and an LALR(1) parser is generated for parsing arithmetic expressions as per the given grammar. Consider an expression 3 x 2 + 1. What precedence and associativity properties does the generated parser realize?

Q49GATE 20051 markMCQ−0.33 if wrong
Consider the following expression grammar. The semantic rules for expression calculation are stated next to each grammar production.
E→ numberE.val = number.val
    | E ‘+’ EE(1).val = E(2).val + E(3).val
    | E ‘×’ EE(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?

Q50GATE 20051 markMCQ−0.33 if wrong
Consider the grammar:

S →\rightarrow (S) | a

Let the number of states in SLR (1), LR(1) and LALR(1) parsers for the grammar be n1, n2 and n3 respectively. The following relationship holds good:

Keep practising

Topics in Compiler Design

All CS topics ›