The formalization and implementation of Adaptable Parsing Expression Grammars

The term "extensible language" is especially used when a language allows the extension of its own concrete syntax and the definition of the semantics of new constructs. Most popular tools designed for automatic generation of syntactic analysers do not offer any adequate resources for the specification of extensible languages. When used in the implementation of features like syntax macro definitions, these tools usually impose severe restrictions. For example, it may be required that macro definitions and their use reside in different files; or it may be impossible to perform the syntax analysis in one single pass. We claim that one of the main reasons for these limitations is the lack of appropriate formal models for the definition of the syntax of extensible languages.This paper presents the design and formal definition of Adaptable Parsing Expression Grammars, an extension to the Parsing Expression Grammar (PEG) model that allows the manipulation of its own production rules during the analysis of an input string. The proposed model compares favourably with similar approaches for the definition of the syntax of extensible languages. An implementation of the model is also presented, simulating the behaviour of packrat parsers. Among the challenges for this implementation is the use of attributes and on the fly modifications on the production rules at parse time, features not present in standard PEG. This approach has been used on the definition of a real extensible language, and initial performance tests suggest that the model may work well in practice. We propose an adaptable model based on Parsing Expression Grammars.We added attributes to PEG so extensibility is achieved by means of grammar attributes.The model is formally defined.The implementation of the adaptable model is detailed.The adaptable model preserves PEG legibility.

[1]  Sukyoung Ryu Parsing Fortress syntax , 2009, PPPJ '09.

[2]  Zoltan Somogyi,et al.  DCGs + Memoing = Packrat Parsing but Is It Worth It? , 2008, PADL.

[3]  Eelco Visser,et al.  Stratego/XT 0.17. A language and toolset for program transformation , 2008, Sci. Comput. Program..

[4]  Pier Stanislao Paolucci,et al.  Dynamic parsers and evolving grammars , 1992, SIGP.

[5]  Shan Shan Huang,et al.  Generating AspectJ Programs with Meta-AspectJ , 2004, GPCE.

[6]  David Walker,et al.  Semantics and algorithms for data-dependent grammars , 2010, POPL '10.

[7]  Bryan Ford,et al.  Packrat Parsing: Simple, Powerful, Lazy, Linear Time , 2006, ICFP 2002.

[8]  Eric E. Allen,et al.  Growing a Syntax , 2008 .

[9]  Sebastian Erdweg,et al.  SugarJ: library-based syntactic language extensibility , 2011, OOPSLA '11.

[10]  Eric Van Wyk,et al.  Silver: An extensible attribute grammar system , 2008, Sci. Comput. Program..

[11]  Mitchell Wand,et al.  Parsing reflective grammars , 2011, LDTA.

[12]  Eelco Visser,et al.  Scannerless Generalized-LR Parsing , 1997 .

[13]  Thomas W. Reps,et al.  Incremental Context-Dependent Analysis for Language-Based Editors , 1983, TOPL.

[14]  Boris Burshteyn,et al.  Generation and recognition of formal languages by modifiable grammars , 1990, SIGP.

[15]  D. B. Davis,et al.  Sun Microsystems Inc. , 1993 .

[16]  C. H. Flood,et al.  The Fortress Language Specification , 2007 .

[17]  Bryan Ford,et al.  Packet parsing : a practical linear-time algorithm with backtracking , 2002 .

[18]  Anthony M. Sloane,et al.  A Pure Object-Oriented Embedding of Attribute Grammars , 2010, LDTA.

[19]  Roman R. Redziejowski MOUSE: FROM PARSING EXPRESSIONS TO A PRACTICAL PARSER , 2015 .

[20]  Russell W. Quong,et al.  ANTLR: A predicated‐LL(k) parser generator , 1995, Softw. Pract. Exp..

[21]  Robert Grimm,et al.  Better extensibility through modular syntax , 2006, PLDI '06.

[22]  E. Visser A Family of Syntax Definition Formalisms , 1995 .

[23]  Pierre Boullier Dynamic grammars and semantic analysis , 1994 .

[24]  Ole Lehrmann Madsen,et al.  Extended Attribute Grammars , 1981, Comput. J..

[25]  Henning Christiansen,et al.  The syntax and semantics of extensible languages , 1988 .

[26]  Thomas W. Reps Optimal-time incremental semantic analysis for syntax-directed editors , 1982, POPL '82.

[27]  Eric Van Wyk,et al.  Verifiable composition of deterministic grammars , 2009, PLDI '09.

[28]  Henning Christiansen,et al.  A survey of adaptable grammars , 1990, SIGP.

[29]  Torbjörn Ekman,et al.  The JastAdd system - modular extensible compiler construction , 2007, Sci. Comput. Program..

[30]  Leonardo Vieira dos Santos Reis Adaptable parsing expression grammars , 2012, SBLP.

[31]  Eric Van Wyk,et al.  Verifiable Parse Table Composition for Deterministic Parsing , 2009, SLE.

[32]  Donald E. Knuth,et al.  Semantics of context-free languages , 1968, Mathematical systems theory.

[33]  Bryan Ford,et al.  Parsing expression grammars: a recognition-based syntactic foundation , 2004, POPL '04.

[34]  Ben Wegbreit Studies in Extensible Programming Languages , 1970, Outstanding Dissertations in the Computer Sciences.

[35]  Eelco Visser,et al.  Pure and declarative syntax definition: paradise lost and regained , 2010, OOPSLA.

[36]  Boris Burshteyn,et al.  USSA—universal syntax and semantics analyzer , 1992, SIGP.

[37]  Bryan Ford,et al.  Packrat parsing:: simple, powerful, lazy, linear time, functional pearl , 2002, ICFP '02.

[38]  John N. Shutt Recursive Adaptable Grammars , 1999 .

[40]  Henning Christiansen Adaptable Grammars for Non-Context-Free Languages , 2009, IWANN.

[41]  Eelco Visser,et al.  Disambiguation Filters for Scannerless Generalized LR Parsers , 2002, CC.

[42]  Terence Parr,et al.  LL(*): the foundation of the ANTLR parser generator , 2011, PLDI '11.

[43]  Chris Seaton,et al.  A Programming Language Where the Syntax and Semantics Are Mutable at Runtime , 2007 .