Abstract
Precedence and associativity declarations in systems like yacc resolve ambiguities in context-free grammars (CFGs) by specifying restrictions on allowed parses. However, they are special purpose and do not handle the grammatical restrictions that language designers need in order to resolve ambiguities like dangling else, the interactions between binary operators and functional if expressions in ML, and the interactions between object allocation and function calls in JavaScript. Often, language designers resort to restructuring their grammars in order to encode these restrictions, but this obfuscates the designer's intent and can make grammars more difficult to read, write, and maintain.
In this paper, we show how tree automata can modularly and concisely encode such restrictions. We do this by reinterpreting CFGs as tree automata and then intersecting them with tree automata encoding the desired restrictions. The results are then reinterpreted back into CFGs that encode the specified restrictions. This process can be used as a preprocessing step before other CFG manipulations and is well behaved. It performs well in practice and never introduces ambiguities or LR(k) conflicts.
- Ali Afroozeh, Mark van den Brand, Adrian Johnstone, Elizabeth Scott, and Jurgen Vinju. Safe Specification of Operator Precedence Rules, pages 137–156. Springer, Cham, 2013. ISBN 978-3-319-02654-1. doi: 10.1007/978-3-319-02654-1_8. Google Scholar
Cross Ref
- Hubert Comon, Max Dauchet, Rémi Gilleron, Florent Jacquemard, Denis Lugiez, Christof Löding, Sophie Tison, and Marc Tommasi. Tree automata techniques and applications, October 2007. URL http://www.grappa.univ- lille3.fr/tata .Google Scholar
- ECMA 2011. Standard ECMA-262: ECMAScript Language Specification. Ecma International, 5.1 edition, June 2011. URL http://www.ecma- international.org/publications/files/ECMA- ST/Ecma- 262.pdf .Google Scholar
- ISO/IEC 9899:TC3: Programming languages – C. ISO/IEC JTC1/SC22/WG14, September 2007. URL http://www.open- std.org/ JTC1/SC22/WG14/www/docs/n1124.pdf .Google Scholar
- Nils Klarlund, Niels Damgaard, and Michael I. Schwartzbach. Yakyak: parsing with logical side constraints. In Grzegorz Rozenberg and Wolfgang Thomas, editors, Developments in Language Theory, Foundations, Applications, and Perspectives, Aachen, Germany, 6-9 July 1999, pages 286–301. World Scientific, 1999. ISBN 981-02-4380-4.Google Scholar
- Paul Klint and Eelco Visser. Using filters for the disambiguation of context-free grammars. Technical Report P9426, University of Amsterdam, December 1994.Google Scholar
- Donald E. Knuth. On the translation of languages from left to right. Information and Control, 8(6):607–639, December 1965. ISSN 0019-9958. doi: 10.1016/S0019- 9958(65)90426- 2.Google Scholar
Cross Ref
- Bernard Lang. Deterministic techniques for efficient non-deterministic parsers, pages 255–269. Springer, Berlin, Heidelberg, 1974. ISBN 978-3-540-37778-8. doi: 10.1007/3- 540- 06841- 4_65.Google Scholar
- Mikkel Thorup. Controlled grammatic ambiguity. ACM Transactions on Programming Languages and Systems (TOPLAS), 16 (3):1024–1050, May 1994. ISSN 0164-0925. doi: 10.1145/177492.177759. Google Scholar
Digital Library
- Mikkel Thorup. Disambiguating grammars by exclusion of sub-parse trees. Acta Informatica, 33(5):511–522, August 1996. ISSN 0001-5903 (Print) 1432-0525 (Online). doi: 10.1007/BF03036460. Google Scholar
Digital Library
- Mark G. J. van den Brand, Jeroen Scheerder, Jurgen J. Vinju, and Eelco Visser. Disambiguation Filters for Scannerless Generalized LR Parsers, pages 143–158. Springer, Berlin, Heidelberg, 2002. ISBN 978-3-540-45937-8. doi: 10.1007/3-540-45937-5_12. Google Scholar
Cross Ref
- Eelco Visser. Syntax Definition for Language Prototyping. PhD thesis, University of Amsterdam, 1997.Google Scholar
- R. M. Wharton. Resolution of ambiguity in parsing. Acta Informatica, 6(4):387–395, December 1976. ISSN 0001-5903 (Print) 1432-0525 (Online). doi: 10.1007/BF00268139. Google Scholar
Digital Library
Index Terms
Restricting grammars with tree automata
Recommendations
Deterministic parsing of ambiguous grammars
Methods of describing the syntax of programming languages in ways that are more flexible and natural than conventional BNF descriptions are considered. These methods involve the use of ambiguous context-free grammars together with rules to resolve ...
Semantics and algorithms for data-dependent grammars
POPL '10: Proceedings of the 37th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languagesWe present the design and theory of a new parsing engine, YAKKER, capable of satisfying the many needs of modern programmers and modern data processing applications. In particular, our new parsing engine handles (1) full scannerless context-free ...
Semantics and algorithms for data-dependent grammars
POPL '10We present the design and theory of a new parsing engine, YAKKER, capable of satisfying the many needs of modern programmers and modern data processing applications. In particular, our new parsing engine handles (1) full scannerless context-free ...






Comments