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.1.tar.gz (21.2 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.1-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: meth-2.1.1.tar.gz
  • Upload date:
  • Size: 21.2 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.1.tar.gz
Algorithm Hash digest
SHA256 deab308f06b22083b9ece28498df447202652890d76129c452d538938f15852a
MD5 b257c10f5639322730b1280d876d442a
BLAKE2b-256 9c4ae3a6f853042417ddd5f148ae945bee0aaa931a1a158b8783a5ff89f71ec4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: meth-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c265c7982aee9973d5bda60f70cab6c82399f468797cc3f4bb9e0537fa13ac59
MD5 dda912a1bcf9a97a406dc49d866858fc
BLAKE2b-256 b9926fe31e3b84d1e763bdd560a1516931a37dd9ce01cc2a3819112c57758985

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