skip to main content

Statically Resolvable Ambiguity

Published:11 January 2023Publication History
Skip Abstract Section

Abstract

Traditionally, a grammar defining the syntax of a programming language is typically both context free and unambiguous. However, recent work suggests that an attractive alternative is to use ambiguous grammars,thus postponing the task of resolving the ambiguity to the end user. If all programs accepted by an ambiguous grammar can be rewritten unambiguously, then the parser for the grammar is said to be resolvably ambiguous. Guaranteeing resolvable ambiguity statically---for all programs---is hard, where previous work only solves it partially using techniques based on property-based testing. In this paper, we present the first efficient, practical, and proven correct solution to the statically resolvable ambiguity problem. Our approach introduces several key ideas, including splittable productions, operator sequences, and the concept of a grouper that works in tandem with a standard parser. We prove static resolvability using a Coq mechanization and demonstrate its efficiency and practical applicability by implementing and integrating resolvable ambiguity into an essential part of the standard OCaml parser.

References

  1. Annika Aasa. 1995. Precedences in Specifications and Implementations of Programming Languages. Theoretical Computer Science, 142, 1 (1995), May, 3–26. issn:0304-3975 https://doi.org/10.1016/0304-3975(95)90680-J Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Ali Afroozeh and Anastasia Izmaylova. 2015. One Parser to Rule Them All. In 2015 ACM International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software (Onward!) (Onward! 2015). Association for Computing Machinery, New York, NY, USA. 151–170. isbn:978-1-4503-3688-8 https://doi.org/10.1145/2814228.2814242 Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Ali Afroozeh, Mark van den Brand, Adrian Johnstone, Elizabeth Scott, and Jurgen Vinju. 2013. Safe Specification of Operator Precedence Rules. In Software Language Engineering, Martin Erwig, Richard F. Paige, and Eric Van Wyk (Eds.) (Lecture Notes in Computer Science). Springer International Publishing, 137–156. isbn:978-3-319-02654-1 https://doi.org/10.1007/978-3-319-02654-1_8 Google ScholarGoogle ScholarCross RefCross Ref
  4. Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman. 2006. Compilers: Principles, Techniques, and Tools (second ed.). Addison Wesley, Boston. isbn:978-0-321-48681-3 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Roland Axelsson, Keijo Heljanko, and Martin Lange. 2008. Analyzing Context-Free Grammars Using an Incremental SAT Solver. In Automata, Languages and Programming, Luca Aceto, Ivan Damgård, Leslie Ann Goldberg, Magnús M. Halldórsson, Anna Ingólfsdóttir, and Igor Walukiewicz (Eds.) (Lecture Notes in Computer Science). Springer Berlin Heidelberg, 410–422. isbn:978-3-540-70583-3 https://doi.org/10.1007/978-3-540-70583-3_34 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Bas Basten. 2011. Ambiguity Detection for Programming Language Grammars. Ph. D. Dissertation. Universiteit van Amsterdam. Google ScholarGoogle Scholar
  7. Claus Brabrand, Robert Giegerich, and Anders Møller. 2007. Analyzing Ambiguity of Context-Free Grammars. In Implementation and Application of Automata, Jan Holub and Jan Žďárek (Eds.) (Lecture Notes in Computer Science). Springer Berlin Heidelberg, 214–225. isbn:978-3-540-76336-9 https://doi.org/10.1007/978-3-540-76336-9_21 Google ScholarGoogle ScholarCross RefCross Ref
  8. David Broman. 2019. A Vision of Miking: Interactive Programmatic Modeling, Sound Language Composition, and Self-Learning Compilation. In Proceedings of the 12th ACM SIGPLAN International Conference on Software Language Engineering (SLE 2019). Association for Computing Machinery, New York, NY, USA. 55–60. isbn:978-1-4503-6981-7 https://doi.org/10.1145/3357766.3359531 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. David G. Cantor. 1962. On The Ambiguity Problem of Backus Systems. J. ACM, 9, 4 (1962), Oct., 477–479. issn:0004-5411 https://doi.org/10.1145/321138.321145 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Arthur Charguéraud. 2022. The TLC Coq Library. Google ScholarGoogle Scholar
  11. Keith Cooper and Linda Torczon. 2011. Engineering a Compiler (second ed.). Elsevier. isbn:978-0-08-091661-3 Google ScholarGoogle Scholar
  12. Nils Anders Danielsson and Ulf Norell. 2011. Parsing Mixfix Operators. In Implementation and Application of Functional Languages, Sven-Bodo Scholz and Olaf Chitil (Eds.) (Lecture Notes in Computer Science). Springer Berlin Heidelberg, 80–99. isbn:978-3-642-24452-0 https://doi.org/10.1007/978-3-642-24452-0_5 Google ScholarGoogle ScholarCross RefCross Ref
  13. Luís Eduardo de Souza Amorim and Eelco Visser. 2020. Multi-Purpose Syntax Definition with SDF3. In Software Engineering and Formal Methods, Frank de Boer and Antonio Cerone (Eds.) (Lecture Notes in Computer Science). Springer International Publishing, Cham. 1–23. isbn:978-3-030-58768-0 https://doi.org/10.1007/978-3-030-58768-0_1 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Jay Earley. 1970. An Efficient Context-free Parsing Algorithm. Commun. ACM, 13, 2 (1970), Feb., 94–102. issn:0001-0782 https://doi.org/10.1145/362007.362035 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Sebastian Erdweg, Tillmann Rendel, Christian Kästner, and Klaus Ostermann. 2011. SugarJ: Library-Based Syntactic Language Extensibility. In Proceedings of the 2011 ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA ’11). Association for Computing Machinery, New York, NY, USA. 391–406. isbn:978-1-4503-0940-0 https://doi.org/10.1145/2048066.2048099 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Robert W. Floyd. 1963. Syntactic Analysis and Operator Precedence. J. ACM, 10, 3 (1963), July, 316–333. issn:0004-5411 https://doi.org/10.1145/321172.321179 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Bryan Ford. 2004. Parsing Expression Grammars: A Recognition-based Syntactic Foundation. In Proceedings of the 31st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’04). ACM, New York, NY, USA. 111–122. isbn:978-1-58113-729-3 https://doi.org/10.1145/964001.964011 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Seymour Ginsburg and Joseph Ullian. 1966. Ambiguity in Context Free Languages. J. ACM, 13, 1 (1966), Jan., 62–89. issn:0004-5411 https://doi.org/10.1145/321312.321318 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Bernard Lang. 1974. Deterministic Techniques for Efficient Non-Deterministic Parsers. In Automata, Languages and Programming, Jacques Loeckx (Ed.) (Lecture Notes in Computer Science). Springer, Berlin, Heidelberg. 255–269. isbn:978-3-662-21545-6 https://doi.org/10.1007/978-3-662-21545-6_18 Google ScholarGoogle ScholarCross RefCross Ref
  20. Stefan Monnier. 2020. SMIE: Weakness Is Power!. The Art, Science, and Engineering of Programming, 5, 1 (2020), June, 1:1–1:26. issn:2473-7321 https://doi.org/10.22152/programming-journal.org/2021/5/1 Google ScholarGoogle ScholarCross RefCross Ref
  21. Viktor Palmkvist and David Broman. 2019. Creating Domain-Specific Languages by Composing Syntactical Constructs. In Practical Aspects of Declarative Languages, José Júlio Alferes and Moa Johansson (Eds.) (Lecture Notes in Computer Science). Springer International Publishing, 187–203. isbn:978-3-030-05998-9 https://doi.org/10.1007/978-3-030-05998-9_12 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Viktor Palmkvist, Elias Castegren, Philipp Haller, and David Broman. 2021. Resolvable Ambiguity: Principled Resolution of Syntactically Ambiguous Programs. In Proceedings of the 30th ACM SIGPLAN International Conference on Compiler Construction (CC 2021). Association for Computing Machinery, New York, NY, USA. 153–164. isbn:978-1-4503-8325-7 https://doi.org/10.1145/3446804.3446846 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Terence Parr and Kathleen Fisher. 2011. LL(*): The Foundation of the ANTLR Parser Generator. In Proceedings of the 32Nd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’11). ACM, New York, NY, USA. 425–436. isbn:978-1-4503-0663-8 https://doi.org/10.1145/1993498.1993548 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Terence Parr, Sam Harwell, and Kathleen Fisher. 2014. Adaptive LL(*) Parsing: The Power of Dynamic Analysis. In Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications (OOPSLA ’14). ACM, New York, NY, USA. 579–598. isbn:978-1-4503-2585-1 https://doi.org/10.1145/2660193.2660202 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. François Pottier and Yann Régis-Gianas. 2005. The Menhir Parser Generator. Google ScholarGoogle Scholar
  26. Sylvain Schmitz. 2007. Conservative Ambiguity Detection in Context-Free Grammars. In Automata, Languages and Programming, Lars Arge, Christian Cachin, Tomasz Jurdziński, and Andrzej Tarlecki (Eds.) (Lecture Notes in Computer Science). Springer Berlin Heidelberg, 692–703. isbn:978-3-540-73420-8 https://doi.org/10.1007/978-3-540-73420-8_60 Google ScholarGoogle ScholarCross RefCross Ref
  27. Elizabeth Scott and Adrian Johnstone. 2010. GLL Parsing. Electronic Notes in Theoretical Computer Science, 253, 7 (2010), Sept., 177–189. issn:1571-0661 https://doi.org/10.1016/j.entcs.2010.08.041 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Thomas A. Sudkamp. 1997. Languages and Machines: An Introduction to the Theory of Computer Science. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA. isbn:978-0-201-82136-9 Google ScholarGoogle Scholar
  29. The dafny-lang community. 2022. Dafny Documentation. https://dafny-lang.github.io/dafny/DafnyRef/DafnyRef.html Google ScholarGoogle Scholar
  30. Adam Brooks Webber. 2003. Modern Programming Languages: A Practical Introduction. Franklin, Beedle & Associates. isbn:978-1-887902-76-2 Google ScholarGoogle Scholar

Index Terms

  1. Statically Resolvable Ambiguity

      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

      • Article Metrics

        • Downloads (Last 12 months)247
        • Downloads (Last 6 weeks)28

        Other Metrics

      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!