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.5.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.5-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pratt_calc-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 6ee847499beaa800d328b931050d85257f55e6212de85de691034e6955e247d6
MD5 c4935d2bb1d3f2f2f40eff3b9c87643a
BLAKE2b-256 ce4352507b8949c5ab356cef61fe98325573700906a809d625805fefe3ed27ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pratt_calc-0.1.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9184506b83473ed2b592a31429bdc5c5b48b9b89f1ad14d976d4366a26e2931c
MD5 6a93bbecd9e6106cd35ea631deb048a2
BLAKE2b-256 88e84d5b6293b3705ddc9079711f0b4f52c205e578f23306a73668bce524e9a7

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