skip to main content
research-article
Open Access

Restricting grammars with tree automata

Published:12 October 2017Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarCross RefCross Ref
  2. 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 ScholarGoogle Scholar
  3. 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 ScholarGoogle Scholar
  4. 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 ScholarGoogle Scholar
  5. 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 ScholarGoogle Scholar
  6. Paul Klint and Eelco Visser. Using filters for the disambiguation of context-free grammars. Technical Report P9426, University of Amsterdam, December 1994.Google ScholarGoogle Scholar
  7. 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 ScholarGoogle ScholarCross RefCross Ref
  8. 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 ScholarGoogle Scholar
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarCross RefCross Ref
  12. Eelco Visser. Syntax Definition for Language Prototyping. PhD thesis, University of Amsterdam, 1997.Google ScholarGoogle Scholar
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Restricting grammars with tree automata

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Published in

              cover image Proceedings of the ACM on Programming Languages
              Proceedings of the ACM on Programming Languages  Volume 1, Issue OOPSLA
              October 2017
              1786 pages
              EISSN:2475-1421
              DOI:10.1145/3152284
              Issue’s Table of Contents

              Copyright © 2017 Owner/Author

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 12 October 2017
              Published in pacmpl Volume 1, Issue OOPSLA

              Permissions

              Request permissions about this article.

              Request Permissions

              Check for updates

              Qualifiers

              • research-article

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader
            About Cookies On This Site

            We use cookies to ensure that we give you the best experience on our website.

            Learn more

            Got it!