Similar questions 1 more →
Semantic Analysis & Type Checking

Answer & solution
Answer: B (no official key was published)
Step through it (19 steps)
1. Expand S→TR. The initial T consumes 9 and immediately prints 9.
2. The first R consumes + and invokes T on 5, printing 5. Its following action prints + before the recursive R begins.
3. That recursive R consumes +, invokes T on 2 and prints 2, then prints +. Its final R chooses ε and prints nothing.
4. Concatenating the actions yields 9,5,+,2,+, or 95+2+, B. Moving the plus action to after the recursive R would change the result, but that is not this scheme.
Solution: The initial T prints 9. Each R expansion reads +, processes T (which prints the next number), prints +, and only then processes the remaining R. Hence the execution order is 9,5,+,2,+, yielding 95+2+, option B. The action is before the recursive R, so it does not postpone both plus signs to the end.