This project was created just for fun and in order to complete the assignment in college. It is a custom interpreter for math expressions, inspired by the Desmos graphing calculator.
To use this interpreter, you first need to copy this repository to folder that you opened in terminal. To do this, go to powershell or bash (or any other terminal) and enter the command:
git clone "https://github.com/Bobfob/Math-Interpreter.git"Next, after you have copied the repository, you need to run the file main.py using Python 3.14 or higher and try to type some expressions into terminal.
- Variables (as well constant variants)
- Functions with local scoping
- Data deletion
- Ternary operator
- Point2D and Point3D
- Strings (with built-in methods)
- Hash Tables (Dictionaries)
- Boolean datatype (
true/false) and logical operations - Attribute and Index assignment
- Augmented assignments (
+=,-=,*=,/=,%=,**=,&=,|=,^=) - Bitwise operators (
&,|,^) - And others (all list you can see in help message, type .help while running)
- @pi - π variable
- @e - Euler value
- @tau - 2π variable
- cos - Calculates cosine with given radians
- sin - Calculates sine with given radians
- tan - Calculates tangent with given radians
- cot - Calculates cotangent with given radians
- sec - Calculates secant with given radians
- csc - Calculates cosecant with given radians
- ln - Calculates natural logarithm with given x
- log - Calculates logarithm of base 10 with given x
- logn - Calculates logarithm of base n with given x
- exp - Calculates exponent with given x
- sqrt - Calculates square root of given x
- cbrt - Calculates cube root of given x
- abs - Returns absolute value of given x
- floor - Returns floored value of given x
- ceil - Returns ceiled value of given x
- cosh - Returns hyperbolic cosine with given x
- sinh - Returns hyperbolic sine with given x
- tanh - Returns hyperbolic tangent with given x
- coth - Returns hyperbolic cotangent with given x
- sech - Returns hyperbolic secant with given x
- csch - Returns hyperbolic cosecant with given x
- cos_d - Calculates cosine with given degrees
- sin_d - Calculates sine with given degrees
- tan_d - Calculates tangent with given degrees
- cot_d - Calculates cotangent with given degrees
- sec_d - Calculates secant with given degrees
- csc_d - Calculates cosecant with given degrees
- clamp - Returns clamped value with given value, minimal value and maximum value
- min - Returns minimum value of given x, y, etc
- max - Returns maximum value of given x, y, etc
- asin - Returns arc sine with given value between -1 and 1
- acos - Returns arc cosine with given value between -1 and 1
- atan - Returns arc tangent with given x
- atan2 - Returns arc tangent with given values y and x (i.e. atan(y / x))
- asinh - Returns arc hyperbolic sine with given x
- acosh - Returns arc hyperbolic cosine with given x
- atanh - Returns arc hyperbolic tangent with given x
- copysign - Returns absolute value of x but with sign of y
- degrees - Converts radians to degrees (x * 180 / π)
- radians - Converts degrees to radians (x * π / 180)
- fabs - Works exactly like abs, but always returns float value
- lcm - Returns least common multiple
- gcd - Returns greatest common divisor
- perm - Returns number of permutations (n! / (n - k)!)
- Added angle property for points.
- Hash table
has_keymethod now returnsBooleandatatype. - Fixed
Numberdatatype operations (raw ints and floats are now normally works with this datatype). normalizemethod is not longer exists for points, now it'snormalizedproperty.
- Fixed skipped XOR augmented assign in parser.
- Added Boolean Datatype:
- Introduced
trueandfalseliterals. - All comparison operators (
>,<,==,!=,>=,<=) now return aBooleaninstead of a raw number/float/bool. - Boolean logic is supported using the
&(AND) and|(OR) operators. For example:true & falseresults infalse. - Booleans can be used as keys in Hash Tables.
- Introduced
- Added Augmented Assignments: You can now use
+=,-=,*=,/=,%=,**=,&=,|=,^=operators. For example:a = 5; a += 2results inabecoming7. - Added Bitwise Operators: Added
&(bitwise AND),|(bitwise OR) and^(bitwise XOR) operators for Number datatype. - Fixed Local Scoping in Functions: Variables assigned inside a function (e.g.,
f(x) = (x = x + 1)) now properly update the local frame instead of leaking to the global scope. Assignments are now allowed inside parentheses. - Improved Function Printing: The
.funcsand.definescommands now print functions in a clean, human-readable format (e.g.,f(x) = (x + 1)) instead of raw AST object representations. - Added full support for Strings:
- String literals can be defined using single or double quotes:
"hello",'world'. - Escape sequences are supported:
\n,\t,\\,\", etc. - Concatenation via
+operator. - Repetition via
*operator (e.g.,"hi" * 3). - Indexing to get a single character (e.g.,
s[0]). - Built-in string methods accessible via
:::upper,lower,strip,split,replace,find,contains,starts_with,ends_with,chars,to_number.
- String literals can be defined using single or double quotes:
- Added Hash Tables (Dictionaries):
- Syntax:
{"key": "value", 1: 2, (3, 4): 5}. - Keys can be Numbers, Strings, Point2D, Point3D, or Boolean.
- Supported properties:
length,keys,values. - Supported methods:
has_key,remove,clear. - Indexing to read or write values:
h["key"] = 10.
- Syntax:
- Scanner rewritten using Regular Expressions: The scanner (
src/scanner.py) was completely rewritten using Python'sremodule for faster and more robust tokenization. - Attribute Assignment: You can now assign values to object properties directly. For example,
p::x = 5updates the X coordinate of Point2D. - Fixed Data Types: All mathematical functions now correctly return the internal
Numberdatatype instead of raw Python floats. Reserved variables (@pi,@e,@tau) are now correctly wrapped inNumber. - Added commands:
.reload|.restartfor program restarting
- Added support for accessing some internal functions or fields in points (with "::" operator)
- Added some missed functions from math module:
asin,acos,atan,atan2,asinh,acosh,atanh,copysign,degrees,radians,fabs,lcm,gcd,perm - Reserved functions and factorial function has been transported to builtins module
- Added always_show_last_error flag for more information in errors
- Added last_error for showing last error
- Added variables
- Added functions
- Added ternary operator
- Added Point2D and Point3D
- Added indexing support (currently only works on points)
- Added deletion operator
- Added help command
- Added basic arithmetics
- Added basic functions (reserved functions)
- Added basic variables (reserved variables)

