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

  • Authors:
  • Hayo Thielecke

  • Affiliations:
  • University of Birmingham, Birmingham, United Kingdom, UK

  • Venue:
  • Proceedings of the 14th symposium on Principles and practice of declarative programming
  • Year:
  • 2012

Quantified Score

Hi-index 0.00

Visualization

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.