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)
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.1-py3-none-any.whl
(23.2 kB
view details)
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deab308f06b22083b9ece28498df447202652890d76129c452d538938f15852a
|
|
| MD5 |
b257c10f5639322730b1280d876d442a
|
|
| BLAKE2b-256 |
9c4ae3a6f853042417ddd5f148ae945bee0aaa931a1a158b8783a5ff89f71ec4
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c265c7982aee9973d5bda60f70cab6c82399f468797cc3f4bb9e0537fa13ac59
|
|
| MD5 |
dda912a1bcf9a97a406dc49d866858fc
|
|
| BLAKE2b-256 |
b9926fe31e3b84d1e763bdd560a1516931a37dd9ce01cc2a3819112c57758985
|