cheatsheets devlog projects search

four-function-calculator.md

Four Function Calculator

2022-11-28 1

I’m working on writing a HTML template engine using BASIC and I’ve learned why writing a four function calculator is important.

The for loop logic was straightforward to implement in the template engine but now that I’m dealing with conditionals, I need to evaluate things. This is exactly where writing a calculator would be handy. Given a string, what is the solution?

I’m pretty happy that it is hitting me like this as it means that there is still so much to learn and know. It also means that writing a templating engine was a good idea even though I had no idea where to even start with it.

The first step to writing the calculator is to convert infix notation to postfix. The second step is to evaluate the postfix notation. I think this is the path to take. Hopefully it pans out.