You are on page 1of 5

Mid term Solution: Compiler Design (CSE6001)

Section-A
1. SR conflict LR(1) item: S->.a , $ A->b. , a
RR conflict LR(1) item: S->a. , $ A->b. , $
2. According to power:

According to states: LR(0) = SLR(1) = LALR(1) <= CLR(5) <= CLR(1)


3. L-attributed SDT:
1. If an SDT uses both synthesized attributes and inherited attributes with a restriction
that inherited attribute can inherit values from left siblings only, it is called as L-
attributed SDT.
2. Attributes in L-attributed SDTs are evaluated by depth-first and left-to-right parsing
manner.
3. Semantic actions are placed anywhere in RHS.
4. i. No ii. No
5. 1000: If x<y goto 5000
2000: If a<b goto 5000
3000: call fun
4000: goto 6000
5000: x=*y
6000:
Section-B
1.
2.
t1 = uminus c
t2 = t1 * b
t3 = uminus c
t4 = t3 * b
t5 = t2 + t4
a = t5

3. input expression “ 3@6#5@2#1@2”


Here @ will replace with * and # with +
Output expression 3*6+5*2+1*2
= 18+5*2+1*2 =18+10+1*2 = 18+10+2 = 18+12 = 30

6. SDT for the “Postfix expression


PRODUCTIONS SEMENTIC RULES
E  E1 op E2 E.code = E1.code|| E2.code || op
E  (E1) F.val = E1.code
E  id E.code=id

Section C
(I) Construct the LALR item set for given grammar
EE+T | T TTF | F FF* | a

(II) Consider the following SDT


ST {Print(+)} R {Print(*)}
R+T {Print(*)} R {Print(+)}
Repsilon{Print(*)}
Tnum {Print(num)}
Construct the annotated parse tree and give the output for input: 9+5+2+7

(III) Design convert the given code into 3-address code?


(IV) Construct the SDT for Desk calculator. Show the parse tree with translation for given
input: 42*6+7#

You might also like