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.
E E1+E2 [E.sign=E2.sign]
E E1 (E2) {E.sign=E1.sign E2.sign}
E E1/E2 {if (E1.sign==0) then E.sign=1 else E.sign=0}
E +E1 {E.sign=0}
E -E1 {E.sign=1}
E id {E.sign=0}
Find the attribute alue at the root E for the given input -id (-id+id)
[Note: E E1+E2 is same as E E+E].

Question 3

Consider the following SDT
G A-T{Print “-”}
A Ea {Print “*”}
E Eb {Print “+”}
E  {Print “0”}
T Eb {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 GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 bepstudentsupport@byjus.com