This project implements a simple calculator lexer and parser in Rust. It can tokenize mathematical expressions, parse into an abstract syntax tree (AST) and evaluate them.
>> 10 + 20
30
>> (5 * 6) - 4
26
>> 3.14 * (2 + 1)
9.42
The calculator supports basic arithmetic operations including addition, subtraction, multiplication, division, and power operations, as well as floating-point numbers. It also supports parentheses for grouping expressions.
- Tokenization of numbers, operators, and parentheses.
- Parsing of expressions into an AST using the Pratt parsing technique.
- Evaluation of expressions with support for floating-point numbers.
- Error handling for invalid expressions and tokens.
To use this project, clone the repository and run:
- Clone the repository:
git clone https://github.com/joeCavZero/calculator-lexer-and-parser.git
- Navigate to the project directory:
cd calculator-lexer-and-parser
- Run or build the project:
cargo run
cargo build --release