Science of Computer Programming 47 (2003) 37 – 58 www.elsevier.com/locate/scico JastAdd—an aspect-oriented compiler construction system G orelHedin , Eva Magnusson Department of Computer Science, Lund University, Lund,Sweden Received 29 May 2002; accepted 4 July 2002 Abstract We describe JastAdd, a Java-based system for compilerconstruction. JastAdd iscentered around an object-oriented representation of the abstract syntax tree where reference variables can be used to link together dierent partsof the tree.JastAdd supports the combination of declarative techniques (using Reference Attributed Grammars) and imperative techniques (using ordinary Java code) in implementing the compiler. The behavior can be modularized into dierentaspects, e.g.name analysis, type checking, code generation, etc.,thatare woven together into classes using aspect-oriented programming techniques, providing a safer and more powerful alternative to the Visitor pattern. The JastAdd system is independent of the underlying parsing technology and supports any noncircular dependencies between computations, thereby allowing general multi-pass compilation. The attribute evaluator (optimal recursive evaluation) is implemented very conveniently using Java classes, interfaces, and virtual methods. c 2002 Elsevier Science B.V. All rights reserved. Keywords: Reference attributed grammars; Aspect-oriented programming; Compiler construction; Visitor pattern; Java 1. Introduction Many existing parser generators have only rudimentary support for further compila- tion.Often,the support is limited to simple semantic actions and tree building during parsing. Systems supporting more advanced processing are usually based on dedicated formalisms like attribute grammars and algebraic specications. These systems often have their own specication language and can be dicult to integrate with handwritten Corresponding author. E-mail addresses: gorel.hedin@cs.lth.se (G. Hedin), eva.magnusson@cs.lth.se (E. Magnusson). 0167-6423/03/$ - see front matterc 2002 Elsevier Science B.V.All rights reserved. PII: S 0 1 6 7 - 6 4 2 3 ( 0 2 ) 0 0 1 0 9 - 0