arXiv:2608.29592cs.PLAug 2026

Manuscript Offprint

arXiv:2608.29592

Separating Parsing Expression Grammars using Cell-Probe Lower Bounds

Jungyeom Kim, Jihyeok Park

Abstract

We resolve three open problems concerning parsing expression grammars (PEGs). We construct a single language CC satisfying C∈LIN∩PEGC \in \text{LIN} \cap \text{PEG} and CR∈LIN∖PEGC^R \in \text{LIN} \setminus \text{PEG}. This proves that some linear context-free language is not a PEG language and that PEG languages are not closed under reversal, confirming a conjecture of Loff, Moreira, and Reis. Factoring the same witness resolves the concatenation-closure problem of Rubtsov and Chudinov negatively, in the strong form PEG⋅REG⊈PEG\text{PEG} \cdot \text{REG} \not\subseteq \text{PEG} despite REG⋅PEG⊆PEG\text{REG} \cdot \text{PEG} \subseteq \text{PEG}. It also refutes closure under Kleene star, homomorphisms, and substitutions.

Our main technique converts scaffolding automata (SCAs), which characterize reversals of PEG languages, into dynamic data structures in the cell-probe model. For any suitably local serialization of a problem with preprocessing, updates, and a final Boolean query, an SCA recognizer yields an exact deterministic cell-probe data structure whose operation costs are proportional to the corresponding encoding lengths. Cell-probe lower bounds can therefore prove SCA non-membership and, by reversal, PEG non-membership. We apply this transfer to Multiphase Inner Product using one-symbol update blocks and a query suffix of length O(log⁡n)\mathcal{O}(\log n), while keeping both the language and its reversal linear context-free. Ko's cell-probe lower bound then yields the witness above. The arguments are additionally formalized in Lean 4.

1 Introduction

Parsing expression grammars (PEGs) are formal grammars that define languages through parsing rules, rather than through generative rules as in context-free grammars (CFGs) [5]. PEGs have several notable advantages. In particular, their prioritized choice gives them deterministic recognition semantics and makes them unambiguous by construction [5]. Moreover, PEGs can be parsed in linear time using a packrat parser, at the cost of additional memory [4]. Packrat parsing is essentially a memoization technique based on dynamic programming. Owing to these advantages, PEGs have been adopted in practical parser implementations. CPython replaced its LL(1) parser with a PEG-based parser in Python 3.9 [20].

Although PEGs are becoming increasingly influential in parsing, their theoretical properties are not yet fully understood. PEGs are highly expressive, and every deterministic context-free language can be expressed by a PEG [2, 5]. Furthermore, PEGs can express some non-context-free languages. One such example is {anbncn∣n≥0}\{a^n b^n c^n \mid n \geq 0\} [2, 5]. Therefore, writing PEG, DCFL, and CFL for the classes of languages defined by PEGs, deterministic context-free grammars, and context-free grammars, respectively, both DCFL ⊆\subseteq PEG and PEG ⊈\not\subseteq CFL hold. PEGs are, moreover, closed under complement and intersection, owing to the expressive power of their lookahead operators [5]. Despite this expressive power, the following two questions have remained open:

Q1. Does CFL ⊆\subseteq PEG hold?

Q2. Is the class of PEG languages closed under reversal, that is, does PEG = PEG R^{R} hold?

We prove that there exists a linear context-free language that cannot be recognized by any PEG and that the class of PEG languages is not closed under reversal.

Both results require showing that no PEG recognizes a given language, which is particularly challenging. Loff, Moreira, and Reis asked whether the language of palindromes has a PEG, observing that none was known even for that comparatively simple language [12]; our witness is instead a language built for the reduction below. Other language classes have well-established techniques for proving that a given language does not belong to them. For example, regular languages can be characterized using the Myhill–Nerode theorem, while context-free languages can often be ruled out using the pumping lemma [15, 16, 1]. By contrast, no comparably effective tool is known for PEGs. Indeed, Loff, Moreira, and Reis proved that PEGs do not admit a pumping lemma analogous to the one for context-free languages [12].

Known positive results do not close this gap from the other side either: translations into PEGs exist only for restricted grammar classes. Mascarenhas, Medeiros, and Ierusalimschy gave language-preserving translations from several subclasses of CFGs, including LL-regular grammars, to PEGs [14]. Our first result shows that such translations cannot cover all context-free languages.

The difficulty of proving PEG non-membership has motivated several automata-theoretic models for studying the expressive power of PEGs. Loff, Moreira, and Reis introduced scaffolding automata (SCAs), a finite-automaton model enriched with a pointer structure, and conjectured that the answer to Q2 is negative [12]. Rubtsov and Chudinov later introduced deterministic pointer pushdown automata as another such model: pushdown automata that record with each stack symbol the input position at which it was pushed and may return the input head there when the symbol is popped [19]. Among these models, our proof builds on scaffolding automata, which we now describe in more detail.

An SCA extends a finite automaton with an append-only persistent pointer structure called a scaffold. As the automaton reads each input symbol, it appends a new node carrying a label and a constant number of backward or self pointers. The scaffold thus grows only by edges pointing toward already-created nodes, encoding the input history in chronological order; this inherent directionality provides important intuition for why reversal may substantially alter the expressive power of PEGs. The key relationship between PEGs and SCAs is captured by the following characterization. For every language H,

H∈PEG  ⟺  HR∈SCA,H\in\mathrm{PEG}\iff H^{R}\in\mathrm{SCA},

where SCA denotes the class of languages decided by SCAs. This characterization reduces PEG lower bounds to SCA lower bounds, but it does not by itself supply such bounds.

Although the scaffold retains the entire input history, an SCA can access only a constant-size portion of it while processing each input symbol. We exploit this access bottleneck through a framework that interprets an SCA as an online data structure. We call a Boolean data-structure problem three-stage if, for each size parameter n, it consists of preprocessing data, a sequence of updates, and a final query with a Boolean answer. We serialize these stages as a prefix, a sequence of update blocks, and a query suffix, so that membership of the resulting string in a fixed language K determines the Boolean answer. Each block depends only on the operation it encodes (an update block may also depend on its position in the sequence), and every complete serialization has polynomial length. If, in addition, the update blocks and the query suffix have lengths at most a(n)a(n) and b(n)b(n), respectively, we call K an (a,b)(a,b)-SCA encoding (Definition 3.2).

Our transfer theorem (Theorem 3.5) states that if such an encoding is decided by an SCA, then the underlying problem admits an exact deterministic cell-probe data structure with word size Θ(log⁡n)\Theta(\log n), update time O(a(n))\mathcal{O}(a(n)), query time O(b(n))\mathcal{O}(b(n)), and polynomially many memory cells. Contrapositively, excluding such a data structure establishes that the encoding lies outside SCA, and the PEG–SCA characterization then places its reversal outside PEG.

We apply our strategy to Multiphase Inner Product, a variant of Pătrașcu's Multiphase Problem [17] for which Ko proved the sufficiently strong lower bound used here [9]. Our encoding uses constant-length update blocks and a query suffix of length O(log⁡n)\mathcal{O}(\log n). Consequently, any query-time lower bound of ω(log⁡n)\omega(\log n), that is, any bound exceeding the logarithmic barrier, suffices for our purposes. The resulting witness language and its reversal are both linear context-free; we write LIN for the class of linear context-free languages.

The same witness also resolves further closure questions. We prove that PEG languages are closed under neither unrestricted concatenation nor Kleene star, with concatenation failing even in the strong form

PEG⋅REG⊈PEG.\mathrm{PEG}\cdot\mathrm{REG}\not\subseteq\mathrm{PEG}.

Our main contributions are as follows:

  1. We introduce a framework that transforms an SCA encoding of a dynamic data-structure problem into a concrete exact deterministic cell-probe data structure with bounded word size, update time, and query time.

  2. Using this framework, we construct a language C satisfying

C∈LIN∩PEGandCR∈LIN∖PEG.C\in LIN\cap PEG\qquad and\qquad C^{R}\in LIN\setminus PEG.

Consequently, LIN ⊈\not\subseteq PEG and hence CFL ⊈\not\subseteq PEG, while the class of PEG languages is not closed under reversal.

  1. From the same witness, we resolve the open closure questions for concatenation and Kleene star negatively. As further consequences, PEG languages are not closed under homomorphisms or substitutions.

Beyond these main contributions, we provide a Lean 4 formalization of the separation argument for the witness language, whose precise scope and trust assumptions are described in the Formal Verification section.