Arithmetic calculator which uses a Pratt parser
Project description
Introduction
An arithmetic expression calculator in Python, demoing the Pratt parsing algorithm.
This takes inspiration from this 2010 blog post by Eli Bendersky, as well as a few other sources:
- Simple but Powerful Pratt Parsing
- Pratt Parsers: Expression Parsing Made Easy
- Compiling Expressions (Chapter 17 of Crafting Interpreters)
Requirements
Requires Python 3.13 or greater.
Installation
pipx install pratt-calc
In some cases it may be necessary to specify the Python version manually:
PIPX_DEFAULT_PYTHON=python3.13 pipx install pratt-calc
Or, if you have uv installed:
uvx pipx install pratt-calc
Contributing
Install uv, then run:
git clone https://github.com/BrandonIrizarry/pratt-calc
cd pratt-calc
uv sync --locked
Usage
pratt-calc $EXPRESSION
Example:
pratt-calc 3-4*5
This should print -17 at the console.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pratt_calc-0.1.7.tar.gz.
File metadata
- Download URL: pratt_calc-0.1.7.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f98081daafc0247a4421139114859e42ed63467f2524f01ac7b50f1cd0f13870
|
|
| MD5 |
87b716fb56665ea8340b7b0c4b134267
|
|
| BLAKE2b-256 |
3f5f45ebc713a18d5ccf7e97bdf079ba54734e57c708d358e009c52b26712806
|
File details
Details for the file pratt_calc-0.1.7-py3-none-any.whl.
File metadata
- Download URL: pratt_calc-0.1.7-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bef3cdc7b80a6797ad10f0242e9d047a190e231876aeb305ce199da2fe8703a0
|
|
| MD5 |
31e59bced68ab9c73a4cbc26c7b95ea2
|
|
| BLAKE2b-256 |
3df5daa959d0e3c9438fd8df5a32a81d63fb1861ddce3cfcc5e2aabf6726326f
|