Exception Handling for Error Reporting in Parsing Expression Grammars
Parsing Expression Grammars (PEGs) are a new formalism to describe a top-down parser of a language. However, error handling techniques that are often applied to top-down parsers are not directly applicable to PEGs. This problem is usually solved in PEGs using a heuristic that helps to simulate the error reporting technique from top-down parsers, but the error messages are generic. We propose the introduction of labeled failures to PEGs for error reporting, as labels help to produce more meaningful error messages. The labeled failures approach is close to that of generating and handling exceptions often used in programming languages, being useful to annotate and label grammar pieces that should not fail. Moreover, our approach is an extension to the PEGs formalism that is expressive enough to implement some previous work on parser combinators. Finally, labeled failures are also useful to compose grammars preserving the error messages of each separate grammar.
Keywordsparsing error reporting parsing expression grammars packrat parsing parser combinators
Unable to display preview. Download preview PDF.
- 1.Aho, A.V., Lam, M.S., Sethi, R., Ullman, J.D.: Compilers: Principles, Techniques, and Tools, 2nd edn. Addison-Wesley Longman Publishing Co., Inc., Boston (2006)Google Scholar
- 2.Ford, B.: Packrat parsing: a practical linear-time algorithm with backtracking. Master’s thesis, Massachusetts Institute of Technology (September 2002)Google Scholar
- 3.Ford, B.: Packrat Parsing: Simple, Powerful, Lazy, Linear Time. In: ICFP 2002: Proceedings of the 7th ACM SIGPLAN International Conference on Functional Programming, pp. 36–47. ACM, New York (2002)Google Scholar
- 5.Grune, D., Jacobs, C.J.: Parsing Techniques: A Practical Guide, 2nd edn. Springer Publishing Company, Incorporated (2010)Google Scholar
- 7.Ierusalimschy, R.: LPeg - Parsing Expression Grammars for Lua (2008), http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html (visited on March 2013)
- 10.Leijen, D., Meijer, E.: Parsec: Direct Style Monadic Parser Combinators For The Real World. Technical Report UU-CS-2001-35, Department of Computer Science, Utrecht University (2001)Google Scholar
- 11.Louden, K.C.: Compiler Construction: Principles and Practice. PWS Publishing Co., Boston (1997)Google Scholar
- 12.Medeiros, S., Mascarenhas, F., Ierusalimschy, R.: From Regular Expressions to Parsing Expression Grammars. In: Brazilian Symposium on Programming Languages (2011)Google Scholar
- 14.Mizushima, K., Maeda, A., Yamaguchi, Y.: Packrat Parsers Can Handle Practical Grammars in Mostly Constant Space. In: PASTE 2010: Proceedings of the 9th ACM SIGPLAN-SIGSOFT Workshop on Program Analysis for Software Tools and Engineering, pp. 29–36. ACM, New York (2010)Google Scholar
- 16.Piumarta, I.: Peg/leg — recursive-descent parser generators for C (2007), http://piumarta.com/software/peg/ (visited on March 2013)
- 17.Röjemo, N.: Efficient Parsing Combinators. Technical report, Department of Computer Science, Chalmers University of Technology (1995)Google Scholar