numper is a small calculator REPL written in C.
The project was built as practice for:
- tokenizing infix expressions
- converting infix to postfix with the shunting-yard algorithm
- evaluating postfix expressions with a stack
- writing low-level tests without hiding behind a framework the size of a small moon
- integer and floating-point numbers
- unary
+and- - operators
+,-,*,/,^ - parentheses
- operator precedence and right-associative exponentiation
- test suite with parser, postfix, evaluator, and stack coverage
makemake runEnter an expression at the prompt:
> 1+2*(3-1)
= 5
> -(1+2)^2
= -9
Type q to quit.
For tokenizer and postfix debug output:
./calc --debugmake test- numbers like
42,3.14,.5,-2 - repeated unary signs like
--3or---2 - unary minus before parentheses like
-(1+2)
- no functions like
sin()orlog() - no variables
- no overflow handling
- division by zero follows the C math runtime
- expressions longer than the fixed stack size are rejected
src/token.c: tokenizersrc/postfix.c: infix to postfix conversionsrc/eval.c: postfix evaluatorsrc/stack.c: generic stack storage helperstest/: unit tests