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 16–20 of 58

Q16GATE 20192 marksNAT
Consider the augmented grammar given below:
S′→SS'\rightarrow S
S→<L>∣idS \rightarrow \lt L \gt |id
L→L,S∣SL \rightarrow L,S|S

Let I0=CLOSURE({[S′→⋅S]})I_0=CLOSURE(\{[S'\rightarrow \cdot S]\}). The number of items in the set GOTO(I0,<)GOTO(I_0,\lt) is __________.

Q17GATE 20182 marksMCQ−0.67 if wrong
C onsider the following parse tree for the expression a#b$c$d#e#f, involving two binary operators $ and #.
# a # $ # $ d e f b c
Which one of the following is correct for the given parse tree?

Q18GATE 2017 (Session 1)2 marksNAT
Consider the following grammar:

stmt→\rightarrow if expr then expr else expr; stmt| O˙\dot{O}
expr→\rightarrowterm relop term|term
term→\rightarrow id|number
id→\rightarrowa|b|c
number→\rightarrow [0-9]

where relop is a relational operator (e.g <,>\lt ,\gt,...), O˙\dot{O} refers to the empty statement, and if ,then, else are terminals.

Consider a program P following the above grammar containing ten if terminals. The number of control flow paths in P is ____________. For example the program

if e1e_1 then e2e_2 else e3e_3

has 2 control flow paths e1→e2e_{1} \rightarrow e_{2} and e1→e3e_{1} \rightarrow e_{3}.

Q19GATE 2016 (Session 2)2 marksMCQ−0.67 if wrong
A student wrote two context-free grammars G1 and G2 for generating a single C-like array declaration. The dimension of the array is at least one. For example,
int a[10][3];
The grammars use D as the start symbol,and use six terminal symbols int ;id[]num.
Grammar G1            Grammar G2
D → int L;            D → int L;
L → id [E             L → id E
E → num]              E → E[num]
E → num] [E           E → [num]

Which of the grammars correctly generate the declaration mentioned above?

Q20GATE 2015 (Session 1)1 markMCQ−0.33 if wrong
Which one of the following is TRUE at any valid state in shift-reduce parsing?

Keep practising

Topics in Compiler Design

All CS topics ›