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 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.