Context-aware scanning for parsing extensible languages

This paper introduces new parsing and context-aware scanning algorithms in which the scanner uses contextual information to disambiguate lexical syntax. The parser uses a slightly modified LR-style algorithm that passes to the scanner the set of valid symbols that the scanner may return at that point in parsing. This set is those terminals whose entries in the parse table for the current parse state are shift, reduce, or accept, but not error. The scanner then only returns tokens in this set. An analysis is given that can statically verify that the scanner will never return more than one token for a single input. Context-aware scanning is especially useful when parsing and scanning extensible languages in which domain specific languages can be embedded. It has been used in extensible versions of Java 1.4 and ANSI C. We illustrate this approach with a declarative specification of a subset of Java and extensions that embed SQL queries and Boolean expression tables into Java.

[1]  Eric Van Wyk,et al.  Flexible and Extensible Notations for Modeling Languages , 2007, FASE.

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

[3]  Eric Van Wyk,et al.  Forwarding in Attribute Grammars for Modular Language Design , 2002, CC.

[4]  Adrian Johnstone,et al.  Generalised Parsing: Some Costs , 2004, CC.

[5]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[6]  Eric Van Wyk,et al.  Silver: an Extensible Attribute Grammar System , 2008, Electron. Notes Theor. Comput. Sci..

[7]  R. Nigel Horspool,et al.  Schrödinger's token , 2001, Softw. Pract. Exp..

[8]  George C. Necula,et al.  Elkhound: A Fast, Practical GLR Parser Generator , 2003, CC.

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

[10]  Constance L. Heitmeyer,et al.  SCR*: A Toolset for Specifying and Analyzing Software Requirements , 1998, CAV.

[11]  E. V. Wyk Context-Aware Scanning : Specification , Implementation , and Applications — DRAFT ∗ , 2007 .

[12]  Andrew Begel,et al.  XGLR - an algorithm for ambiguity in programming languages , 2006, Sci. Comput. Program..

[13]  Susan L. Graham,et al.  Incremental analysis of real programming languages , 1997, PLDI '97.

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

[15]  Eric Van Wyk,et al.  Attribute Grammar-Based Language Extensions for Java , 2007, ECOOP.

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

[17]  Donald E. Knuth,et al.  On the Translation of Languages from Left to Right , 1965, Inf. Control..

[18]  Constance L. Heitmeyer,et al.  SCR: a toolset for specifying and analyzing requirements , 1995, COMPASS '95 Proceedings of the Tenth Annual Conference on Computer Assurance Systems Integrity, Software Safety and Process Security'.