On constructing efficient evaluators for attribute grammars

  • Mikko Saarinen
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 62)


An attribute grammar is an ordinary context-free grammar augmented with attributes and semantic rules for describing the semantics of terminal strings generated by the underlying context-free grammar. The meaning of a terminal string is revealed in two steps: first a parse tree is constructed for the string, and then a so-called evaluator defines the values of attribute instances attached to the parse tree. Many of these values are very temporary in nature, making it important to use the space allocated for them repeatedly.

In this paper the evaluator construction method of Kennedy and Warren is improved in two ways. First, we present how temporary values can be detected and stored in a stack so that their space requirement is linear in the height of the parse tree. Second, we demonstrate how to reduce the size of the evaluator. In the best case a reduction by an exponential factor can be achieved.


Quiescent State Parse Tree Construction Time Input String Semantic Rule 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [1]
    Aho, A.V. and Ullman, J.D.: The theory of parsing, translation and compiling, Volume 1: parsing. Prentice-Hall, Inc., Englewood Cliffs, N.J., 1972.Google Scholar
  2. [2]
    Blaizot, L.: DELTA: Système de description de langages et traducteurs par attributs. Rapport de Recherche 20, IRIA Laboria, Rocquencourt, Juin 1973.Google Scholar
  3. [3]
    Bochmann, G.V.: Semantic evaluation from left to right. Publication #175, Département d'Informatique, Université de Montréal, Montréal, May 1974. Also in CACM 19, 2 (February 1976), 55–62.Google Scholar
  4. [4]
    Böhm, C.(ed.): λ-calculus and computer science theory. Lecture Notes in Computer Science, Volume 37, Springer-Verlag, New York, 1975.Google Scholar
  5. [5]
    Borowiec, J.: Pragmatics in a compiler production system. Methods of algorithmic language implementation, A. Ershov and C.H.A. Koster (eds.), Springer-Verlag, Berlin-Heidelberg-New York, 1977, 314–340.Google Scholar
  6. [6]
    Bruno, J. and Burkhard, W.A.: A circularity test for interpreted grammars. Technical Report 88, Computer Science Laboratory, Department of Electrical Engineering, Princeton University, Princeton, N.J., 1970.Google Scholar
  7. [7]
    Fang, I: FOLDS, a declarative formal language definition system. STAN-CS-72-329, Computer Science Department, Stanford University, Stanford, California, December 1972.Google Scholar
  8. [8]
    Feldman, J.A. and Gries, D.: Translator writing systems. CACM 11, 2 (February 1968), 77–113.Google Scholar
  9. [9]
    Ganzinger,H.: MUG1 — Manual. Report 7608, Institut für Informatik, Technische Universität München, Juli 1976.Google Scholar
  10. [10]
    Ganzinger, H., Ripken, K. and Wilhelm, R.: Automatic generation of optimizing multipass compilers. Information Processing 77, Proceedings of IFIP Congress 77, B. Gilchrist (ed.), North-Holland Publ. Co., Amsterdam-New York-Oxford, 1977, 535–540.Google Scholar
  11. [11]
    Giegerich, R. and Wilhelm, R.: Implementierbarkeit attributierter Grammatiken. GI — 7.Jahrestagung, H.J. Schneider (ed.), Springer-Verlag, Berlin-Heidelberg-New York, 1977.Google Scholar
  12. [12]
    Jazayeri, M.: On attribute grammars and the semantic specification of programming languages. Report 1159, Jennings Computing Center, Case Western University, Cleveland, Ohio, October 1974.Google Scholar
  13. [13]
    Jazayeri, M., Ogden, W.F. and Rounds, W.C.: The intrinsically exponential complexity of the circularity problem for attribute grammars. CACM 18, 12 (December 1975), 697–706.Google Scholar
  14. [14]
    Jazayeri, M. and Pozefsky, D.: Algorithms for efficient evaluation of multi-pass attribute grammars without a parse tree. Report TR 77-001, Department of Computer Science, University of North Carolina, Chapel Hill, N.C., February 1977.Google Scholar
  15. [15]
    Jazayeri,M. and Walter,K.G.: Alternating semantic evaluator. Proceedings of the Annual Conference ACM 1975, October 1975, 230–234.Google Scholar
  16. [16]
    Kastens, U.: Ein Übersetzer-erzeugendes System auf der Basis attributierter Grammatiken. Interner Bericht 10, Fakultät für Informatik, Universität Karlsruhe, Karlsruhe, September 1976.Google Scholar
  17. [17]
    Kennedy, K. and Ramanathan, J.: A deterministic attribute grammar evaluator based on dynamic sequencing. Technical Report 476-093-12, Department of Mathematical Sciences, Rice University, Houston, Texas, October 1975.Google Scholar
  18. [18]
    Kennedy,K. and Warren,S.K.: Automatic generation of efficient evaluators for attribute grammars. Conference Record of the Third ACM Symposium on Principles of Programming Languages, January 1976, 32–49.Google Scholar
  19. [19]
    Knuth, D.E.: Semantics of context-free languages. Mathematical Systems Theory 2, 2 (1968), 127–145.CrossRefGoogle Scholar
  20. [20]
    Knuth, D.E.: Semantics of context-free languages: correction. Mathematical Systems Theory 5, 1 (1971), 95–96.CrossRefGoogle Scholar
  21. [21]
    Koster, C.H.A.: Affix grammars. Algol 68 implementation, J.E.L. Peck (ed.), North-Holland Publ. Co., Amsterdam-London, 1971, 95–109.Google Scholar
  22. [22]
    Lecarme, O.L. and Bochmann, G.V.: A (truly) usable and portable compiler writing system. Information Processing 74, Proceedings of IFIP Congress 74, J.L. Rosenfeld (ed.), North-Holland Publ. Co., Amsterdam-London, 1974, 218–221.Google Scholar
  23. [23]
    Lewi, J., DeVlaminck, K., Huens, J. and Mertens, P.: SLS/I: a translator writing system. GI — 5. Jahrestagung, J. Mühlbacher (ed.), Springer-Verlag, Berlin-Heidelberg-New York, 1975, 627–641.Google Scholar
  24. [24]
    Lorho, B.: De la définition à la traduction des langages de programmation: méthode des attributs sémantiques. Thèse d'Etat, Université Paul Sabatier, Toulouse, 1974.Google Scholar
  25. [25]
    Lorho, B. and Pair, C.: Algorithms for checking consistency of attribute grammars. Proving and improving programs, G. Huet and G. Kahn (eds.), IRIA, Rocquencourt, July 1975, 29–54.Google Scholar
  26. [26]
    Milne, R. and Strachey, C.: A theory of programming language ɛemantics. Chapman and Hall, London, and Wiley, New York, 2 Volumes, 1976.Google Scholar
  27. [27]
    Néel, D. and Amirchahy, M.: Semantic attributes and improvement of generated code. Proceedings of the Annual Conference ACM 1974, November 1974, 1–10.Google Scholar
  28. [28]
    Räihä, K.-J.: On attribute grammars and their use in a compiler writing system. Report A-1977-4, Department of Computer Science, University of Helsinki, Helsinki, August 1977.Google Scholar
  29. [29]
    Räihä, K.-J. and Saarinen, M.: Developments in compiler writing systems. GI-6. Jahrestagung, E.J. Neuhold (ed.), Springer-Verlag, Berlin-Heidelberg-New York, 1976, 164–178.Google Scholar
  30. [30]
    Räihä, K.-J. and Saarinen, M.: An optimization of the alternating semantic evaluator. Information Processing Letters 6, 3 (1977), 97–100.CrossRefGoogle Scholar
  31. [31]
    Räihä, K.-J., Saarinen, M., Soisalon-Soininen, E. and Tienari, M.: The compiler writing system HLP (Helsinki Language Processor). Report A-1978-2, Department of Computer Science, University of Helsinki, Helsinki, March 1978.Google Scholar
  32. [32]
    Saarinen, M.: Stack realizable attribute grammars. In preparation.Google Scholar
  33. [33]
    Schulz, W.A.: Semantic analysis and target language synthesis in a translator. Ph.D. Thesis, University of Colorado, Boulder, Colorado, 1976.Google Scholar
  34. [34]
    Warren, S.K.: The efficient evaluation of attribute grammars. M.A. Thesis, Department of Mathematical Sciences, Rice University, Houston, Texas, April 1975.Google Scholar
  35. [35]
    Watt, D.A.: The parsing problem for affix grammars. Acta Informatica 8, 1 (1977), 1–20.Google Scholar
  36. [36]
    Wegner, P.: The Vienna definition language. Computing Surveys 4, 1 (March 1972), 5–63.CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1978

Authors and Affiliations

  • Mikko Saarinen
    • 1
  1. 1.Department of Computer ScienceUniversity of HelsinkiHelsinki 10Finland

Personalised recommendations