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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pratt_calc-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 3b19b6243a4bbecf0c90a26f949b113ee5de168ec3a1b9ea86db674375fb1691
MD5 bbe954213dbb501c147f348a712f4669
BLAKE2b-256 b4374c6652cf69c5ed873a2ffd6f7597f13d3b74026ff3b2541686f1dbaee0b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pratt_calc-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 41accea2f645fb90b909bffbec16c3a56c083af37a44396245520a9ebcdd9caf
MD5 150837364b5a5583522fd4a2d82f2465
BLAKE2b-256 19bf3206304d12fbd74a57fa1c8b1e36774a23510986b3ad739269771beaddfe

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