Applications and Extensions of Reference Attributed Grammars

Programming languages are the main tools used to describe models of the real world and algorithms which manipulate these models. Over time much effort has been devoted to the task of making programming languages more high-level by enhancing their expressiveness, bringing it closer to the way the programmer thinks and reasons. The development of object-oriented programming languages is one important step in this direction. Object-oriented languages include several abstraction mechanisms to support real world modelling. The resulting models represent a balanced view of data and computation aspects. Declarative programming is another important principle, offering features to build general libraries of functions. The model of programming is here clean and simple: the programmer specifies a result as a function of others, thereby concentrating on what relationsships there are between values rather than on the order of computations. This thesis deals with techniques for making specifications of computations on abstract syntax trees more high-level. Such computations are performed in different language-based tools e.g., compilers, smart syntax-sensitive editors, software metric tools, etc. Our basis is Reference Attributed Grammars (RAGs), which combines object-oriented features with declarative programming to specify computations on abstract syntax trees. RAGs have proven useful e.g., for performing static-semantic analysis of object-oriented languages. A RAG is an extension of traditional or classical attribute grammars (AGs) which is a formalism in which the static semantics of a programming language can be specified using a declarative approach. Traditional AGs are often considered clumsy and difficult to use for some aspects of compiler related tasks, for example name- and type-analysis of languages with complex scope rules. By allowing references between distant nodes in the AST the RAG formalism facilitates these tasks. The object-oriented view of the grammar used in RAGs is a conceptual extension of AGs which make it possible to apply all the object-oriented advantages. In the thesis we deal with extensions of RAGs and how they can be combined to facilitate tasks further for the attribute grammar author. We also explore applications of the combined extensions. Furthermore, we discuss evaluation techniques for extended AG formalisms. Some extensions are formal, e.g., allowing cyclic dependencies between attribute instances while others can be characterized as conceptual. Conceptual extensions include the object-oriented modelling of the grammar and modularization concepts. Even in extended AG formalisms some specifications can be complicated to express while their equivalent imperative style implementations are almost trivial. Another objective of this thesis is therefore to show how the declarative approach used in attribute grammars can be combined with imperative techniques in a tool using aspect-oriented modularization and where modules can be implemented in either imperative or declarative style. The thesis consist of an introduction and three papers. The first paper deals with the application of RAGs to a new problem area; program visualization. The second paper describes a practical system for RAGs, based on aspect-oriented programming and the combination of imperative and declarative programming. The third paper describes a formal extension of RAGs supporting circular dependencies (CRAGs). The extended formalism opens up new application areas which is also discussed in the paper. The techniques have all been implemented and tested in practice. Our tool JastAdd incorporates the extended AG formalisms. Its modularization concept also allows imperative style modules to be freely combined with AG modules. An automatic evaluator construction capability that can handle the extended formalisms has also been developed. (Less)