Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/2370776.2370789acmotherconferencesArticle/Chapter ViewAbstractPublication PagesppdpConference Proceedingsconference-collections
research-article

Functional semantics of parsing actions, and left recursion elimination as continuation passing

Published: 19 September 2012 Publication History

Abstract

Parsers, whether constructed by hand or automatically via a parser generator tool, typically need to compute some useful semantic information in addition to the purely syntactic analysis of their input. Semantic actions may be added to parsing code by hand, or the parser generator may have its own syntax for annotating grammar rules with semantic actions. In this paper, we take a functional programming view of such actions. We use concepts from the semantics of mostly functional programming languages and adapt them to give meaning to the actions of the parser. Specifically, the semantics is inspired by the categorical semantics of lambda calculi and the use of premonoidal categories for the semantics of effects in programming languages. This framework is then applied to our leading example, the transformation of grammars to eliminate left recursion. The syntactic transformation of left-recursion elimination leads to a corresponding semantic transformation of the actions for the grammar. We prove the semantic transformation correct and relate it to continuation passing style, a widely studied transformation in lambda calculi and functional programming.

References

[1]
A. V. Aho, R. Sethi, and J. D. Ullman. Compilers - Principles, Techniques and Tools. Addison Wesley, 1985.
[2]
A. W. Appel and J. Palsberg. Modern Compiler Implementation in Java. Cambridge University Press, 1997.
[3]
A. Baars, S. Doaitse Swierstra, and M. Viera. Typed transformations of typed grammars: The left corner transform. Electron. Notes Theor. Comput. Sci., 253:51--64, September 2010. ISSN 1571-0661. URL http://dx.doi.org/10.1016/j.entcs.2010.08.031.
[4]
C. Barker. Continuations in natural language. In Proceedings of the Fourth ACM SIGPLAN Continuations Workshop (CW'04). University of Birmingham Computer Science technical report CSR-04-1, 2004.
[5]
J. Berdine, P. W. O'Hearn, U. Reddy, and H. Thielecke. Linear continuation passing. Higher-order and Symbolic Computation, 15 (2/3):181--208, 2002.
[6]
O. Danvy and A. Filinski. Representing control, a study of the CPS transformation. Mathematical Structures in Computer Science, 2(4): 361--391, Dec. 1992.
[7]
M. Felleisen and D. P. Friedman. Control operators, the SECDmachine, and the λ-calculus. In M. Wirsing, editor, Formal Description of Programming Concepts, pages 193--217. North-Holland, 1986.
[8]
J. A. Goguen, J. W. Thatcher, E. G. Wagner, and J. B. Wright. Initial algebra semantics and continuous algebras. Journal of the ACM, 24 :68--95, 1977.
[9]
C. A. Gunther. Semantics of Programming Languages. MIT Press, 1992.
[10]
J. Hughes. Generalising monads to arrows. Science of Computer. Programming, 37(1--3):67--111, 2000.
[11]
G. Hutton and E. Meijer. Monadic parsing in Haskell. Journal of Functional Programming, 8(4):437--444, 1998.
[12]
D. E. Knuth. Semantics of context-free languages. Mathematical Systems Theory, 2(2):127--145, 1968.
[13]
J. Lambek. The mathematics of sentence structure. American Mathematical Monthly, 65(3):154--170, 1958.
[14]
P. J. Landin. The mechanical evaluation of expressions. The Computer Journal, 6(4):308--320, Jan. 1964.
[15]
W. Lohmann, G. Riedewald, and M. Stoy. Semantics-preserving migration of semantic rules during left recursion removal in attribute grammars. Electronic Notes in Theoretical Compututer Science, 110: 133--148, 2004.
[16]
S. Mac Lane. Categories for the Working Mathematician. Springer Verlag, 1971.
[17]
E. Moggi. Computational lambda calculus and monads. In Proceedings, Fourth Annual Symposium on Logic in Computer Science (LICS), pages 14--23, 1989. ISBN 0-8186-1954-6.
[18]
K. B. Oege de Moor and S. D. Swierstra. First class attribute grammars. Informatica: An International Journal of Computing and Informatics, 24(2):329--341, June 2000. ISSN ISSN 0350-5596. Special Issue: Attribute grammars and their Applications.
[19]
T. Parr and K. Fisher. LL(*): the foundation of the ANTLR parser generator. In PLDI. ACM, 2011. ISBN 978-1-4503-0663-8.
[20]
R. Paterson. A new notation for arrows. In ICFP. ACM, 2001. ISBN 1-58113-415-0.
[21]
G. D. Plotkin. Call-by-name, call-by-value, and the λ-calculus. Theoretical Computer Science, 1(2):125--159, 1975.
[22]
J. Power and E. Robinson. Premonoidal categories and notions of computation. Mathematical Structures in Computer Science, 7(5): 453--468, 1997.
[23]
J. Power and H. Thielecke. Environments, continuation semantics and indexed categories. In M. Abadi and T. Ito, editors, Proceedings TACS'97, number 1281 in LNCS, pages 391--414. Springer Verlag, 1997.
[24]
J. Power and H. Thielecke. Closed Freyd- and kappa-categories. In J. Wiedermann, P. van Emde Boas, and M. Nielsen, editors, Proceedings 26th International Colloquium on Automata, Languages and Programming (ICALP), number 1644 in LNCS, pages 625--634. Springer Verlag, 1999.
[25]
J. C. Reynolds. Definitional interpreters for higher-order programming languages. In Proceedings of the 25th ACM National Conference, pages 717--740. ACM, Aug. 1972.
[26]
J. C. Reynolds. Definitional interpreters for higher-order programming languages. Higher-Order and Symbolic Computation, 11(4):363--397, 1998. Reprint of a conference paper {25}.
[27]
D. Sitaram and M. Felleisen. Control delilmiters and their hierarchies. Lisp and Symbolic Computation, 3(1):67--99, 1990.
[28]
G. Steele. Rabbit: A compiler for Scheme. Technical Report AI TR 474, Artificial Intelligence Laboratory, Massachusetts Institute of Technology, May 1978.
[29]
C. Strachey and C. P. Wadsworth. Continuations: A mathematical semantics for handling full jumps. Technical Monograph PRG-11, Oxford University Computing Laboratory, Jan. 1974.
[30]
S. D. Swierstra. Combinator parsers: a short tutorial. In A. Bove, L. Barbosa, A. Pardo, and J. Sousa Pinto, editors, Language Engineering and Rigorous Software Development, volume 5520 of LNCS, pages 252--300. Spinger, 2009.
[31]
H. Thielecke. From control effects to typed continuation passing. In Principles of Programming Languages (POPL'03), pages 139--149. ACM, 2003.
[32]
P. Wadler. Theorems for free! In Proceedings of the 4th International Conference on Functional Programming and Computer Architecture (FPCA'89), London, 11--13 September 1989, pages 347--359. ACM Press, New York, 1989.

Cited By

View all

Index Terms

  1. Functional semantics of parsing actions, and left recursion elimination as continuation passing

      Recommendations

      Comments

      Information & Contributors

      Information

      Published In

      cover image ACM Other conferences
      PPDP '12: Proceedings of the 14th symposium on Principles and practice of declarative programming
      September 2012
      226 pages
      ISBN:9781450315227
      DOI:10.1145/2370776
      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

      Sponsors

      • Kuleuven Belgium: Kuleuven Belgium

      In-Cooperation

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      Published: 19 September 2012

      Permissions

      Request permissions for this article.

      Check for updates

      Author Tags

      1. continuations
      2. functional programming
      3. lambda calculus
      4. parsing
      5. semantics
      6. types
      7. verification

      Qualifiers

      • Research-article

      Conference

      PPDP'12
      Sponsor:
      • Kuleuven Belgium

      Acceptance Rates

      Overall Acceptance Rate 230 of 486 submissions, 47%

      Contributors

      Other Metrics

      Bibliometrics & Citations

      Bibliometrics

      Article Metrics

      • 0
        Total Citations
      • 107
        Total Downloads
      • Downloads (Last 12 months)3
      • Downloads (Last 6 weeks)0
      Reflects downloads up to 10 Feb 2025

      Other Metrics

      Citations

      Cited By

      View all

      View Options

      Login options

      View options

      PDF

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      Figures

      Tables

      Media

      Share

      Share

      Share this Publication link

      Share on social media