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:
1 3 2 | |
2 2 3 | |
2 3 1 | |
syntax error |
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
2 * 3 + 4 | |
2 * +3 4
| |
2 3 * 4 + | |
2 3 4+* |
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
always be evaluated | |
be evaluated only if the definition is L-attributed | |
be evaluated only if the definition has synthesized attributes | |
never be evaluated |
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.
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.