3 ms·
I use higher-order parser combinators in a few different languages and its not really that noticable on a modern machine assuming you're parsing human-written s
by convolvatron 8y ago
I use higher-order parser combinators in a few different languages and its not really that noticable on a modern machine assuming you're parsing human-written source and not gigabytes of json.
but if you look at it, the real cost is in closure creation and control transfers (function indirection). functional compilers are already trying really hard to make those costs disappear.
there is some really interesting work lately in manual vectorization of traditionally control flow laden tasks like parsing. i would fully expect some clever people in an appropriate linguistic framework to make frameworks for automating that transformation.
but for me personally I find the parser combinator approach:
o a pretty direct translation of a model you might see in BNF
o considerably easier to maintain/extend/reuse than either external parser generator or recursive descent
o more straightforward in the construction of output values than the traditional approach of a parser generator language
o amenable to a flexible decomposition of layers rather than the traditional scanner/parser split (alot of simple languages dont really need that distinction)
o self contained - removes a big external dependency
o simplifies the build
its a really good default in the absence of other constraints
- thedufer 8y agoA lot of the closure creation costs can be eliminated by writing the library in a continuation-passing style, which shoves all of the data into proper arguments, bypassing the need for the closure. Of course, the user of the library is still likely to generate closures. The implementation of this I'm most familiar with is OCaml's angstrom library.