Syntax-Directed-Translation

Question 1

Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals {a,b}.

  S → aA   { print 1 }
  S → a    { print 2 }
  A → Sb   { print 3 }

Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:

A
1 3 2
B
2 2 3
C
2 3 1
D
syntax error
       Compiler-Design       Syntax-Directed-Translation       GATE 2016 [Set-1]       Video-Explanation
Question 1 Explanation: 
By using bottom up parser, the output will be “2 3 1”
Question 2

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

A
2 * 3 + 4
B
2 * +3 4
C
2 3 * 4 +
D
2 3 4+*
       Compiler-Design       Syntax-Directed-Translation       GATE 2006
Question 2 Explanation: 

Now perform post order evaluation, you will get output as,
2 3 4 + *
Question 3

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

A
always be evaluated
B
be evaluated only if the definition is L-attributed
C
be evaluated only if the definition has synthesized attributes
D
never be evaluated
       Compiler-Design       Syntax-Directed-Translation       GATE 2003
Question 3 Explanation: 
L-Attributed grammar can able to inherits either inherited attributes (or) synthesized attributes.
L-Attributed definitions are a class of syntax directed definitions whose attributes can be evaluated by a single traversal of the parse-tree.
There are 3 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access