Efficient Combinator Parsers

Parser combinators enable the construction of recursive descent parsers in a very clear and simple way. Unfortunately, the resulting parsers have a polynomial complexity and are far too slow for realistic inputs. We show how the speed of these parsers can be improved by one order of magnitude using continuations. These continuations prevents the creation of intermediate data structures. Furthermore, by using an exclusive or-combinator instead of the ordinary or-combinator the complexity for deterministic parsers can be reduced from polynomial to linear. The combination of both improvements turn parser combinators from a beautiful toy to a practically applicable tool which can be used for real world applications. The improved parser combinators remain very easy to use and are still able to handle ambiguous grammars.

[1]  Steve Hill,et al.  Combinators for parsing expressions , 1996, Journal of Functional Programming.

[2]  Simon L. Peyton Jones,et al.  Yacc in sasl — an exercise in functional programming , 1985, Softw. Pract. Exp..

[3]  Murray Hill,et al.  Yacc: Yet Another Compiler-Compiler , 1978 .

[4]  Andrew W. Appel,et al.  Compiling with Continuations , 1991 .

[5]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[6]  Graham Hutton,et al.  Higher-order functions for parsing , 1992, Journal of Functional Programming.

[7]  Jeroen D. Fokker,et al.  Functional Parsers , 1995, Advanced Functional Programming.

[8]  Philip Wadler,et al.  Packrat parsing:: simple, powerful, lazy, linear time, functional pearl , 2002, ICFP '02.

[9]  Rinus Plasmeijer,et al.  Concurrent Clean Language Report - version 1.3 , 1998 .