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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pratt_calc-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 3ef66f9bd42d6f1a0e3550990a38917f3594008c51263e1b68c27bcae547a1e6
MD5 96396317762425ecde2ef9f0f97aacea
BLAKE2b-256 eb4f562f2f5a04a9180e73f89ad83cc3aa9af7901c40a08a6733c181c1d6cbd0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pratt_calc-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a1c309e15ed148da1bab5314f870dcc8e434250f58d4e5d75eeb090db2d9cdae
MD5 662084d4cfdd95b24cbe89b565a1288b
BLAKE2b-256 716a79d7ac332013ee693751548f9d013656a94c5686080dd68827bc94615b3f

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