build a programming language posts

Subscribe to just build a programming language posts via RSS.

Part 7: Cleaning Up Binary Operators

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 combine_with_binary_operator if should_group_left returned true.

Part 6: Grouping

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.

Part 5: Fixing Floats

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.

Part 4: Operator Precedence

I’ve gone through the lexer, parser, and evaluator and added subtraction, multiplication, and division in addition to, uh… addition. And they kind of work, but there’s one glaring issue that I mentioned back in part 2. It’s that the parser has no understanding of operator precedence. That is to say, it doesn’t know which operators have a higher priority in the order of operations when implicit grouping is taking place.

Part 3: Basic Evaluation

Last time I said operator precedence was going to be next. Well, if you’ve read the title, you know that’s not the case. I decided I really wanted to see this actually run[1] some code[2], so let’s do that.