Dylan Carroll
Dylan Carroll

Command-Line Calculator

Nov 2020


Much more detail on the specifics of the syntax and functionality of the calculator can be found in the readme on its github repo: https://github.com/DylanScottCarroll/Command-Line-Calculator

This is a calculator written in python that runs in the terminal. The program uses python data types and math functions, but I wrote all of the parsing logic myself. This calculator has largely been an exercise in parsing user input and parsing mathematical expressions using regular expressions and finite context-free grammars.

I wrote this because I seldom used the Windows calculator and instead typed calculations right into the windows search bar because I found the calculator slow and cumbersome to open and use. Most of the time, this shows up as a bing search, which has the result of the calculation. The advantage of this is that all I need to do is quickly hit the windows key and start typing. The problem is that this uses bing, and it doesn't work all of the time (sometimes it thinks you're trying to search for files). On my PC, I have this calculator linked to run whenever I type a keyboard shortcut, so it is just as fast.

The inner workings of this calculator were inspired by a few things that I've learned in my studies of Computer Science. First, was a brief example problem in an introductory class that referenced postfix notation for mathematical expressions. That got me interested in the shunting yard algorithm, which converts standard notation of expressions into postfix, which is easy to evaluate programmatically. I wrote the calculator initially in November of 2020, after becoming frustrated with the windows calculator. The code was pretty messy and there were a lot of things wrong with it, but it worked very well for my purposes.

Later, I began a new Computer Science class studying state machines, regular expressions, and regular grammar. This inspired me to more robustly rewrite the entire calculator using regular expressions and an LL1 parser to parse the input before converting it to postfix.

Now the calculator is much more robust and extensible.