Skip to main content

A mathematical expression parser and evaluator.

Project description

meth: A mathematical expression evaluator.

A python package to parse and evaluate mathematical expressions.

Installation

pip install meth

or install it from source:

git clone https://github.com/sertdfyguhi/meth/
cd meth
python3 -m build
pip install dist/*.whl

Examples

More examples in the examples/ directory.

import meth

# tokenizing expression
meth.tokenize("5 + 2") # [Token(TokenType.NUMBER, 5), Token(TokenType.ADD), Token(TokenType.NUMBER, 2)]

# parsing expression
meth.parse("7 * 2") # BinaryOp(Number(7), TokenType.MUL, Number(2))

# evaluating expression
meth.evaluate("4 ^ 2") # 16
meth.evaluate("3(1 + 2)") # 9
meth.evaluate("sqrt(9)") # 3

# evaluation with variables
evaluator = meth.Evaluator()
evaluator.evaluate("x = 5")
evaluator.evaluate("x") # 5

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

meth-2.1.0.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

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

meth-2.1.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file meth-2.1.0.tar.gz.

File metadata

  • Download URL: meth-2.1.0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for meth-2.1.0.tar.gz
Algorithm Hash digest
SHA256 fac066f406b112d77ae7a0ea78029048ca0c50e2733fd7cbbc5786a50f39c8b2
MD5 709c53524496a765e46d20adcf945c05
BLAKE2b-256 4d2359894c71cd565247d9446124d7d69617f4fb3184850bfc4682d6e2f0a81b

See more details on using hashes here.

File details

Details for the file meth-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: meth-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for meth-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b7a7cbbb118e09204d8b1eba8a6eb3486bcb62f921f41d50be4f7348472fc79
MD5 2743e2e8d2c12f3f0910766a40661f47
BLAKE2b-256 be87c7802c8ab43305c8d2e94cd60053c681b4fe9ba8a63ee2fb4f81cb5d5bf4

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