-
Consider the translation scheme shown below:
S → RT
R → + T {print (‘+’:) R/ ε
T → num {print (num. val);}
Here, num is a taken that represents an integer and num. val represents the corresponding integer value. For an input string ‘9 + 5 + 2’, this translation scheme will print
-
- 9 + 5 + 2
- 95 + 2 +
- 952 + +
- + + 952
- 9 + 5 + 2
Correct Option: B
Let us make the parse tree for 9 + 5 + 2 in top down manner, left first derivation.
Steps:
1) Expand S → TR
2) Apply T → Num...
3) Apply R → +T...
4) Apply T → Num...
5) Apply R → +T..
6) Apply T → Num..
7) Apply R → ε (epsilon)
After printing through the print statement in the parse tree formed you will get the answer as 95 + 2 +