On the relation between context-free grammars and parsing expression grammars

Context-Free Grammars (CFGs) and Parsing Expression Grammars (PEGs) have several similarities and a few differences in both their syntax and semantics, but they are usually presented through formalisms that hinder a proper comparison. In this paper we present a new formalism for CFGs that highlights...

Full description

Saved in:
Bibliographic Details
Published inScience of computer programming Vol. 89; pp. 235 - 250
Main Authors Mascarenhas, Fabio, Medeiros, Sérgio, Ierusalimschy, Roberto
Format Journal Article
LanguageEnglish
Published Elsevier B.V 01.09.2014
Subjects
Online AccessGet full text

Cover

Loading…
More Information
Summary:Context-Free Grammars (CFGs) and Parsing Expression Grammars (PEGs) have several similarities and a few differences in both their syntax and semantics, but they are usually presented through formalisms that hinder a proper comparison. In this paper we present a new formalism for CFGs that highlights the similarities and differences between them. The new formalism borrows from PEGs the use of parsing expressions and the recognition-based semantics. We show how one way of removing non-determinism from this formalism yields a formalism with the semantics of PEGs. We also prove, based on these new formalisms, how LL(1) grammars define the same language whether interpreted as CFGs or as PEGs, and also show how strong-LL(k), right-linear, and LL-regular grammars have simple language-preserving translations from CFGs to PEGs. Once these classes of CFGs can be automatically translated to equivalent PEGs, we can reuse classic top-down grammars in PEG-based tools. •We present new formalizations of CFGs and PEGs, based on natural semantics.•We discuss the correspondence between the languages of CFGs and PEGs.•We show transformations from classes of CFGs to equivalent PEGs.•Transformations of LL(1), strong-LL(k) and LL-regular grammars are presented.•The transformations preserve the structure of the original grammars.
ISSN:0167-6423
1872-7964
DOI:10.1016/j.scico.2014.01.012