Derivative Grammars: A Symbolic Approach to Parsing with Derivatives

被引:5
|
作者
Henriksen, Ian [1 ]
Bilardi, Gianfranco [2 ]
Pingali, Keshav [3 ]
机构
[1] Univ Texas Austin, Oden Inst Computat Engn & Sci, 201 E 24th St,POB 4-102, Austin, TX 78712 USA
[2] Univ Padua, Dipartimento Ingn Informaz, Via Gradenigo 6-B, I-35131 Padua, Italy
[3] Univ Texas Austin, Dept Comp Sci, 2317 Speedway, Austin, TX 78712 USA
来源
基金
美国国家科学基金会;
关键词
context-free grammars; parsing with derivatives; Earley's algorithm;
D O I
10.1145/3360553
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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.
引用
收藏
页数:28
相关论文
共 50 条
  • [1] Derivatives of Parsing Expression Grammars
    Moss, Aaron
    [J]. ELECTRONIC PROCEEDINGS IN THEORETICAL COMPUTER SCIENCE, 2017, (252): : 180 - 194
  • [2] Look Ma, No Input Samples! Mining Input Grammars from Code with Symbolic Parsing
    Bettscheider, Leon
    Zeller, Andreas
    [J]. COMPANION PROCEEDINGS OF THE 32ND ACM INTERNATIONAL CONFERENCE ON THE FOUNDATIONS OF SOFTWARE ENGINEERING, FSE COMPANION 2024, 2024, : 522 - 526
  • [3] PARSING DEPENDENCY GRAMMARS
    LOMBARDO, V
    [J]. LECTURE NOTES IN ARTIFICIAL INTELLIGENCE, 1991, 549 : 291 - 300
  • [4] Interval Parsing Grammars for File Format Parsing
    Zhang, Jialun
    Morrisett, Greg
    Tan, Gang
    [J]. PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL, 2023, 7 (PLDI):
  • [5] A PREPROCESSOR FOR YACC OR A POOR MANS APPROACH TO PARSING ATTRIBUTED GRAMMARS
    VANKATWIJK, J
    [J]. SIGPLAN NOTICES, 1983, 18 (10): : 12 - 15
  • [6] LR parsing for conjunctive grammars
    Okhotin, Alexander
    [J]. Grammars, 2002, 5 (02): : 81 - 124
  • [7] Tunnel Parsing with Ambiguous Grammars
    Handzhiyski, Nikolay
    Somova, Elena
    [J]. CYBERNETICS AND INFORMATION TECHNOLOGIES, 2023, 23 (02) : 34 - 53
  • [8] DETERMINISTIC PARSING OF AMBIGUOUS GRAMMARS
    AHO, AV
    JOHNSON, SC
    ULLMAN, JD
    [J]. COMMUNICATIONS OF THE ACM, 1975, 18 (08) : 441 - 452
  • [9] Parsing spatial graph grammars
    Kong, J
    Zhang, K
    [J]. 2004 IEEE SYMPOSIUM ON VISUAL LANGUAGES AND HUMAN CENTRIC COMPUTING: PROCEEDINGS, 2004, : 99 - 101
  • [10] LR parsing for Boolean grammars
    Okhotin, A
    [J]. DEVELOPMENTS IN LANGUAGE THEORY, PROCEEDINGS, 2005, 3572 : 362 - 373