There are two ways in which our tokenizer might encounter parenthesis. The first is to group a lower-precedence operator, as in:
(3 + 4) * 6
The next is in the use of function calls.:
f(4)
For now, we want to pull out the () as tokens. We’ll allow something at a higher level to determine the context.
Create a first test to see what happens when we use (:
Interesting, this works. I’m skeptical that we’ve got it working as needed. Knowing a little bit about the code, I’ll add another test:
There’s the failure I’m expecting:
Now it’s time to update the code just a touch. Rather than changing how to handle operators, I’ll add another match:
Run your tests, that seems to work.
Now is a good time to commit your code.
After this, it seemed like there was a pattern in the code that I could represent with an array and a loop. Here’s another version that also works. I’m not sure if I like this better or not.
Comments