Natural and Flexible Error Recovery for Generated Parsers

  • Maartje de Jonge
  • Emma Nilsson-Nyman
  • Lennart C. L. Kats
  • Eelco Visser
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5969)

Abstract

Parser generators are an indispensable tool for rapid language development. However, they often fall short of the finesse of a hand-crafted parser, built with the language semantics in mind. One area where generated parsers have provided unsatisfactory results is that of error recovery. Good error recovery is both natural, giving recovery suggestions in line with the intention of the programmer; and flexible, allowing it to be adapted according to language insights and language changes. This paper describes a novel approach to error recovery, taking into account not only the context-free grammar, but also indentation usage. We base our approach on an extension of the SGLR parser that supports fine-grained error recovery rules and can be used to parse complex, composed languages. We take a divide-and-conquer approach to error recovery: using indentation, erroneous regions of code are identified. These regions constrain the search space for applying recovery rules, improving performance and ensuring recovery suggestions local to the error. As a last resort, erroneous regions can be discarded. Our approach also integrates bridge parsing to provide more accurate suggestions for indentation-sensitive language constructs such as scopes. We evaluate our approach by comparison with the JDT Java parser used in Eclipse.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    The permissive grammars project, http://strategoxt.org/Stratego/PermissiveGrammars
  2. 2.
    Aho, A., Peterson, T.G.: A minimum distance error-correcting parser for context-free languages. SIAM Journal on Computing 1, 305 (1972)MATHCrossRefMathSciNetGoogle Scholar
  3. 3.
    Bravenboer, M., Tanter, E., Visser, E.: Declarative, formal, and extensible syntax definition for AspectJ. A case for scannerless generalized-LR parsing. In: Cook, W.R. (ed.) OOPSLA 2006, pp. 209–228. ACM Press, New York (2006)CrossRefGoogle Scholar
  4. 4.
    Burke, M.G., Fisher, G.A.: A practical method for LR and LL syntactic error diagnosis and recovery. ACM Trans. Program. Lang. Syst. 9(2), 164–197 (1987)CrossRefGoogle Scholar
  5. 5.
    Charles, P.: A practical method for constructing efficient LALR(K) parsers with automatic error recovery. PhD thesis, New York University (1991)Google Scholar
  6. 6.
    Charles, P., Fuhrer, R.M., Sutton Jr., S.M.: IMP: a meta-tooling platform for creating language-specific IDEs in Eclipse. In: Stirewalt, R.E.K., Egyed, A., Fischer, B. (eds.) Automated Software Engineering (ASE 2007), pp. 485–488. ACM, New York (2007)Google Scholar
  7. 7.
    Degano, P., Priami, C.: Comparison of syntactic error handling in LR parsers. Software – Practice and Experience 25(6), 657–679 (1995)CrossRefGoogle Scholar
  8. 8.
    Efftinge, S., et al.: openArchitectureWare User Guide. Version 4.3 (2008), http://openarchitectureware.org/pub/documentation/
  9. 9.
    Ford, B.: Packrat parsing: Simple, powerful, lazy, linear time. In: International Conference on Functional Programming (ICFP 2002). SIGPLAN Notices, vol. 37, pp. 36–47. ACM, New York (2002)CrossRefGoogle Scholar
  10. 10.
    Graham, S.L., Haley, C.B., Joy, W.N.: Practical LR error recovery. In: SIGPLAN 1979: Symposium on Compiler Construction, pp. 168–175. ACM, New York (1979)CrossRefGoogle Scholar
  11. 11.
    Kalleberg, K.T., et al.: JSGLR, http://www.spoofax.org/
  12. 12.
    Kats, L.C.L., de Jonge, M., Nilsson-Nyman, E., Visser, E.: Providing rapid feedback in generated modular language environments. Adding error recovery to scannerless generalized-LR parsing. In: Leavens, G.T. (ed.) Proceedings of the 24th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2009). ACM SIGPLAN Notices, vol. 44, pp. 445–464. ACM Press, New York (2009)CrossRefGoogle Scholar
  13. 13.
    Kats, L.C.L., Kalleberg, K.T., Visser, E.: Domain-specific languages for composable editor plugins. In: Ekman, T., Vinju, J. (eds.) Language Descriptions, Tools, and Applications (LDTA 2009). ENTCS. Elsevier Science Publishers, Amsterdam (2009)Google Scholar
  14. 14.
    Krahn, H., Rumpe, B., Völkel, S.: MontiCore: Modular development of textual domain specific languages. In: Paige, R., Meyer, B. (eds.) TOOLS EUROPE 2008. LNBIP, vol. 11, pp. 297–315. Springer, Heidelberg (2008)Google Scholar
  15. 15.
    Kuhn, T., Thomann, O.: Eclipse corner: Abstract syntax tree (2006), http://eclipse.org/articles/article.php?file=Article-JavaCodeManipulationAST/index.html
  16. 16.
    Lévy, J.-P.: Automatic Correction of Syntax Errors in Programming Languages. PhD thesis, Ithaca, NY, USA (1971)Google Scholar
  17. 17.
    Lyon, G.: Syntax-directed least-errors analysis for context-free languages: a practical approach. Commun. ACM 17(1), 3–14 (1974)MATHCrossRefGoogle Scholar
  18. 18.
    Mauney, J., Fischer, C.: Determining the extent of lookahead in syntactic error repair. ACM Trans. Program. Lang. Syst. (TOPLAS) 10(3), 456–469 (1988)CrossRefGoogle Scholar
  19. 19.
    Moonen, L.: Generating robust parsers using island grammars. In: Working Conference on Reverse Engineering (WCRE 2001), pp. 13–22. IEEE, Los Alamitos (2001)Google Scholar
  20. 20.
    Nilsson-Nyman, E., Ekman, T., Hedin, G.: Practical scope recovery using bridge parsing. In: Gašević, D., Lämmel, R., Van Wyk, E. (eds.) SLE 2008. LNCS, vol. 5452, pp. 95–113. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  21. 21.
    Pai, A., Kieburtz, R.: Global Context Recovery: A New Strategy for Syntactic Error Recovery by Table-Drive Parsers. ACM Trans. Program. Lang. Syst. (TOPLAS) 2(1), 18–41 (1980)MATHCrossRefGoogle Scholar
  22. 22.
    Pennello, T.J., DeRemer, F.: A forward move algorithm for LR error recovery. In: Principles of programming languages (POPL 1978), pp. 241–254. ACM, New York (1978)Google Scholar
  23. 23.
    Rekers, J., Koorn, W.: Substring parsing for arbitrary context-free grammars. SIGPLAN Not. 26(5), 59–66 (1991)CrossRefGoogle Scholar
  24. 24.
    Salomon, D., Cormack, G.: The disambiguation and scannerless parsing of complete character-level grammars for programming languages. Technical report, TR 95/06, Dept. of Comp. Sci., University of Manitoba, Winnipeg, Canada (1995)Google Scholar
  25. 25.
    Swierstra, S.D., Duponcheel, L.: Deterministic, error-correcting combinator parsers. In: Launchbury, J., Sheard, T., Meijer, E. (eds.) AFP 1996. LNCS, vol. 1129, pp. 184–207. Springer, Heidelberg (1996)Google Scholar
  26. 26.
    Valkering, R.: Syntax error handling in scannerless generalized LR parsers. Master’s thesis, University of Amsterdam (August 2007)Google Scholar
  27. 27.
    van den Brand, M.G.J., Bruntink, M., Economopoulos, G.R., de Jong, H.A., Klint, P., Kooiker, T., van der Storm, T., Vinju, J.J.: Using the Meta-Environment for maintenance and renovation. In: European Conference on Software Maintenance and Reengineering (CSMR 2007), pp. 331–332. IEEE, Los Alamitos (2007)CrossRefGoogle Scholar
  28. 28.
    van Deursen, A., Kuipers, T.: Building documentation generators. In: IEEE International Conference on Software Maintenance (ICSM 1999), p. 40. IEEE Computer Society, Los Alamitos (1999)CrossRefGoogle Scholar
  29. 29.
    Visser, E.: Syntax Definition for Language Prototyping. PhD thesis, University of Amsterdam (September 1997)Google Scholar
  30. 30.
    Visser, E.: Meta-programming with concrete object syntax. In: Batory, D., Consel, C., Taha, W. (eds.) GPCE 2002. LNCS, vol. 2487, pp. 299–315. Springer, Heidelberg (2002)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2010

Authors and Affiliations

  • Maartje de Jonge
    • 1
  • Emma Nilsson-Nyman
    • 2
  • Lennart C. L. Kats
    • 1
  • Eelco Visser
    • 1
  1. 1.Dept. of Software TechnologyDelft University of TechnologyThe Netherlands
  2. 2.Dept. of Computer ScienceLund UniversitySweden

Personalised recommendations