This project implements a basic Pratt parser for parsing simple arithmetic expressions. Pratt parsing is a top-down operator precedence parsing technique that allows for parsing expressions with varying levels of operator precedence.
Some of the references I based this on:
- An amazing article on the idea of "binding power" as a function of operator precedence by @matklad: Simple but Powerful Pratt Parsing
- A great functional article on the core implementation of pratt parsing by Bob Nystrom: Pratt Parsers: Expression Parsing Made Easy
- This entire chapter of parsing from the Crafting Interpreters book.
Make sure you have Rust installed on your system. If not, you can install Rust.
Clone the repository to your local machine:
git clone https://github.com/bIgBV/calc
Navigate to the project directory and run the following command to build and run the parser:
cargo run
This will build the project and execute the parser on a set of sample arithmetic expressions.
The Pratt parser in this project is designed to handle basic arithmetic expressions containing the following operators:
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Grouping (
()
)
This project is licensed under the MIT License - see the LICENSE file for details.