GATE CS : Compiler Design Champion Quiz 3
Attempt now to get your rank among 515 students!
Question 1
Question 2
Question 3
Question 4
EE1+E2 [E.sign=E2.sign]
EE1(E2) {E.sign=E1.signE2.sign}
EE1/E2 {if (E1.sign==0) then E.sign=1 else E.sign=0}
E+E1 {E.sign=0}
E-E1 {E.sign=1}
Eid {E.sign=0}
Find the attribute alue at the root E for the given input -id(-id+id)
[Note: EE1+E2 is same as EE+E].
Question 5
Question 6
Consider the grammar with the following translation rules and E as the start symbol.
E→E1#T {E.value=E1.value*T.value}
T {E.value=T.value}
T→T1&F {T.value=T1.value+F.value}
F {T.value=F.value}
F→num {F.value=num.value}
Compute E.value for the root of the parse tree for the expression: 2#3&5#6&4.
Question 7
S →ER
R →*E {print (‘*’);}R|ε
E →F + E {print (‘+’);}|F
F →(S)|id {print (id.value);}
Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input '2 * 3 +4', this translation scheme prints
Question 8
Question 9
E→ E11 * T {E.val = E11.val * T.val}
E→ T {E.val = T.val}
T→ F - T11 {T.val = F.val - T11.val}
T→ F {T.val = F.val}
F→2 {F.val = 2}
F→4 {F.val = 4}
Question 10
Consider the syntax directed definition shown below
S → id : = E {gen(id.place = E.place;);}
E → E1 + E2 {t = newtemp( );
gen(t = E1.place + E2.place;);
E.place = t;}
E →id {E.place = id.place;}
Here, gen is a function that generates the output code, and newtemp is a function that returns the name of a new temporary variable on every call. Assume that ti’s are the temporary variable names generated by newtemp. For the statement ‘X : = Y + Z’, the 3-address code sequence generated by this definition is
- 515 attempts
- 3 upvotes
- 23 comments