Abstract
This paper presents an object-oriented technique for rewriting abstract syntax trees in order to simplify compilation. The technique, Rewritable Reference Attributed Grammars (ReRAGs), is completely declarative and supports both rewrites and computations by means of attributes. We have implemented ReRAGs in our aspect-oriented compiler compiler tool JastAdd II. Our largest application is a complete static-semantic analyzer for Java 1.4. ReRAGs uses three synergistic mechanisms for supporting separation of concerns: inheritance for model modularization, aspects for cross-cutting concerns, and rewrites that allow computations to be expressed on the most suitable model. This allows compilers to be written in a high-level declarative and modular fashion, supporting language extensibility as well as reuse of modules for different compiler-related tools. We present the ReRAG formalism, its evaluation algorithm, and examples of its use. Initial measurements using a subset of the Java class library as our benchmarks indicate that our generated compiler is only a few times slower than the standard compiler, javac, in J2SE 1.4.2 SDK. This shows that ReRAGs are already useful for large-scale practical applications, despite that optimization has not been our primary concern so far.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
Hedin, G.: Reference Attributed Grammars. Informatica (Slovenia) 24 (2000)
Vogt, H.H., Swierstra, S.D., Kuiper, M.F.: Higher order attribute grammars. In: Proceedings of the SIGPLAN 1989 Programming language design and implementation, ACM Press, New York (1989)
Saraiva, J.: Purely functional implementation of attribute grammars. PhD thesis, Utrecht University, The Netherlands (1999)
Van Wyk, E., de Moor, O., Backhouse, K., Kwiatkowski, P.: Forwarding in attribute grammars for modular language design. In: Horspool, R.N. (ed.) CC 2002. LNCS, vol. 2304, pp. 128–142. Springer, Heidelberg (2002)
Visser, E.: Stratego: A language for program transformation based on rewriting strategies. System description of Stratego 0.5. In: Middeldorp, A. (ed.) RTA 2001. LNCS, vol. 2051, pp. 357–361. Springer, Heidelberg (2001)
van den Brand, M., et al.: The ASF+SDF Meta-Environment: a Component-Based Language Development Environment. In: Wilhelm, R. (ed.) CC 2001. LNCS, vol. 2027, p. 365. Springer, Heidelberg (2001)
Cordy, J.R.: Txl:A language for programming language tools and applications. In: Proceedings of the 4th Workshop on Language Descriptions, Tools, and Applications (LDTA 2004) at ETAPS 2004 (2004)
Hedin, G., Magnusson, E.: JastAdd: an aspect-oriented compiler construction system. Science of Computer Programming 47, 37–58 (2003)
Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, 2nd edn. Addison-Wesley, Boston (2000)
Kiczales, G., Hilsdale, E., Hugunin, J., Kersten, M., Palm, J., Griswold, W.G.: An overview of AspectJ. In: Knudsen, J.L. (ed.) ECOOP 2001. LNCS, vol. 2072, pp. 327–355. Springer, Heidelberg (2001)
Knuth, D.E.: Semantics of context-free languages. Mathematical Systems Theory 2, 127–145 (1968); Correction: Mathematical Systems Theory 5, 1, pp. 95-96 (March 1971)
Hedin, G.: An object-oriented notation for attribute grammars. In: The 3rd European Conference on Object-Oriented Programming (ECOOP 1989). BCS Workshop Series, pp. 329–345. Cambridge University Press, Cambridge (1989)
Nilsson, A.: Compiling Java for Real-Time Systems. Licentiate thesis, Department of Computer Science, Lund Institute of Technology (2004) (in preparation)
Lindholm, T., Yellin, F.: Java Virtual Machine Specification. Addison-Wesley Longman Publishing Co., Inc, Amsterdam (1999)
Visser, E.: Scoped dynamic rewrite rules. Electronic Notes in Theoretical Computer Science 59 (2001)
Boyland, J., Farnum, C., Graham, S.L.: Attributed transformational code generation for dynamic compilers. In: Giegerich, R., Graham, S.L. (eds.) Code Generation - Concepts, Tools, Techniques.Workshops in Computer Science, pp. 227–254. Springer, Heidelberg (1992)
Serrano, M.: Wide classes. In: Guerraoui, R. (ed.) ECOOP 1999. LNCS, vol. 1628, pp. 391–415. Springer, Heidelberg (1999)
Chambers, C.: Predicate classes. In: Nierstrasz, O. (ed.) ECOOP 1993. LNCS, vol. 707, pp. 268–296. Springer, Heidelberg (1993)
Drossopoulou, S., Damiani, F., Dezani-Ciancaglini, M., Giannini, P.: More dynamic object reclassification: FickleII. ACM Trans. Program. Lang. Syst. 24, 153–191 (2002)
Costanza, P.: Dynamic object replacement and implementation-only classes. In: 6th International Workshop on Component-Oriented Programming (WCOP 2001) at ECOOP 2001 (2001)
Magnusson, E., Hedin, G.: Circular reference attributed grammars - their evaluation and applications. Electronic Notes in Theoretical Computer Science 82 (2003)
Bracha, G., Odersky, M., Stoutamire, D., Wadler, P.: Making the future safe for the past: Adding genericity to the Java programming language. In: Proceedings of Object Oriented Programming: Systems, Languages, and Applications (OOPSLA), pp. 183–200 (1998)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2004 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Ekman, T., Hedin, G. (2004). Rewritable Reference Attributed Grammars. In: Odersky, M. (eds) ECOOP 2004 – Object-Oriented Programming. ECOOP 2004. Lecture Notes in Computer Science, vol 3086. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-24851-4_7
Download citation
DOI: https://doi.org/10.1007/978-3-540-24851-4_7
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-22159-3
Online ISBN: 978-3-540-24851-4
eBook Packages: Springer Book Archive