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
Release history Release notifications | RSS feed
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.2.tar.gz
(21.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
meth-2.1.2-py3-none-any.whl
(23.3 kB
view details)
File details
Details for the file meth-2.1.2.tar.gz.
File metadata
- Download URL: meth-2.1.2.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59f2502898a8cc215db033a1444aeed4e8e4ceed222faa3662072d18c652a46e
|
|
| MD5 |
551c8605747b2b19f24212976b3d7f45
|
|
| BLAKE2b-256 |
3f78ccb5789b12e8ce2bad8d100be77208c79e43b58a33c1bb2785c5d9a3669b
|
File details
Details for the file meth-2.1.2-py3-none-any.whl.
File metadata
- Download URL: meth-2.1.2-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e95bce80b1dd37ed510c032823e5cb55c0350320f6f2f748a98da80a1149f3ac
|
|
| MD5 |
b2799ee249ab1eb162355e4de3853e9b
|
|
| BLAKE2b-256 |
44b7c26df015b3cb9dace1c36d5cdf71391c999f7048cea7c24cc85a2ccdff84
|