Time Left - 20:00 mins

GATE CS : Compiler Design Champion Quiz 3

Attempt now to get your rank among 515 students!

Question 1

In a bottom-up evaluation of a syntax directed definition, inherited attributes can

Question 2

Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?

Question 3

Consider the grammar rule E E1 - E2 for arithmetic expressions. The code generated is targeted to a CPU having a single user register. The subtraction operation requires the first operand to be in the register. If E1 and E2 do not have any-common sub-expression, in order to get the shortest possible code

Question 4

Let G be a grammar is used for arithmetic expressions. The grammar G is shown below with sematic actions and attribute “sign” can contain either 0 or 1.
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

Find the C statement which has a syntax error.

Question 6

Consider the grammar with the following translation rules and E as the start symbol.
EE1#T {E.value=E1.value*T.value}
     T {E.value=T.value}
TT1&F {T.value=T1.value+F.value}
     F {T.value=F.value}
Fnum {F.value=num.value}
Compute E.value for the root of the parse tree for the expression: 2#3&5#6&4.

Question 7

Consider the following translation scheme.
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

Type checking is normally done during ___

Question 9

Consider the syntax directed translation scheme (SDTS) given in the following. Assume attribute evaluation with bottom-up parsing, i.e., attributes are evaluated immediate ly after a reduction.

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}

F2 {F.val = 2}

F4 {F.val = 4}

Using this SDTS, for the expression 4 – 2 – 4 * 2 compute its E.val.

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
Apr 9GATE & PSU CS