3 ms·
If someone wants to have a look at the code of a cutting-edge parser combinator framework with focus on features + usability, I'll plug this here (it's in Java)
by norswap 8y ago
If someone wants to have a look at the code of a cutting-edge parser combinator framework with focus on features + usability, I'll plug this here (it's in Java)
https://github.com/norswap/autumn4 https://github.com/norswap/autumn4
WIP but 1.0.0 will land somewhere within the next two months, with a full user-guide (half of it is already written and available).
Constructive feedback welcome!
- tempguy9999 8y agoHonest question, why use parser combinators? If I need to do it by hand I can write a recursive descent parser, but I never do it by hand any more, just break out lex/yacc or antlr. So, what have I or anyone to gain by learning/using PCs? (I'm never against learning new stuff but I have so much to learn that adding something unnecessary to that would be just dumb). TIA
- fooker 8y agoParser combinators aid in writing recursive descent parsers, they are not something alien. You can maybe consider it a design pattern which eliminates redundancies and makes it easier to construct an AST.
- norswap 8y agoThe 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...)