Home » Compiler Design » Compiler design miscellaneous » Question

Compiler design miscellaneous

  1. 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
    1. 9 + 5 + 2
    2. 95 + 2 +
    3. 952 + +
    4. + + 952
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 +



Your comments will be displayed only after manual approval.