A mathematical expression calculator, written in Python.
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Aadhavan Srinivasan 88902d9066 Added additional error checking, for number formatting and consecutive operators 11 months ago
.gitignore Added gitignore file 11 months ago
README.md Updated README 11 months ago
calculator.py Added additional error checking, for number formatting and consecutive operators 11 months ago
parse.py First commit 11 months ago
todo.txt Added TODO file 11 months ago

README.md

Pycalc

Pycalc is a simple expression calculator. It can evaluate mathematical expressions, and output the result of the evaluation.

How it works

  1. Scan the expression
    • Check for malformed expression and invalid characters
    • Tokenize the expression (I wrote a custom parser to do this)
  2. If there are any parantheses, replace the parantheses with the result of the sub-expression.
  3. Evaluate the overall expression (which should no longer have any parantheses)

Rather than building a tree from the expression (which is the recommended approach), I have opted to perform the substitutions in-place. This means that the result of an operation replaces the operation itself.

The reason I chose to do this, is that my parsing algorithm considers everything inside parantheses as a single token. Therefore, it is fairly easy to replace this token with the result of the expression within the parantheses.

Features

  • Order of operations
  • Arbitrary whitespace
  • Parantheses
  • Simple error checking

To-do

  • Simple algebraic parsing (assign values to variables, etc.)
  • More robust error-checking