Detecting Ambiguity in Programming Language Grammars

  • Naveneetha Vasudevan
  • Laurence Tratt
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8225)


Ambiguous Context Free Grammars (CFGs) are problematic for programming languages, as they allow inputs to be parsed in more than one way. In this paper, we introduce a simple non-deterministic search-based approach to ambiguity detection which non-exhaustively explores a grammar in breadth for ambiguity. We also introduce two new techniques for generating random grammars – Boltzmann sampling and grammar mutation – allowing us to test ambiguity detection tools on much larger corpuses than previously possible. Our experiments show that our breadth-based approach to ambiguity detection performs as well as, and generally better, than extant tools.


Main Experiment Mini Experiment Search Base Software Engineering Ambiguous Subset Uniform Random Generation 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Cantor, D.G.: On the ambiguity problem of backus systems. Journal of the ACM 9(4), 477–479 (1962)MathSciNetCrossRefzbMATHGoogle Scholar
  2. 2.
    Tratt, L.: Parsing: The solved problem that isn’t. Hacker Monthly, 37–42 (June 2011)Google Scholar
  3. 3.
    Schröer, F.W.: Amber, an ambiguity checker for context-free grammars. Technical report (2001),
  4. 4.
    Brabrand, C., Giegerich, R., Møller, A.: Analyzing ambiguity of context-free grammars. Science of Computer Programming 75(3), 176–191 (2010)MathSciNetCrossRefzbMATHGoogle Scholar
  5. 5.
    Basten, H.J.S., Vinju, J.J.: Faster ambiguity detection by grammar filtering. In: Proc. LDTA, pp. 5:1–5:9 (2010)Google Scholar
  6. 6.
    Axelsson, R., Heljanko, K., Lange, M.: Analyzing context-free grammars using an incremental SAT solver. In: Aceto, L., Damgård, I., Goldberg, L.A., Halldórsson, M.M., Ingólfsdóttir, A., Walukiewicz, I. (eds.) ICALP 2008, Part II. LNCS, vol. 5126, pp. 410–422. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  7. 7.
    Cheung, B.S.N., Uzgalis, R.C.: Ambiguity in context-free grammars. In: Proc. SAC, pp. 272–276. ACM (1995)Google Scholar
  8. 8.
    Basten, H.J.S.: Ambiguity detection methods for context-free grammars. Master’s thesis, Universiteit van Amsterdam (August 2007)Google Scholar
  9. 9.
    Vasudevan, N., Tratt, L.: Search-based ambiguity detection in context-free grammars. In: Proc. ICCSW, pp. 142–148 (September 2012)Google Scholar
  10. 10.
    Harman, M.: The current state and future of search based software engineering. In: FOSE, pp. 342–357 (2007)Google Scholar
  11. 11.
    Schröer, F.W.: Accent, a compiler compiler for the entire class of context-free grammars. Technical report (2000),
  12. 12.
    Canou, B., Darrasse, A.: Fast and sound random generation for automated testing and benchmarking in objective caml. In: Proc. Workshop on ML, pp. 61–70 (2009)Google Scholar
  13. 13.
    Mougenot, A., Darrasse, A., Blanc, X., Soria, M.: Uniform random generation of huge metamodel instances. In: Paige, R.F., Hartman, A., Rensink, A. (eds.) ECMDA-FA 2009. LNCS, vol. 5562, pp. 130–145. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  14. 14.
    Basten, H.J.S., van der Storm, T.: Ambidexter: Practical ambiguity detection. In: Proc. SCAM 2010, pp. 101–102 (2010)Google Scholar
  15. 15.
    Tomita, M.: An efficient context-free parsing algorithm for natural languages. In: Proc. IJCAI, pp. 756–764 (1985)Google Scholar

Copyright information

© Springer International Publishing Switzerland 2013

Authors and Affiliations

  • Naveneetha Vasudevan
    • 1
  • Laurence Tratt
    • 1
  1. 1.Software Development TeamKing’s College LondonUK

Personalised recommendations