Capstone B: an expression parser and evaluator
The second capstone of the Haskell course builds an expression parser and evaluator in eight lessons. A lexer turns the input into tokens, a recursive descent parser turns them into a tree, and an evaluator answers with a value or an error that carries a position. A REPL follows, then the tests over a table of expressions, and a variable added in the last lesson to show what a feature costs.
10.1
Capstone B: the tokens
a token type, a lexer, numbers and operators
Open
10.2
Capstone B: the parser
a recursive descent parser, precedence climbing, an error with a position
Open
10.3
Capstone B: the syntax tree
an expression type, show for it, a round trip
Open
10.4
Capstone B: evaluation
an evaluator over the tree, division by zero, Either for the error
Open
10.5
Capstone B: errors a user can read
a position in the input, the message, the exit status
Open
10.6
Capstone B: the REPL
a loop over getLine, :quit, a running total of errors
Open
10.7
Capstone B: testing the evaluator
a table of expressions and values, the parser and the evaluator together
Open
10.8
Capstone B: adding a feature
a variable, an environment, the parser change and the tests that follow
Open