4 ms·
> Parser generators are a great help in writing parsers, but they all have one major drawback--they are based on grammars. So what's wrong with grammars? Well .
by munro 12y ago
> Parser generators are a great help in writing parsers, but they all have one major drawback--they are based on grammars. So what's wrong with grammars? Well ... nothing as an expository tool. When you want to diagram a complex rule for deriving tree-like structures within a string of symbols, nothing beats a good old-fashioned grammar. But when you want to write a computer program to convert a string into the logical structure that it represents and then use that logical structure for further processing, then grammars are not ideal.
Not sure what they mean by "logical structure". But I've used Parsec to convert a string into AST. Then did a second pass with Parsec to turn that AST into VM representations of what the program is talking about. Which worked really well for me. :)
- tel 12y agoAnd if that's not a "logical" enough of a structure then you can skip the AST step if you really like and parse directly into the final effect.
- david-gudeman 12y agoBy "logical structure" I mean the AST. I make this clear in the rest of the document. The point is, with Classp you don't have to write a grammar to create a parse tree and then convert to an AST; you write a specification that produces the AST directly.