Derivative grammars: a symbolic approach to parsing with derivatives
Autor: | Keshav Pingali, Ian Henriksen, Gianfranco Bilardi |
---|---|
Rok vydání: | 2019 |
Předmět: |
Functional programming
Earley’s algorithm Parsing Programming language LR parser Computer science Parsing with derivatives 020207 software engineering 02 engineering and technology Context-free grammar computer.software_genre Earley parser Grammars and context-free languages TheoryofComputation_MATHEMATICALLOGICANDFORMALLANGUAGES Rule-based machine translation 020204 information systems 0202 electrical engineering electronic engineering information engineering Haskell Theory of computation Grammars and context-free languages Parsing with derivatives Earley’s algorithm Lazy evaluation Safety Risk Reliability and Quality computer Software Theory of computation computer.programming_language |
Zdroj: | Proceedings of the ACM on Programming Languages. 3:1-28 |
ISSN: | 2475-1421 |
DOI: | 10.1145/3360553 |
Popis: | We present a novel approach to context-free grammar parsing that is based on generating a sequence of grammars called derivative grammars from a given context-free grammar and input string. The generation of the derivative grammars is described by a few simple inference rules. We present an O ( n 2 ) space and O ( n 3 ) time recognition algorithm, which can be extended to generate parse trees in O ( n 3 ) time and O ( n 2 log n ) space. Derivative grammars can be viewed as a symbolic approach to implementing the notion of derivative languages , which was introduced by Brzozowski. Might and others have explored an operational approach to implementing derivative languages in which the context-free grammar is encoded as a collection of recursive algebraic data types in a functional language like Haskell. Functional language implementation features like knot-tying and lazy evaluation are exploited to ensure that parsing is done correctly and efficiently in spite of complications like left-recursion. In contrast, our symbolic approach using inference rules can be implemented easily in any programming language and we obtain better space bounds for parsing. Reifying derivative languages by encoding them symbolically as grammars also enables formal connections to be made for the first time between the derivatives approach and classical parsing methods like the Earley and LL/LR parsers. In particular, we show that the sets of Earley items maintained by the Earley parser implicitly encode derivative grammars and we give a procedure for producing derivative grammars from these sets. Conversely, we show that our derivative grammar recognizer can be transformed into the Earley recognizer by optimizing some of its bookkeeping. These results suggest that derivative grammars may provide a new foundation for context-free grammar recognition and parsing. |
Databáze: | OpenAIRE |
Externí odkaz: |