ComputingComputer ScienceNatural Language ProcessingProgramming LanguagesSyntaxGrammarParsingSyntactic AnalysisSyntactic ParsingSyntax AnalysisSyntax ParsingContext-free Grammar ParsingContext-free GrammarsExpressivenessLanguage ParsingLr ParsingParsing Expression GrammarsRegular ExpressionsSyntactic Ambiguity
Generative grammars such as CFGs and REs have long been used to describe programming language syntax, but their ability to express ambiguity makes them difficult to use for machine‑oriented languages. The paper proposes PEGs as a recognition‑based alternative to CFGs that eliminates ambiguity in machine‑oriented syntax. PEGs replace nondeterministic choice with prioritized choice, address expressiveness limits of CFGs and REs, and simplify syntax definitions by eliminating the need to separate lexical and hierarchical components. The authors show that any PEG admits a linear‑time parser, outperforming LR and generalized CFG parsers, and that PEGs are equivalent in recognition power to the minimal schemas TS/TDPL and gTS/GTDPL.
For decades we have been using Chomsky's generative system of grammars, particularly context-free grammars (CFGs) and regular expressions (REs), to express the syntax of programming languages and protocols. The power of generative grammars to express ambiguity is crucial to their original purpose of modelling natural languages, but this very power makes it unnecessarily difficult both to express and to parse machine-oriented languages using CFGs. Parsing Expression Grammars (PEGs) provide an alternative, recognition-based formal foundation for describing machine-oriented syntax, which solves the ambiguity problem by not introducing ambiguity in the first place. Where CFGs express nondeterministic choice between alternatives, PEGs instead use prioritized choice. PEGs address frequently felt expressiveness limitations of CFGs and REs, simplifying syntax definitions and making it unnecessary to separate their lexical and hierarchical components. A linear-time parser can be built for any PEG, avoiding both the complexity and fickleness of LR parsers and the inefficiency of generalized CFG parsing. While PEGs provide a rich set of operators for constructing grammars, they are reducible to two minimal recognition schemas developed around 1970, TS/TDPL and gTS/GTDPL, which are here proven equivalent in effective recognition power.
19
Rex Jaeschke · ACM SIGPLAN Notices · 1998 · 544 citations · Full text
Indexed Grammars—An Extension of Context-Free Grammars
Alfred V. Aho · Journal of the ACM · 1968 · 441 citations · Full text
The syntax definition formalism SDF—reference manual—
Jan Heering, Paul Hendriks, Paul Klint et al. · ACM SIGPLAN Notices · 1989 · 269 citations
Report on the Algorithmic Language ALGOL 68
B. J. Mailloux, J. E. L. Peck, C. H. A. Koster · Numerische Mathematik · 1969 · 267 citations