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.
CITATION STYLE
Johnsson, T. (1987). Attribute grammars as a functional programming paradigm. In Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics) (Vol. 274 LNCS, pp. 154–173). Springer Verlag. https://doi.org/10.1007/3-540-18317-5_10
Mendeley helps you to discover research relevant for your work.