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.
- Tadashi Ae. Direct or cascade product of pushdown automata. Journal of Computer and System Sciences, 14(2):257–263, 1977.Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- CVE. CVE-2013-0269. Common Vulnerabilities and Exposures, February 2013. Retrieved November 13, 2014.Google Scholar
- CVE. CVE-2013-4547. Common Vulnerabilities and Exposures, November 2013. Retrieved November 13, 2014.Google Scholar
- 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 Scholar
Digital Library
- J. des Rivières and J. Wiegand. Eclipse: A platform for integrating development tools. IBM Systems Journal, 43(2):371–383, 2004. Google Scholar
Digital Library
- John Hopcroft and Jeffrey Ullman. Introduction to Automata Theory, Languages and Computation. Addison-Wesley, Reading, MA, 1979. ISBN 978-0-201-02988-8. Google Scholar
Digital Library
- Scott E. Hudson, Frank Flannery, C. Scott Ananian, Dan Wang, and Andrew Appel. CUP LALR parser generator for Java, 1996.Google Scholar
- Software release. At http://www.cs.princeton.edu/˜appel/ modern/java/CUP/.Google Scholar
- Stephen C. Johnson. Yacc: Yet another compiler-compiler. Computing Science Technical Report 32, AT&T Bell Laboratories, Murray Hill, NJ, July 1975.Google Scholar
- Richard E. Korf. Depth-first iterative-deepening: an optimal admissible tree search. Artificial Intelligence, 27(1):97–109, September 1985. Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Hari Mohan Pandey. Advances in ambiguity detection methods for formal grammars. Procedia Engineering, 24(0):700–707, 2011.Google Scholar
Cross Ref
- International Conference on Advances in Engineering 2011.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Friedrich Wilhelm Schröer. AMBER, an ambiguity checker for contextfree grammars. Technical report, Fraunhofer Institute for Computer Architecture and Software Technology, 2001.Google Scholar
- Masaru Tomita, editor. Generalized LR Parsing. Springer US, 1991. ISBN 978-1-4613-6804-5. Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Index Terms
Finding counterexamples from parsing conflicts
Recommendations
Finding counterexamples from parsing conflicts
PLDI '15: Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and ImplementationWriting 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 ...
A fast general parser for automatic code generation
MTPP'10: Proceedings of the Second Russia-Taiwan conference on Methods and tools of parallel programming multicomputersThe code generator in a compiler attempts to match a subject tree against a collection of tree-shaped patterns for generating instructions. Tree-pattern matching may be considered as a generalization of string parsing. We propose a new generalized LR (...
LLLR parsing
SAC '13: Proceedings of the 28th Annual ACM Symposium on Applied ComputingThe idea of an LLLR parsing is presented. An LLLR(k) parser can be constructed for any LR(k) grammar but it produces the left parse of the input string in linear time (in respect to the length of the derivation) without backtracking. If used as a basis ...






Comments