Skip to content

TopiCsarno/numper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

numper

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

Features

  • integer and floating-point numbers
  • unary + and -
  • operators +, -, *, /, ^
  • parentheses
  • operator precedence and right-associative exponentiation
  • test suite with parser, postfix, evaluator, and stack coverage

Build

make

Run

make run

Enter 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 --debug

Test

make test

Supported Syntax

  • numbers like 42, 3.14, .5, -2
  • repeated unary signs like --3 or ---2
  • unary minus before parentheses like -(1+2)

Limitations

  • no functions like sin() or log()
  • no variables
  • no overflow handling
  • division by zero follows the C math runtime
  • expressions longer than the fixed stack size are rejected

Layout

  • src/token.c: tokenizer
  • src/postfix.c: infix to postfix conversion
  • src/eval.c: postfix evaluator
  • src/stack.c: generic stack storage helpers
  • test/: unit tests

About

Small expression calculator in C with infix parsing and postfix evaluation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors