← 🧮 Syntax-Directed Translation
Subtopic 5 of 5

6.5Translation schemes (actions inside rules)

Actions are embedded at the point they must run. Output order follows the depth-first, left-to-right traversal. Example: E → E + T {print("+")} yields postfix.

Input9 − 5 + 2
Output so far
  • Parse 9 as T → digit: action prints 9
  • Parse 5 as T → digit: prints 5 (operator comes later!)
  • Reduce E → E − T: action prints −
  • Parse 2: prints 2
  • Reduce E → E + T: action prints +. Result is the POSTFIX form of (9 − 5) + 2

Scheme: E → E + T {print("+")} | E − T {print("−")} | T ; T → digit {print(digit)}. Input 9 − 5 + 2

Previous year questions: Syntax-Directed Translation (9)

PYQs are grouped by topic, so this is the full set for Syntax-Directed Translation; try the ones that match this subtopic. Open all 9 on the topic page.