Parse Forest Diagnostics with Dr. Ambiguity

  • Hendrikus J. S. Basten
  • Jurgen J. Vinju
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6940)


In this paper we propose and evaluate a method for locating causes of ambiguity in context-free grammars by automatic analysis of parse forests. A parse forest is the set of parse trees of an ambiguous sentence. Deducing causes of ambiguity from observing parse forests is hard for grammar engineers because of (a) the size of the parse forests, (b) the complex shape of parse forests, and (c) the diversity of causes of ambiguity.

We first analyze the diversity of ambiguities in grammars for programming languages and the diversity of solutions to these ambiguities. Then we introduce Dr. Ambiguity: a parse forest diagnostics tools that explains the causes of ambiguity by analyzing differences between parse trees and proposes solutions. We demonstrate its effectiveness using a small experiment with a grammar for Java 5.


Production Rule Parse Tree Difference Class Derivation Step Ambiguous Sentence 
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.
    Aho, A., Sethi, R., Ullman, J.: Compilers. Principles, Techniques and Tools. Addison-Wesley (1986)Google Scholar
  2. 2.
    Altman, T., Logothetis, G.: A note on ambiguity in context-free grammars. Inf. Process. Lett. 35(3), 111–114 (1990)MathSciNetzbMATHCrossRefGoogle Scholar
  3. 3.
    Aycock, J., Horspool, R.N.: Faster Generalized LR Parsing. In: Jähnichen, S. (ed.) CC 1999. LNCS, vol. 1575, pp. 32–46. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  4. 4.
    Basten, H.J.S.: Tracking Down the Origins of Ambiguity in Context-Free Grammars. In: Cavalcanti, A., Deharbe, D., Gaudel, M.-C., Woodcock, J. (eds.) ICTAC 2010. LNCS, vol. 6255, pp. 76–90. Springer, Heidelberg (2010)CrossRefGoogle Scholar
  5. 5.
    Basten, H.J.S., Vinju, J.J.: Faster ambiguity detection by grammar filtering. In: Brabrand, C., Moreau, P.E. (eds.) Proceedings of the Tenth Workshop on Language Descriptions, Tools and Applications (LDTA 2010), pp. 5:1–5:9. ACM (2010)Google Scholar
  6. 6.
    Begel, A., Graham, S.L.: XGLR–an algorithm for ambiguity in programming languages. Science of Computer Programming 61(3), 211–227 (2006); Special Issue on The Fourth Workshop on Language Descriptions, Tools, and Applications (LDTA 2004)Google Scholar
  7. 7.
    Bouwers, E., Bravenboer, M., Visser, E.: Grammar engineering support for precedence rule recovery and compatibility checking. ENTCS 203(2), 85–101 (2008); Proceedings of the Seventh Workshop on Language Descriptions, Tools, and Applications (LDTA 2007)Google Scholar
  8. 8.
    Brabrand, C., Giegerich, R., Møller, A.: Analyzing ambiguity of context-free grammars. Sci. Comput. Program. 75(3), 176–191 (2010)zbMATHCrossRefGoogle Scholar
  9. 9.
    van den Brand, M., Scheerder, J., Vinju, J.J., Visser, E.: Disambiguation Filters for Scannerless Generalized LR Parsers. In: Horspool, R.N. (ed.) CC 2002. LNCS, vol. 2304, pp. 143–158. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  10. 10.
    Bravenboer, M., Tanter, E., Visser, E.: Declarative, formal, and extensible syntax definition for AspectJ. SIGPLAN Not. 41, 209–228 (2006)CrossRefGoogle Scholar
  11. 11.
    Bravenboer, M., Vermaas, R., de Groot, R., Dolstra, E.: Java-front: Java syntax definition, parser, and pretty-printer. Tech. rep., (2011),
  12. 12.
    Bravenboer, M., Vermaas, R., Vinju, J.J., Visser, E.: Generalized Type-Based Disambiguation of Meta Programs with Concrete Object Syntax. In: Glück, R., Lowry, M.R. (eds.) GPCE 2005. LNCS, vol. 3676, pp. 157–172. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  13. 13.
    Cantor, D.G.: On the ambiguity problem of Backus systems. Journal of the ACM 9(4), 477–479 (1962)MathSciNetzbMATHCrossRefGoogle Scholar
  14. 14.
    Charles, P., Fuhrer, R.M., Sutton Jr., S.M., Duesterwald, E., Vinju, J.: Accelerating the creation of customized, language-specific IDEs in eclipse. In: Arora, S., Leavens, G.T. (eds.) Proceedings of the 24th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2009 (2009)Google Scholar
  15. 15.
    Chomsky, N., Schützenberger, M.: The algebraic theory of context-free languages. In: Braffort, P. (ed.) Computer Programming and Formal Systems, pp. 118–161. North-Holland, Amsterdam (1963)CrossRefGoogle Scholar
  16. 16.
    Earley, J.: An efficient context-free parsing algorithm. Commun. ACM 13, 94–102 (1970)zbMATHCrossRefGoogle Scholar
  17. 17.
    Economopoulos, G.R.: Generalised LR parsing algorithms. Ph.D. thesis, Royal Holloway, University of London (August 2006)Google Scholar
  18. 18.
    Floyd, R.W.: On ambiguity in phrase structure languages. Communications of the ACM 5(10), 526–534 (1962)CrossRefGoogle Scholar
  19. 19.
    Ford, B.: Parsing expression grammars: a recognition-based syntactic foundation. SIGPLAN Not. 39, 111–122 (2004)CrossRefGoogle Scholar
  20. 20.
    Ginsburg, S., Harrison, M.A.: Bracketed context-free languages. Journal of Computer and System Sciences 1(1), 1–23 (1967)MathSciNetzbMATHCrossRefGoogle Scholar
  21. 21.
    Heering, J., Hendriks, P.R.H., Klint, P., Rekers, J.: The syntax definition formalism SDF - reference manual. SIGPLAN Notices 24(11), 43–75 (1989)CrossRefGoogle Scholar
  22. 22.
    Johnstone, A., Scott, E.: Modelling GLL Parser Implementations. In: Malloy, B., Staab, S., van den Brand, M. (eds.) SLE 2010. LNCS, vol. 6563, pp. 42–61. Springer, Heidelberg (2011)CrossRefGoogle Scholar
  23. 23.
    Klint, P., van der Storm, T., Vinju, J.: EASY Meta-Programming with Rascal. In: Fernandes, J.M., Lämmel, R., Visser, J., Saraiva, J. (eds.) Generative and Transformational Techniques in Software Engineering III. LNCS, vol. 6491, pp. 222–289. Springer, Heidelberg (2011)CrossRefGoogle Scholar
  24. 24.
    Klint, P., Visser, E.: Using filters for the disambiguation of context-free grammars. In: Pighizzini, G., San Pietro, P. (eds.) Proc. ASMICS Workshop on Parsing Theory, pp. 1–20. Tech. Rep. 126–1994, Dipartimento di Scienze dell’Informazione, Università di Milano, Milano, Italy (1994)Google Scholar
  25. 25.
    Lämmel, R., Verhoef, C.: Semi-automatic grammar recovery. Softw. Pract. Exper. 31, 1395–1448 (2001)zbMATHCrossRefGoogle Scholar
  26. 26.
    Landin, P.J.: The next 700 programming languages. Commun. ACM 9, 157–166 (1966)zbMATHCrossRefGoogle Scholar
  27. 27.
    Moonen, L.: Generating robust parsers using island grammars. In: Proceedings of the Eighth Working Conference on Reverse Engineering (WCRE 2001), p. 13. IEEE Computer Society, Washington, DC (2001)CrossRefGoogle Scholar
  28. 28.
    Parr, T., Fisher, K.: LL(*): the foundation of the ANTLR parser generator. In: Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2011, pp. 425–436. ACM, New York (2011)Google Scholar
  29. 29.
    Rekers, J.: Parser Generation for Interactive Environments. Ph.D. thesis, University of Amsterdam (1992)Google Scholar
  30. 30.
    Salomon, D.J., Cormack, G.V.: Scannerless NSLR(1) parsing of programming languages. In: Proceedings of the ACM SIGPLAN 1989 Conference on Programming Language Design and Implementation, PLDI 1989, pp. 170–178. ACM (1989)Google Scholar
  31. 31.
    Schröer, F.W.: AMBER, an ambiguity checker for context-free grammars. Tech. rep., (2001),
  32. 32.
    Schröer, F.W.: ACCENT, a compiler compiler for the entire class of context-free grammars, 2nd edn. Tech. rep., (2006),
  33. 33.
    Scott, E.: SPPF-style parsing from earley recognisers. ENTCS 203, 53–67 (2008)Google Scholar
  34. 34.
    Scott, E., Johnstone, A.: GLL parsing. ENTCS 253(7), 177–189 (2010); Proceedings of the Ninth Workshop on Language Descriptions Tools and Applications (LDTA 2009)Google Scholar
  35. 35.
    Tomita, M.: Efficient Parsing for Natural Languages. A Fast Algorithm for Practical Systems. Kluwer Academic Publishers (1985)Google Scholar
  36. 36.
    Vinju, J.J.: SDF disambiguation medkit for programming languages. Tech. Rep. SEN-1107, Centrum Wiskunde & Informatica (2011),
  37. 37.
    Visser, E.: Syntax Definition for Language Prototyping. Ph.D. thesis, Universiteit van Amsterdam (1997)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Hendrikus J. S. Basten
    • 1
  • Jurgen J. Vinju
    • 1
  1. 1.Centrum Wiskunde & Informatica (CWI)AmsterdamThe Netherlands

Personalised recommendations