Time Left - 15:00 mins

GATE CS 2022 : Compiler design Quiz -4

Attempt now to get your rank among 175 students!

Question 1

Consider the grammar with the following translation rules and S as the start symbol.
S Ã S1 # T {S.val = S1.val x T.val }
S Ã T {S.val = T.val}
T Ã T1 & F { T.val = T1.val + F.val }
T Ã F {T.val = F.val}
F Ã num {F.val = num.lexval}
If the input string w=5#2 & 3#7 & 1 then the value of S.val is _____

Question 2

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 3

Consider the following SDT
GA-T{Print “-”}
AEa {Print “*”}
EEb {Print “+”}
E {Print “0”}
TEb {Print “1”}
In the SDT uses L-attribute definition, what is the output printed for evaluation of an input string “ba-bb”?

Question 4

Consider the syntax directed translation scheme(SDTS), with non-terminals {S,A} and {a,b}-

S -> bA {print 30}

S->b {print 20}

A-> Sa {print 10}

Using above SDTS, the output printed by bottom - up parser, for the input bba:-

Question 5

Consider the following SDT

S -> 0 {S.x = 0}

S -> 1 {S.x = 1}

S -> S0 {S.x = S1.x * 2}

S -> S1 {S.x = S1.x * 2 + 1}

What will be translation of an input “1001” using above SDT?

Question 6

How many of the following statements are true?

i) A Synthesized attribute is an attribute of the non-terminal on the left-hand side of a production.

ii) The synthesized attribute can take value only from its children (Variables in the RHS of the production).

iii) S-attributed SDT uses only synthesized attributes.

iv) L-attributed uses both synthesized attributes and inherited attributes.

  • 175 attempts
  • 1 upvote