Time Left - 15:00 mins
GATE CS 2022 : Compiler design Quiz -4
Attempt now to get your rank among 177 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 _____
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].
E
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767828374852.png)
E
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/147376782923510.png)
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/147376783006791.png)
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767830972233.png)
E
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767831860230.png)
E
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767832690566.png)
E
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767833539641.png)
E
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767834407398.png)
Find the attribute alue at the root E for the given input -id
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767835247342.png)
[Note: E
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767837247940.png)
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767838106563.png)
Question 3
Consider the following SDT
G
A-T{Print “-”}
A
Ea {Print “*”}
E
Eb {Print “+”}
E![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767909103695.png)
{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”?
G
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767906599354.png)
A
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767907423688.png)
E
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/14737679082443.png)
E
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767909103695.png)
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767909923588.png)
T
![](https://gradeup-question-images.grdp.co/liveData/PROJ439/1473767910740333.png)
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.
- 177 attempts
- 1 upvote
- 0 comments
Oct 21GATE & PSU CS