Skip to main content

A lightweight and basic maths interpreter

Project description

mathterpreter

A lightweight and basic maths interpreter

Example usage

Basic usage

from mathterpreter import interpret

print(interpret("54-3*(2+1)-3", use_decimals=False))

Step by step

from mathterpreter import Lexer, Parser

lexer = Lexer("54-3*(2+1)-3", use_decimals=False)
tokens = lexer.tokenize()
parser = Parser(tokens)
tree = parser.parse()
result = tree.evaluate()
print(result)

use_decimals determines whether numbers should be handled as decimal.Decimal rather than float for more accurate but slower calculations. Defaults to True

Command line

python3 -m mathterpreter 54-3*(2+1)-3
# or
echo 54-3*(2+1)-3 | python3 -m mathterpreter

Syntax:

Operation Syntax
Addition a+b
Subtraction a-b
Multiplication a*b
Division a/b
Exponentiation a^b
ath root a√b or asqrtb
Standard Form: aE+b (shorthand for a*10^b)

Constants:

Symbol(s) Value
π/pi 3.141592653589793
e 2.718281828459045
All constants are just replaced with their value, wrapped in brackets.

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

mathterpreter-1.1.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

mathterpreter-1.1.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file mathterpreter-1.1.2.tar.gz.

File metadata

  • Download URL: mathterpreter-1.1.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5

File hashes

Hashes for mathterpreter-1.1.2.tar.gz
Algorithm Hash digest
SHA256 ac4d545ecda0117d32f05b66bebe71f289a11e09f8dc04d1c6a5abd9ee175ce5
MD5 1344d9034d0bc50e6665dfd795eeb9be
BLAKE2b-256 bc938231f3e990fe815a98465490f8dcb34f04f66c5b8c2f1fa4ce500c89ad1a

See more details on using hashes here.

File details

Details for the file mathterpreter-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: mathterpreter-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5

File hashes

Hashes for mathterpreter-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9e766419f4d19d596c3e5ea040594c6a820f0fff93e0e80520ed5d5b88e34f30
MD5 1f46452e5d91952f56544ecddee1c5e9
BLAKE2b-256 8466d00f6be7c45d6ec0a652bdf873a2cf3e624958d47e8de1072cb5ea415c11

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page