skip to main content
research-article

Finding counterexamples from parsing conflicts

Published:03 June 2015Publication History
Skip Abstract Section

Abstract

Writing a parser remains remarkably painful. Automatic parser generators offer a powerful and systematic way to parse complex grammars, but debugging conflicts in grammars can be time-consuming even for experienced language designers. Better tools for diagnosing parsing conflicts will alleviate this difficulty. This paper proposes a practical algorithm that generates compact, helpful counterexamples for LALR grammars. For each parsing conflict in a grammar, a counterexample demonstrating the conflict is constructed. When the grammar in question is ambiguous, the algorithm usually generates a compact counterexample illustrating the ambiguity. This algorithm has been implemented as an extension to the CUP parser generator. The results from applying this implementation to a diverse collection of faulty grammars show that the algorithm is practical, effective, and suitable for inclusion in other LALR parser generators.

References

  1. Tadashi Ae. Direct or cascade product of pushdown automata. Journal of Computer and System Sciences, 14(2):257–263, 1977.Google ScholarGoogle ScholarCross RefCross Ref
  2. Roland Axelsson, Keijo Heljanko, and Martin Lange. Analyzing context-free grammars using an incremental SAT solver. In Automata, Languages and Programming, volume 5126 of Lecture Notes in Computer Science, pp. 410–422. Springer Berlin Heidelberg, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. H. J. S. Basten. Tracking down the origins of ambiguity in context-free grammars. In Theoretical Aspects of Computing – ICTAC 2010, volume 6255 of Lecture Notes in Computer Science, pp. 76–90. Springer Berlin Heidelberg, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. H. J. S. Basten and T. van der Storm. AmbiDexter: Practical ambiguity detection. In Proc. 10th IEEE Int’l Workshop on Source Code Analysis and Manipulation (SCAM 2010), pp. 101–102, Sept 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. H. J. S. Basten and J. J. Vinju. Faster ambiguity detection by grammar filtering. In Proc. 10th Workshop on Language Descriptions, Tools and Applications, pp. 5:1–5:9, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Hendrikus J. S. Basten and Jurgen J. Vinju. Parse forest diagnostics with Dr. Ambiguity. In Software Language Engineering, volume 6940 of Lecture Notes in Computer Science, pp. 283–302. Springer Berlin Heidelberg, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Ira Baxter. What is the easiest way of telling whether a BNF grammar is ambiguous or not? (answer). StackOverflow, July 2011. Retrieved November 11, 2014.Google ScholarGoogle Scholar
  8. Ira D. Baxter, Christopher Pidgeon, and Michael Mehlich. DMS ® : Program transformations for practical scalable software evolution. In Proc. 26th Int’l Conf. on Software Engineering (ICSE), pp. 625–634, May 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. CVE. CVE-2013-0269. Common Vulnerabilities and Exposures, February 2013. Retrieved November 13, 2014.Google ScholarGoogle Scholar
  10. CVE. CVE-2013-4547. Common Vulnerabilities and Exposures, November 2013. Retrieved November 13, 2014.Google ScholarGoogle Scholar
  11. Frank DeRemer and Thomas Pennello. Efficient computation of LALR(1) look-ahead sets. ACM Trans. on Programming Languages and Systems, 4(4):615–649, October 1982. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. J. des Rivières and J. Wiegand. Eclipse: A platform for integrating development tools. IBM Systems Journal, 43(2):371–383, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. John Hopcroft and Jeffrey Ullman. Introduction to Automata Theory, Languages and Computation. Addison-Wesley, Reading, MA, 1979. ISBN 978-0-201-02988-8. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Scott E. Hudson, Frank Flannery, C. Scott Ananian, Dan Wang, and Andrew Appel. CUP LALR parser generator for Java, 1996.Google ScholarGoogle Scholar
  15. Software release. At http://www.cs.princeton.edu/˜appel/ modern/java/CUP/.Google ScholarGoogle Scholar
  16. Stephen C. Johnson. Yacc: Yet another compiler-compiler. Computing Science Technical Report 32, AT&T Bell Laboratories, Murray Hill, NJ, July 1975.Google ScholarGoogle Scholar
  17. Richard E. Korf. Depth-first iterative-deepening: an optimal admissible tree search. Artificial Intelligence, 27(1):97–109, September 1985. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Scott McPeak and George C. Necula. Elkhound: A fast, practical GLR parser generator. In Proc. 13th Int’l Conf. on Compiler Construction (CC’04), pp. 73–88, 2004.Google ScholarGoogle ScholarCross RefCross Ref
  19. Nathaniel Nystrom, Michael R. Clarkson, and Andrew C. Myers. Polyglot: An extensible compiler framework for Java. In Proc. 12th Int’l Conf. on Compiler Construction (CC’03), pp. 138–152, April 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Hari Mohan Pandey. Advances in ambiguity detection methods for formal grammars. Procedia Engineering, 24(0):700–707, 2011.Google ScholarGoogle ScholarCross RefCross Ref
  21. International Conference on Advances in Engineering 2011.Google ScholarGoogle Scholar
  22. Terence Parr and Kathleen Fisher. LL(*): The foundation of the ANTLR parser generator. In Proc. 32nd ACM SIGPLAN Conf. on Programming Language Design and Implementation (PLDI), pp. 425–436, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Terence Parr, Sam Harwell, and Kathleen Fisher. Adaptive LL(*) parsing: The power of dynamic analysis. In Proc. 2014 ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages, and Applications, pp. 579–598, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Leonardo Teixeira Passos, Mariza A. S. Bigonha, and Roberto S. Bigonha. A methodology for removing LALR(k) conflicts. Journal of Universal Computer Science, 13(6):737–752, June 2007.Google ScholarGoogle Scholar
  25. Leonardo Teixeira Passos, Mariza A. S. Bigonha, and Roberto S. Bigonha. An LALR parser generator supporting conflict resolution. Journal of Universal Computer Science, 14(21):3447–3464, December 2008.Google ScholarGoogle Scholar
  26. C. Rodriguez-Leon and L. Garcia-Forte. Solving difficult LR parsing conflicts by postponing them. Comput. Sci. Inf. Syst., 8(2):517–531, 2011.Google ScholarGoogle ScholarCross RefCross Ref
  27. Sylvain Schmitz. Conservative ambiguity detection in context-free grammars. In Automata, Languages and Programming, volume 4596 of Lecture Notes in Computer Science, pp. 692–703. Springer Berlin Heidelberg, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Sylvain Schmitz. An experimental ambiguity detection tool. Science of Computer Programming, 75(1–2):71–84, 2010. Special Issue on ETAPS 2006 and 2007 Workshops on Language Descriptions, Tools, and Applications (LDTA ’06 and ’07). Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Friedrich Wilhelm Schröer. AMBER, an ambiguity checker for contextfree grammars. Technical report, Fraunhofer Institute for Computer Architecture and Software Technology, 2001.Google ScholarGoogle Scholar
  30. Masaru Tomita, editor. Generalized LR Parsing. Springer US, 1991. ISBN 978-1-4613-6804-5. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Naveneetha Vasudevan and Laurence Tratt. Detecting ambiguity in programming language grammars. In Proc. 6th Int’l Conf. on Software Language Engineering, pp. 157–176, October 2013.Google ScholarGoogle ScholarCross RefCross Ref
  32. Andreas Wenger and Michael Petter. CUP2 LR parser generator for Java, 2014. Software beta release. At http://www2.in.tum.de/ cup2. 564 Introduction Background Parser State Machine Shift/Reduce Conflicts Reduce/Reduce Conflicts Precedence Counterexamples A Challenging Conflict Properties of Good Counterexamples Constructing Nonunifying Counterexamples Constructing Unifying Counterexamples Product Parser Outward Search from the Conflict State Successor Configurations Completing the Search Implementation Evaluation Grammar Examples Effectiveness Efficiency Scalability Related Work ConclusionGoogle ScholarGoogle Scholar

Index Terms

  1. Finding counterexamples from parsing conflicts

      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

      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!