Skip to content

pariola/calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

calculator

mathematical expression evaluator with the Shunting Yard Algorithm.

This implementation of the Shunting Yard Algorithm has:

- no support for unary operations like '-1' or '1+(-2)'
- no support for functions like sqrt(64)

The calculator supports the following:

Operations:
- '-' (subtraction)
- '+' (addition)
- '*' (multiplication)
- '/' (division)
- '^' (exponent)

Supports Parenthesis

Number formats:
- integers
- floats

Use

go run main.go
> 5*2*(1*9)
90
> 5+2*(1*9)+5^2
48 

To run tests:

go test ./...

Flow

Input -> Lexical Analysis -> Parsing (Shunting Yard) --> Evaluate --> Output