Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bigbv/calc
A simple pratt parser implementation
https://github.com/bigbv/calc
Last synced: about 2 months ago
JSON representation
A simple pratt parser implementation
- Host: GitHub
- URL: https://github.com/bigbv/calc
- Owner: bIgBV
- License: mit
- Created: 2024-01-18T04:59:23.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-16T02:49:12.000Z (12 months ago)
- Last Synced: 2024-10-30T12:52:01.514Z (3 months ago)
- Language: Rust
- Size: 147 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pratt Parser for Simple Arithmetic Expressions
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](https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html)
* A great functional article on the core implementation of pratt parsing by Bob Nystrom: [Pratt Parsers: Expression Parsing Made Easy](https://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/)
* This entire chapter of parsing from the [Crafting Interpreters](http://craftinginterpreters.com/compiling-expressions.html) book.## Getting Started
### Prerequisites
Make sure you have Rust installed on your system. If not, you can [install Rust](https://www.rust-lang.org/learn/get-started).
### Installation
Clone the repository to your local machine:
```bash
git clone https://github.com/bIgBV/calc
```### Usage
Navigate to the project directory and run the following command to build and run the parser:
```bash
cargo run
```This will build the project and execute the parser on a set of sample arithmetic expressions.
## Parser Details
The Pratt parser in this project is designed to handle basic arithmetic expressions containing the following operators:
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Grouping (`()`)## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.