Macros for context-free grammars

  • Authors:
  • Peter Thiemann;Matthias Neubauer

  • Affiliations:
  • Institut für Informatik, Universität Freiburg, Germany;Institut für Informatik, Universität Freiburg, Germany

  • Venue:
  • Proceedings of the 10th international ACM SIGPLAN conference on Principles and practice of declarative programming
  • Year:
  • 2008

Quantified Score

Hi-index 0.00

Visualization

Abstract

Current parser generators are based on context-free grammars. Because such grammars lack abstraction facilities, the resulting specifications are often not easy to read. Fischer's macro grammars extend context-free grammars with macro-like productions thus providing the equivalent of procedural abstraction. However, their use is hampered by the lack of an efficient, off-the-shelf parsing technology for macro grammars. We define specialization for macro grammars to enable reuse of parsing technology for context-free grammars while facilitating the specification of a language with a macro grammar. This specialization yields context-free rules, but it does not always terminate. We present a sound and complete static analysis that applies to any macro grammar and decides whether specialization terminates for it and thus yields a (finite) context-free grammar. The analysis is based on an intuitive notion of self-embedding nonterminals, which is easy to check by hand. We have implemented the analysis as part of a preprocessing tool that transforms a Yacc grammar extended with macro productions to a standard Yacc grammar.