Parser Combinators
Parser combinators take lists of tokens and produce a parse tree for us.
- Atomic parsers have a concrete task of parsing a number or keyword.
- Sequence and alternative parsers build bigger parsers out of smaller components.
- Semantic action (map-parser) is applying a function to the parsed part.
Examples of parsers
-
Atomic parser, for example, for number tokens:
You consume one or more tokens from the input stream. This also works for characters and strings.
-
Alternative parser (code ) Apply and also then combine the outputs
-
Sequence parser (code ) Apply first producing a set of pairs Then apply to the unparsed parts Then combine the results:
-
Map-parser (code ) Apply producing a set of pairs Then apply the function to each first component
is the semantic action (what to do with the parsed input)
Semantic Actions Addition
Multiplication
Parenthesis