Syntax-Directed Translation

San Skulrattanakulchai

February 15, 2019

Tree traversals

Terms

Syntax-directed translation

  1. with each grammar symbol, a set of attributes
  2. with each production, a set of semantic rules for computing the values of the attributes associated with the symbols appearing in the production,
    e.g.
    productions               semantic rules
  
  expr → expr1 + term     expr.t = expr1.t || term.1 || '+'
  expr → expr1 - term     expr.t = expr1.t || term.1 || '-'
  expr → term             expr.t = term.t
  term → 0                term.t = '0'
  term → 1                term.t = '1'
  term → 2                term.t = '2'
  term → 3                term.t = '3'
  term → 4                term.t = '4'
  term → 5                term.t = '5'
  term → 6                term.t = '6'
  term → 7                term.t = '7'
  term → 8                term.t = '8'
  term → 9                term.t = '9'

Syntax-directed translation scheme