CS 614: Theory and Construction of Compilers Lecture 11 Fall 2002 Department of Computer Science University of Alabama Joel Jones
Overview Action routines in Java Cup Abstract Syntax Trees Readings for Next Time ©2002 Joel Jones
Action Routines in Java Cup Associated with productions Return Symbol Symbol contains token type and value Syntactically assign to RESULT with type of value ©2002 Joel Jones
Abstract Syntax Trees Clean Interface between parser and later phases of compiler Conveys phrase structure with all parsing issues resolved ©2002 Joel Jones
Concrete Syntax Vs. Abstract Syntax Stm -> Stm ; Stm Stm -> id := Exp Stm -> print ( ExpList ) Exp -> id Exp -> num Exp -> Exp Binop Exp Exp -> (Stm, Exp) ExpList -> Exp, ExpList ExpList -> Exp BinOp -> + | - | * | / S -> S ; S S -> id := E S -> print L E -> id E -> num E -> E B E E -> S , E L -> L -> L E B -> + | - | * | / ©2002 Joel Jones
Representing Tree Data Structures in Java A tree is described by one or more abstract classes, corresponding to a symbol in the grammar Each abstract class is extended by one or more subclasses, one for each gramar rule For each nontrivial symbol on rhs, thereis a field in the corresponding class Each class has a constructor that initializes all fields and is thereafter immutable ©2002 Joel Jones
Readings for Next Time Chapter 4 through and including section 4.6 ©2002 Joel Jones