__                     _ ____   __
  / /_____ _      _______(_) __/  / /_
 / __/ __ \ | /| / / ___/ / /_   / __ \
/ /_/ /_/ / |/ |/ (__  ) / __/_ / / / /
\__/\____/|__/|__/____/_/_/  (_)_/ /_/
                                       
Home Blog Projects Work

Parsematic

Jan 02, 2024

A math expression parser written in Python that supports arithmetic, comparison, and mathematical functions.

Parsematic

A basic math parser that can parse and evaluate mathematical expressions.

Features

  • Integers, floats, and constants (PI, TAU, E, INF)
  • Basic arithmetic (+, -, *, /, **, //, %)
  • Comparison operators (==, !=, <, >, <=, >=)
  • Mathematical functions (sin, cos, tan, abs, sqrt, log, fact, gcd, lcm)
  • Parentheses for grouping

Installation

pip install parsematic

Usage

from math_parser import MathParser

parser = MathParser()
result = parser.parse("2 + 3 * (4 - 1)")
print(result)  # Output: 11

Or from the command line:

python -m parsematic "2 + 3 * (4 - 1)"