So the parser can handle a single expression, but since we’re not building a Lisp, that’s not enough. It needs to handle multiple statements. For context, an expression is a piece of code that represents a value whereas a statement is a piece of code that can be executed but does not result in a value.
Subscribe to just rust posts via RSS.
Arithmetic expressions are all well and good, but they don’t really feel much like a programming language. To fix that, let’s start working on variables and function calls.
The code from part 4 that checks whether a pair of binary operators should be grouped to the left or right works, but I’m not particularly happy with it. The issue is that it needs to pattern match on the right node twice: first in the
should_group_left function, and then again in
should_group_left returned true.
Parsing groups is pretty straightforward, with only one minor pain point to keep in mind. I’ll gloss over adding left and right parentheses because it’s super easy—just another single character token.
In the process of adding floating point numbers, I ran into something a little bit unexpected. The issue turned out to be pretty simple, but I thought it was worth mentioning.