3 ms·
The problem is the definition of "by hand". I assume you mean it as "writing code in a general programming language". Note that in a sense, lex/yacc and antlr a
by norswap 8y ago
The problem is the definition of "by hand". I assume you mean it as "writing code in a general programming language". Note that in a sense, lex/yacc and antlr are programming languages as well.
Parser combinators are usually put out in the form of DSLs. So effectively they're very similar to the above.
e.g. here are JSON and Java in Autumn
https://github.com/norswap/autumn4/blob/master/test/lang/json/JSON.java https://github.com/norswap/autumn4/blob/master/test/lang/jso...
https://github.com/norswap/autumn4/blob/master/src/norswap/lang/java/Grammar.java https://github.com/norswap/autumn4/blob/master/src/norswap/l...
There is actually very little difference between parser generators and parser generators. Like you could take the above Autumn code and make it generate a parser (I plan to do that eventually).
The main advantage of parser generators is that the code you generate is usually a faster. The main disadvantage compared to combinators is that you add a layer of indirection: it's not code in your language that you can trace and debug directly, but generated code.
The main advantage of Autumn over lex/yacc and ANTLR (and a whole host of others, though not all) is that you can define new combinators (not an advantage of PC, you could have this in a parser generator too). Essentially add the recursive-descent logic you need to do something new, then wrap in a nice combinator, and now your grammar has a new primitive element!
Autumn has cool built-in combinators that users could have built themselves using the available facilities. For instance: memoization, longest-match, ways to define left- and right-associative operators, ... (https://github.com/norswap/autumn4/tree/master/src/norswap/autumn/parsers https://github.com/norswap/autumn4/tree/master/src/norswap/a...)