Hostname: page-component-586b7cd67f-t7fkt Total loading time: 0 Render date: 2024-11-23T21:40:44.612Z Has data issue: false hasContentIssue false

Combinators for parsing expressions

Published online by Cambridge University Press:  07 November 2008

Steve Hill
Affiliation:
University of Kent, Canterbury, UK
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

This paper describes a scheme for constructing parsers based on the top-down combinator approach. In particular, it describes a set of combinators for parsing expressions described by ambiguous grammars with precedence and associativity rules. The new combinators embody the mechanical grammar manipulations typically employed to remove left-recursion and hence help to avoid the possibility of a non-terminating parser. A number of approaches to the problem are described—the most elegant and efficient method is based on continuation passing. As a practical demonstration, a parser for the expression part of the C programming language is presented. The expression combinators are general, and may be constructed from any suitable set of top-down combinators. A comparison with parser generators shows that the combinator approach is most applicable for rapid development.

Type
Articles
Copyright
Copyright © Cambridge University Press 1996

References

Aho, A. V., Sethi, R. and Ullman, J. D. (1986) Compilers – Principles, Techniques and Tools. Addison-Wesley.Google Scholar
Appel, A. W. (1992) Compiling with Continuations. Combridge University Press.Google Scholar
Augustsson, L. (1994) The chalmers haskell compiler: hbc/hbi. (Available via anonymous ftp from ftp.cs.chalmers.se.)Google Scholar
Burge, W. H. (1975) Recursive Programming Techniques. Addison Wesley.Google Scholar
Fairbairn, J. (1986) Making form follow function. Technical Report 89, University of Cambridge, Computer Laboratory, June.Google Scholar
Gill, A. and Marlow, S. (1995) Happy Manual. (Available via anonymous ftp from ftp.dcs.gla.ac.uk in pub/haskell/happy.)Google Scholar
Hudak, P., Peyton Jones, S. and Wadler, P. L. (editors) (1992) Report on the functional programming language Haskell, a non-strict purely functional language (version 1.2). ACM SIGPLAN Notices 27(5) May.CrossRefGoogle Scholar
Hutton, G. (1992) Higher-order functions for parsing. J. Functional Programming 2(3) July.CrossRefGoogle Scholar
Johnson, S. C. (1978) Yacc: Yet Another Compiler Compiler, July. UNIX on-line documentation.Google Scholar
Jones, M. P. (1991) Introduction to Gofer 2.20. (Available via anonymous ftp from nebula.cs.yale.edu.)Google Scholar
Lesk, M. E. and Schmidt, E. (1975) Lex – A Lexical Analyser Generator, July. UNIX on-line documentation.Google Scholar
Mogensen, T. (1993) Ratatosk: A Parser Generator and Scanner Generator for Gofer. (Avaliable via anonymous ftp from ftp.diku.dk.)Google Scholar
Peyton Jones, S. L. (1985) Yacc in sasl – an exercise in functional programming. Software Practice and Experience 15(8):807820.CrossRefGoogle Scholar
Turner, D. A. (1986) An overview of Miranda. SIGPLAN Notices December.CrossRefGoogle Scholar
Wadler, P. (1985) How to replace failure by a list of successes. In: Lecture Notes in Computer Science 201. Springer-Verlag.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.