Skip to content

sertdfyguhi/meth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A Python library to parse and evaluate mathematical equations.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages