Abstract
The purpose of this paper is twofold. Firstly we show how attributes in an attribute grammar can be simply and efficiently evaluated using a lazy functional language. The class of attribute grammars we can deal with are the most general ones possible: attributes may depend on each other in an arbitrary way, as long as there are no truly circular data dependencies.
Secondly, we describe a methodology based on attribute grammars, where, in a fairly straightforward way, we can develop efficient functional programs where direct, conventional solutions yield less efficient programs. We review two examples from a paper by R. Bird (Using circular programs to eliminate multiple traversals of data, Acta Informatica, 21, 1984) where he transforms simple but inefficient multipass programs into more efficient single pass ones, but which on their own can be very hard to understand. We show how such efficient but tangled programs can have natural formulations as attribute grammars.
We also propose a language construct, called case rec (akin to the case expression in Standard ML and Lazy ML), that defines an attribute grammar over a data structure in the language. In effect, a case rec expression defines a recursion operator that can handle multiple values, both upwards-propagating and downwards-propagating ones.
Keywords
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.
Download to read the full chapter text
Chapter PDF
References
L. Augustsson. A compiler for lazy Ml. In Proceedings of the 1984 ACM Symposium on Lisp and Functional Programming, pages 218–227, Austin, 1984.
A. V. Aho, J. D. Ullman, and R. Sethi. Compilers: Principles, Techniques, Tools. Addison-Wesley Publishing Company, Reading, Mass., 1986.
R. M. Burstall and J. Darlington. A transformation system for developing recursive programs. Journal of the ACM, 24:44–67, 1977.
R. S. Bird. Using circular programs to eliminate multiple traverals of data. Acta Informatica, 21:239–250, 1984.
R. M. Burstall, D. B. McQueen, and D. T. Sannella. Hope: an experimental applicative language. In Proceedings of the 1980 ACM Symposium on Lisp and Functional Programming, pages 136–143, Stanford, CA, August 1980.
L. M. Chirica and D. F. Martin. An order-algebraic definition of knuthian semantics. Math. Systems Theory, 13:1–27, 1979.
Pierre Deransart, Martin Jourdan, and Bernard Lorho. A Survey on Attribute Grammars, Part III: Classified Bibliography. Rapport de Recherche 417, Inria, Rocquencourt, France, June 1985.
Pierre Deransart, Martin Jourdan, and Bernard Lorho. A Survey on Attribute Grammars, Part II: Review of Existing Systems. Rapport de Recherche 510, Inria, Rocquencourt, France, March 1986.
Pierre Deransart, Martin Jourdan, and Bernard Lorho. A Survey on Attribute Grammars, Part I: Main Results on Attribute Grammars. Rapport de Recherche 485, Inria, Rocquencourt, France, January 1986.
H. Ganzinger and R. Giegerich. Attribute coupled grammars. In Proceedings of the SIGPLAN '84 Symposium on Compiler Construction, pages 157–170, Montreal, 1984.
M. Gordon, R. Milner, and C. Wadsworth. Edinburgh Lcf. Volume 78 of Lecture Notes in Computer Science, Springer-Verlag, 1979.
R. J. M. Hughes. Lazy memo-functions. In Proceedings 1985 Conference on Functional Programming Languages and Computer Architecture, Nancy, France, 1985.
S. C. Johnson. Yacc—Yet Another Compiler Compiler. Technical Report 32, Bell labs, 1975. Also in Unix Programmer's Manual, Volume 2B.
T. Johnsson. Efficient compilation of lazy evaluation. In Proceedings of the SIGPLAN '84 Symposium on Compiler Construction, pages 58–69, Montreal, 1984.
T. Johnsson. Lambda lifting: transforming programs to recursive equations. In Proceedings 1985 Conference on Functional Programming Languages and Computer Architecture, Nancy, France, 1985.
Mehdi Jazayeri, William F. Ogden, and William C. Rounds. The intrinsically exponential complexity of the circularity problem for attribute grammars. Communications of the ACM, 18:697–706, 1975.
M. Jourdan. An optimal-time recursive evaluator for attribute grammars. In Proceedings of 6th Int. Symp. on Programming, LNCS 167, pages 167–178, Springer-Verlag, April 1984.
Takuya Katayama. Translation of attribute grammars into procedures. ACM Trans. on Programming Languages and Systems, 6(3):345–369, July 1984.
R. M. Keller and G. Lindstrom. Applications of feedback in functional programming. Technical Report, University of Utah, Salt Lake City, April 1981.
Donald E. Knuth. Semantics of context-free languages. Math. Systems Theory, 2:127–145, 1968.
B. Mayoh. Attribute grammars and mathematical semantics. SIAM J. of Computing, 10(3):503–518, August 1981.
R. Milner. Standard ML proposal. Polymorphism: The ML/LCF/Hope Newsletter, 1(3), January 1984.
L. Paulson. A semantics-directed compiler generator. In Proc. 9th POPL, 1982.
D. A. Turner. Sasl Language Manual. Technical report, University of St. Andrews, 1976.
D. A. Turner. Miranda: A non-strict language with polymorphic types. In Proceedings 1985 Conference on Functional Programming Languages and Computer Architecture, pages 1–16, Nancy, France, 1985.
G. Uddeborg. A Functional Parser Generator. In preparation.
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 1987 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Johnsson, T. (1987). Attribute grammars as a functional programming paradigm. In: Kahn, G. (eds) Functional Programming Languages and Computer Architecture. FPCA 1987. Lecture Notes in Computer Science, vol 274. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-18317-5_10
Download citation
DOI: https://doi.org/10.1007/3-540-18317-5_10
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-18317-4
Online ISBN: 978-3-540-47879-9
eBook Packages: Springer Book Archive