Professional Documents
Culture Documents
) – 7
Submission date: 28-04-2022 (10 points)
Q.1
a) For the grammar S → 0 S 1 | 0 1
Give bottom-up parses for the input string: 000 1 1 1
Q.3
Consider the following grammar:
S → S(S) | ∈
Part-I
a) Construct the DFA of LR(0) items for this grammar.
b) Construct the SLR(1) parsing table for this grammar.
c) Show the parsing stack and the actions of an SLR(1) parser for the input string
( ( ) ( ) ).
d) Is this grammar an LR (0) grammar? If not, describe the LR(0) conflict. If so,
construct the LR(0) parsing table, and describe how a parse might differ from an
SLR(1) parse.
Part-II
a) Construct the DFA of LR(1) items for this grammar.
b) Construct the general LR(1) parsing table.
c) Construct the DFA of LALR(1) items for this grammar.
d) Construct the LALR(1) parsing table.
e) Describe any difference that might occur between the actions of a general LR(1)
parser and an LALR(1) parser.
---------------------------------------------------------------------------------------
Q.4
Consider the following grammar of simplified statement sequences:
stmt-sequence → stmt-sequence ; stmt | stmt
stmt → s
Part-I
a) Construct the DFA of LR(0) items for this grammar.
b) Construct the SLR(1) parsing table for this grammar.
c) Show the parsing stack and the actions of an SLR(1) parser for the input string
s ; s ; s.
d) Is this grammar an LR (0) grammar? If not, describe the LR(0) conflict. If so,
construct the LR(0) parsing table, and describe how a parse might differ from an
SLR(1) parse.
Part-II
a) Construct the DFA of LR(1) items for this grammar.
b) Construct the general LR(1) parsing table.
c) Construct the DFA of LALR(1) items for this grammar.
d) Construct the LALR(1) parsing table.
e) Describe any difference that might occur between the actions of a general LR(1)
parser and an LALR(1) parser.
------------------------------------------------------------------------------------
Q.5
Consider the following grammar:
E →(L) | a
L → E L | E
Part-I
a) Construct the DFA of LR(0) items for this grammar.
b) Construct the SLR(1) parsing table for this grammar.
c) Show the parsing stack and the actions of an SLR(1) parser for the input string
( ( a ) a (a a ) ).
Part-II
d) Construct the DFA of LALR(1) items by propagating the lookaheads through the
DFA of LR(0) items.
e) Construct the LALR(1) parsing table.
Q. 6
Consider the following grammar:
declaration → type var-list
type → int | float
var-list → identifier , var-list | identifier
Part-I
a) Rewrite it in a form more suitable for bottom-up parsing.
b) Construct the DFA of LR(0) items for the re-written grammar.
c) Construct the SLR(1) parsing table for the re-written grammar.
d) Show the parsing stack and the actions of an SLR(1) parser for the input string int x,
y, z using the table of part (c).
Part-II
a) Construct the DFA of LALR(1) items by propagating the lookaheads through the
DFA of LR(0) items of part(b).
b) Construct the LALR(1) parsing table for the rewritten grammar.
--------------------------------------------------------------------------------------
Q.7
Consider the following grammar.
E→E+T | T
T→T*F | F
F → ( E ) | id
a) Configure the LR(0) automaton for the above expression grammar.
b) Construct SLR(1) parsing table for the above expression grammar.
c) Configure the shift-reduce parser for the above grammar on the input id * id + id.
-----------------------------------------------------------------------------------------
Q.8
i) Consider the following grammar
S' → S
S→aAdǀbBdǀaBeǀbAe
A→c
B→c
Show that the above grammar is LR(1) but not LALR(1).
ii)
a. show that the following grammar is not LR(1):
A→ aAa| ∈
b. Is this grammar ambiguous? Why or why not ?
Q. 9
Trace the behavior of a panic mode error recovery mechanism for the string (*2. using
the following parsing table. (As is discussed on page 246. Example 5.19) the DFA is
given on page 233.(Louden book)
State INPUT Goto
Number ( + - * ) $ command exp term Factor
0 s5 s6 1 2 3 4
1 accept
2 r1 r1 s7 s8 r1 r1 r1
3 r4 r4 r4 r4 s9 r4 r4
4 r6 r6 r6 r6 r6 r6 r6
5 r7 r7 r7 r7 r7 r7 r7
6 s5 s6 10 3 4
7 s5 s6 11 4
8 s5 s6 12 4
9 s5 s6 13
10 s7 s8 s14
11 r2 r2 r2 r2 s9 r2 r2
12 r3 r3 r3 r3 s9 r3 r3
13 r5 r5 r5 r5 r5 r5 r5
14 r8 r8 r8 r8 r8 r8 r8
-------------------------------------------------------------------------
Q. 10. Consider the following grammar G:
P→ Q )
Q → Q , R | ( R, R
R → { num , num }
S →A a A b ǀ B b B a
A→∈
B →∈
is LL(1) but not SLR(1).
I4: E → E + . E I9: E → ( E ).
E→.E+E
E→.E*E
E→.(E)
E → . id