Skip to main content

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:

  1. Simple but Powerful Pratt Parsing
  2. Pratt Parsers: Expression Parsing Made Easy
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pratt_calc-0.1.6.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pratt_calc-0.1.6-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file pratt_calc-0.1.6.tar.gz.

File metadata

  • Download URL: pratt_calc-0.1.6.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.8

File hashes

Hashes for pratt_calc-0.1.6.tar.gz
Algorithm Hash digest
SHA256 37995560e055a3f739609d758ec1c4dae2e3b7b021c2fbd1321c98f20498fe3e
MD5 085fd50708b64171bd8c9119b52fdde8
BLAKE2b-256 0f4d420e9e35f1558395e0008a1c2edcf55705956f024ae89c76051925cbc4be

See more details on using hashes here.

File details

Details for the file pratt_calc-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: pratt_calc-0.1.6-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

Hashes for pratt_calc-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 24ca95e0e9a562b41a7264c4552407a961d4615a15a4977714674210055d3dd7
MD5 e2abaa6668ceb1a72b6ba9a9e2675c9f
BLAKE2b-256 40c02875ed18a850ff16dfc4a0def6cd5208b5ea2c41c7047e3f81645b3fe1e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page