Efficient parsing with parser combinators

Jan Kurs*, Jan Vrany, Mohammad Ghafari, Mircea Lungu, Oscar Nierstrasz

*Corresponding author for this work

Research output: Contribution to journalArticleAcademicpeer-review

3 Citations (Scopus)
153 Downloads (Pure)


Parser combinators offer a universal and flexible approach to parsing. They follow the structure of an underlying grammar, are modular, well-structured, easy to maintain, and can recognize a large variety of languages including context-sensitive ones. However, these advantages introduce a noticeable performance overhead mainly because the same powerful parsing algorithm is used to recognize even simple languages. Time-wise, parser combinators cannot compete with parsers generated by well-performing parser generators or optimized hand-written code.

Techniques exist to achieve a linear asymptotic performance of parser combinators, yet there is a significant constant multiplier. The multiplier can be lowered to some degree, but this requires advanced meta-programming techniques, such as staging or macros, that depend heavily on the underlying language technology.

In this work we present a language-agnostic solution. We optimize the performance of parsing combinators with specializations of parsing strategies. For each combinator, we analyze the language parsed by the combinator and choose the most efficient parsing strategy. By adapting a parsing strategy for different parser combinators we achieve performance comparable to that of hand-written or optimized parsers while preserving the advantages of parsers combinators. (C) 2017 Elsevier B.V. All rights reserved.

Original languageEnglish
Pages (from-to)57-88
Number of pages32
JournalScience of computer programming
Publication statusPublished - 1-Sept-2018


  • Optimizations
  • Parsing expression grammars
  • Parser combinators

Cite this