https://github.com/sirridemirtas/mathexpressionparser
Basic Mathematical Expression Lexer/Parser/Interpreter
https://github.com/sirridemirtas/mathexpressionparser
arithmetic-expression-parser compilers lexer math-interpreter parser
Last synced: 2 months ago
JSON representation
Basic Mathematical Expression Lexer/Parser/Interpreter
- Host: GitHub
- URL: https://github.com/sirridemirtas/mathexpressionparser
- Owner: sirridemirtas
- License: mit
- Created: 2024-11-28T17:14:43.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-11T11:46:52.000Z (6 months ago)
- Last Synced: 2025-02-07T10:32:45.762Z (4 months ago)
- Topics: arithmetic-expression-parser, compilers, lexer, math-interpreter, parser
- Language: TypeScript
- Homepage: https://mathexpressionparser.onrender.com
- Size: 283 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Math Expression Parser
This project is a Math Expression Parser that tokenizes, interprets and evaluates mathematical expressions using a clearly defined grammar for parsing complex mathematical operations.

The parser first breaks down input expressions into tokens (like numbers, operators, functions), then uses these tokens to build an Abstract Syntax Tree (AST) which is finally evaluated to produce the result.
### Features
The grammar below defines the rules for parsing mathematical expressions. It supports various mathematical operations and follows standard operator precedence rules:
- Basic arithmetic operations (+, -, \*, /)
- Implicit multiplication (like 2(3) or 2sin(45))
- Exponentiation (^)
- Factorial operations (!)
- Trigonometric functions (sin, cos)
- Parentheses for grouping
- Integer and decimal numbers
- Negative numbers### Mathematical Expression Grammar in Extended Backus-Naur Form
```ebnf
G = {Σ, T, V, P, S}
V = {expression, term, power, factorial, function, primary, number, digit} ⊆ Σ
T = {sin, cos, +, -, *, /, ^, !, (, ), ., 0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ⊆ Σ
Σ = T ∪ V
S = expression
P:
::= (("+" | "-") )*
::= (("*" | "/" | ε) )*
::= ("^" )*
::= ("!")*
::= "sin" "(" ")"
| "cos" "(" ")"
|
::=
| "(" ")"
::= ["-"]{}["."{}]
::= "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"
```Each rule in the grammar serves a specific purpose:
| Rule | Description |
| -------------- | ------------------------------------------------------------ |
| `` | Top-level rule for handling addition and subtraction |
| `` | Handles multiplication, division and implicit multiplication |
| `` | Manages exponentiation operations |
| `` | Processes factorial operations |
| `` | Handles trigonometric functions and primary expressions |
| `` | Manages numbers and parenthesized expressions |
| `` | Defines number format (including decimals) |
| `` | Specifies valid numerical digits |### Installation and Usage
To run the project, follow these steps:
1. **Clone Project**:
```bash
git clone https://github.com/sirridemirtas/MathExpressionParser.git
```
2. **Navigate to the project directory**:
```bash
cd MathExpressionParser
```
3. **Install the dependencies**:
```bash
npm install
```
4. **Start the development server**:
```bash
npm run dev
```
5. **Open your browser and navigate to**:
```bash
http://localhost:5173
```