Advertisement

Abstract

Name analysis for Java is challenging with its complex visibility rules involving nested scopes, inheritance, qualified access, and syntactic ambiguities. We show how Java name analysis including ambiguities related to names of variables, fields, and packages, can be implemented in a declarative and modular manner using the JastAdd compiler construction system.

Declarative attributes and context-dependent rewrites enable the implementation to be modularized in the same way as the informal Java language specification. The individual rules in the specification transfer directly to equations in the implementation. Rewrites are used to define new concepts in terms of existing concepts in an iterative manner in the same way as the informal language specification. This enables equations to use both context-free and context-dependent concepts and leads to improved separation of concerns. A full Java 1.4 compiler has been implemented to validate the technique.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Ekman, T., Hedin, G.: The JastAdd compiler compiler system, http://jastadd.cs.lth.se
  2. 2.
    Ekman, T., Hedin, G.: Rewritable Reference Attributed Grammars. In: Odersky, M. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 147–171. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  3. 3.
    Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, 2nd edn. Addison-Wesley, Boston (2000)Google Scholar
  4. 4.
    Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, 3rd edn. Addison-Wesley, Boston (2005)Google Scholar
  5. 5.
    Hedin, G.: An overview of door attribute grammars. In: Fritzson, P.A. (ed.) CC 1994. LNCS, vol. 786, pp. 31–51. Springer, Heidelberg (1994)Google Scholar
  6. 6.
    Hedin, G.: Reference attribute grammars. Informatica (Slovenia) 24(3) (2000)Google Scholar
  7. 7.
    Hedin, G., Magnusson, E.: JastAdd: an aspect-oriented compiler construction system. Science of Computer Programming 47(1), 37–58 (2003)zbMATHCrossRefMathSciNetGoogle Scholar
  8. 8.
    Kastens, U., Waite, W.M.: An abstract data type for name analysis. Acta Informatica 28(6), 539–558 (1991)zbMATHCrossRefGoogle Scholar
  9. 9.
    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)CrossRefGoogle Scholar
  10. 10.
    Knuth, D.E.: Semantics of context-free languages. Mathematical Systems Theory 2(2), 127–145 (1968); Correction: Mathematical Systems Theory 5(1) 95–96 (March 1971)zbMATHCrossRefMathSciNetGoogle Scholar
  11. 11.
    Olmos, K., Visser, E.: Composing source-to-source data-flow transformations with rewriting strategies and dependent dynamic rewrite rules. In: Bodik, R. (ed.) CC 2005. LNCS, vol. 3443, pp. 204–220. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  12. 12.
    Saraiva, J.: Purely functional implementation of attribute grammars. PhD thesis, Utrecht University, The Netherlands (1999)Google Scholar
  13. 13.
    Sloane, A., Waite, W.M., Kastens, U.: Eli - translator construction made easy, http://eli-project.sourceforge.net/
  14. 14.
    van den Brand, M., Klint, P.: The ASF+SDF MetaEnvironment, http://www.cwi.nl/htbin/sen1/twiki/bin/view/SEN1/MetaEnvironment
  15. 15.
    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)CrossRefGoogle Scholar
  16. 16.
    Visser, E., Bravenboer, M., Vermaas, R.: Stratego: Strategies for Program Transformation, http://www.program-transformation.org/Stratego/WebHome
  17. 17.
    Vogt, H.H., Swierstra, S.D., Kuiper, M.F.: Higher order attribute grammars. In: Proceedings of the SIGPLAN 1989 Conference on Programming language design and implementation, pp. 131–145. ACM Press, New York (1989)CrossRefGoogle Scholar
  18. 18.
    Vorthmann, S.A.: Modelling and specifying name visibility and binding semantics. Technical Report CMU//CS-93-158 (1993)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Torbjörn Ekman
    • 1
  • Görel Hedin
    • 1
  1. 1.Department of Computer ScienceLund UniversitySweden

Personalised recommendations