Skip to content

btwotwo/calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Used crates

In the production application I would probably also use chumsky crate, since it simplifies the whole process. But it was interesting for me to implement parser and tokenizer myself, so I didn’t use it this time :)

thiserror

Simplifies boilerplate for defining custom error types. I used it in parser and tokenizer modules.

test-case

Self-explanatory :)

Usage

The calculator accepts expressions via STDIN:

echo '2 / (3 - 1)' | castor_calculator

No special build steps required, cargo build is enough :)

Approach

The calculator uses the grammar described in the parser.rs in combination with the recursive descent. Before parser is invoked, the input is run through the tokenizer, preventing invalid input at the beginning. Parser only works with the list of tokens, not with the raw string.

About

Simple calculator with AST parsing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors