• Cite Icon47
  • https://doi.org/10.1145/2034574.2034801Copy DOI Icon

Parsing with derivatives

Show More
  • Abstract
  • Literature Map
  • References
  • Citations
  • Similar Papers
Abstract

We present a functional approach to parsing unrestricted context-free grammars based on Brzozowski's derivative of regular expressions. If we consider context-free grammars as recursive regular expressions, Brzozowski's equational theory extends without modification to context-free grammars (and it generalizes to parser combinators). The supporting actors in this story are three concepts familiar to functional programmers - laziness, memoization and fixed points; these allow Brzozowski's original equations to be transliterated into purely functional code in about 30 lines spread over three functions. Yet, this almost impossibly brief implementation has a drawback: its performance is sour - in both theory and practice. The culprit? Each derivative can double the size of a grammar, and with it, the cost of the next derivative. Fortunately, much of the new structure inflicted by the derivative is either dead on arrival, or it dies after the very next derivative. To eliminate it, we once again exploit laziness and memoization to transliterate an equational theory that prunes such debris into working code. Thanks to this compaction, parsing times become reasonable in practice. We equip the functional programmer with two equational theories that, when combined, make for an abbreviated understanding and implementation of a system for parsing context-free languages.

Similar Papers
  • PDF
  • Research Article
  • Citations5

Parsing with zippers (functional pearl)

  • Aug 02, 2020
  • Proceedings of the ACM on Programming Languages
  • Pierce Darragh +1
  • Research Article
  • Citations2

Product Derivatives of Regular Expressions

  • Jan 01, 2008
  • IPSJ Online Transactions
  • Taro Suzuki +1
  • PDF
  • Book Chapter
  • Citations1

A Proof Theory of ($$\omega $$-)Context-Free Languages, via Non-wellfounded Proofs

  • Jan 01, 2024
  • Anupam Das +1
  • Conference Article
  • Citations47

Back in Black: Towards Formal, Black Box Analysis of Sanitizers and Filters

  • May 01, 2016
  • George Argyros +3
  • Research Article
  • Citations1

Learning TOC - Begins

  • Apr 01, 2018
  • International Journal of Scientific Research in Science, Engineering and Technology
  • Vishal Prajapati +4
  • Book Chapter
  • Citations7

Certified Derivative-Based Parsing of Regular Expressions

  • Jan 01, 2016
  • Raul Lopes +2
  • Conference Article
  • Citations5

Analysis of grammatical evolutionary approaches to regular expression induction

  • Jun 01, 2011
  • Antonio Gonzalez-Pardo +1
  • Book Chapter

4 - Context-free grammar

  • Jan 01, 2023
  • Automata Theory and Formal Languages
  • Pallavi Vijay Chavan +1
  • Research Article
  • Citations5

On the degrees of non-regularity and non-context-freeness

  • Oct 24, 2019
  • Journal of Computer and System Sciences
  • Henning Bordihn +1
  • Conference Article
  • Citations1

Theory and practice of string solvers (invited talk abstract)

  • Jul 10, 2019
  • Adam Kiezun +4
  • Research Article
  • Citations6

Labelled BNF: a high-level formalism for defining well-behaved programming languages

  • Oct 18, 2003
  • Proceedings of the Estonian Academy of Sciences. Physics. Mathematics
  • Markus Forsberg +1
  • Research Article
  • Citations2

Introducing practical applications into a computational theory class

  • Dec 01, 2004
  • Journal of Computing Sciences in Colleges
  • William Hawkins +1
  • Book Chapter

Classical Language Equations and the Substitution Property

  • Jan 01, 1999
  • Ernst L Leiss
  • Single Book
  • Citations7

Logic and Language Models for Computer Science

  • Apr 21, 2022
  • Dana Richards +1
  • Research Article
  • Citations1

An Elementary Proof of the FMP for Kleene Algebra

  • Feb 06, 2026
  • Fundamenta Informaticae
  • Tobias Kappé
Cactus Communications logo

Copyright 2026 Cactus Communications. All rights reserved.