Skip to content

notmd/calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple calculator written in Rust.

This is a fist time I learn about parser and Rust, so I decide to write a simple calculator using the Recursive Descent algorithm with the following grammar:

E --> T {( "+" | "-" ) T}
T --> F {( "*" | "/" ) F}
F --> P ["^" F]
P --> v | "(" E ")" | "-" T | Function "(" {E[,]} ")"

This grammar is base on this awesome guide. I also extends it to support function.

Example:

cargo run "1+2*sqrt(4)"

Feature:

  • Support the following operators: +,-,*,/,^.
  • Built in functions:
    • sin
    • cos
    • tan
    • sqrt
    • abs
    • max: max(arg1,arg2,...)
    • min: min(arg1,arg2,...)
  • Built in constants:
    • PI
    • e

TODO:

  • Support for variables.
  • Better error handling.

About

A simple calculator written in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages