3a) Assignment 2
3a) Assignment 2
(Deemed to be University)
Construct the canonical LR and LALR sets of items for the grammar
2 S → SS + | SS* | a CO3 L3
Show that the following grammar: [ GATE-2016]
S → Aa | bAc | Bc | bBa
3 A→d CO3 L3
B→d
is LR(1) but not LALR(1).
Define the SDT for the evaluation of the following arithmetic expressions and, also
show the annotated parse trees. [ n is the end marker of the expression]
4 CO4 L1, L2
a) (9 + 8 * (7 + 6 ) + 5 ) * 4 n
b) (3+ 4)* (5 + 6 ) n
The following grammar generates binary numbers with a “decimal” point:
S→L . L | L
L→ L B | B
5 B→0|1
CO4
Construct an L-attributed SDD to compute S. val, the decimal-number value of an L3
input string. For example, the translation of string 101.101 should be the decimal
number 5.625. Hint: use an inherited attribute L. side that tells which side of the
decimal point a bit is on.
Suppose that we have a production A → BCD.Each of the four nonterminals A, B,
C and D have two attributes: s is a synthesized attribute and i is an inherited
attribute. For each of the sets of rules below, analyze and tell whether (i) the rules
are consistent with an S-attributed definition (ii) the rules are consistent with an L-
attributed definition, and (iii) whether the rules are consistent with any evaluation
L4
6 order at all? CO4
a) A.s= B.i + C.s
b) A.s= B.i + C.s and D.i = A.i + B.s
c) A.s= B.s + D.s
d) A.s =D.i, B.i = A.s +C.s , C.i =B.s and D.i = B.i +C.i