CST zu AST

AST-Typ deklarieren (wie Grammatik)

Abstract Syntax Tree 
    exp = { plus }   [left]:exp [right]:exp
      | { times }   [left]:exp [right]:exp
      | { number } number  ;

und Übersetzungen für jeder Regel

Productions
  expression { -> exp } =  sum { -> sum.exp } ;
  sum { -> exp } 
     = { simple } product { -> product.exp } 
     | { complex } sum plus product 
	  { -> New exp.plus (sum.exp, product.exp) } ;
links Typ, rechts Kopie oder Konstruktion (new)

Das ist Attributgrammatik (jeder Knoten des CST bekommt als Wert eine Knoten des AST)


Johannes Waldmann 2006-02-02