Contents
When would you use a parser generator?
Traditionally, parser generators work by allowing the user to specify custom code for each rule, which is then copy-pasted into the generated parser. This is typically used to construct an abstract syntax tree, but could be used, for example, to evaluate arithmetic expressions during parsing.
Do you need a Lexer?
A complete parser is usually composed of two parts: a lexer, also known as scanner or tokenizer, and the proper parser. The parser needs the lexer because it does not work directly on the text, but on the output produced by the lexer.
How are combinators used in classical parsers?
Classical Parser Combinators are nothing more than ‘lego pieces’ that can be put together to build an LL-style parser. LR parsing travels the other way, bottom-up: At each step, the top element (s) on the stack are compared to the list of grammar, to see if they could be reduced to a higher-level rule in the grammar.
Which is the best parser combinator in Haskell?
The Introduction to Parsec tutorial on Parsec, which is a Parser Combinator in Haskell, does not mention Parser Generators at all. Boost::spirit, the best-known C++ Parser Combinator, does not mention Parser Generators at all. The great explanatory blog post You Could Have Invented Parser Combinators does not mention Parser Generators at all.
How are parser generators written in the DSL?
Parser Generators are written in a combination of the EBNF-ish DSL and the code that these statements should generate to when they match. Parser Combinators are written in the target language directly.
What’s the difference between a parser generator and lexer generator?
Parser Generators have a very distinct difference between the ‘lexer’ (which splits a string into tokens that might be tagged to show what kind of value we are dealing with) and the ‘parser’ (which takes the output list of tokens from the lexer and attempts to combine them, forming an Abstract Syntax Tree).