A high-performance mathematical expression engine written in Java 21, designed as a portfolio-grade project showcasing compiler-like architecture, symbolic computation, and clean API design.
math-tokenizer is more than a calculator — it's a modular expression engine that mimics how real interpreters and compilers work.
It transforms raw mathematical input into structured representations, enabling both:
- ⚡ Fast numeric evaluation
- 🌿 Symbolic differentiation (like a mini CAS)
This project demonstrates skills in:
- Language design & parsing
- Abstract Syntax Trees (AST)
- Algorithmic problem-solving
- Clean architecture & separation of concerns
- 🔢 Expression Evaluation – Supports +, -, *, /, ^ with full precedence handling
- 💾 Variables & State – Assign and reuse variables (e.g.,
x = 10) - 🌿 Symbolic Differentiation – Automatically compute derivatives
- 🧹 Expression Simplification – Reduce expressions using algebraic identities
- 🛡️ Validation Layer – Detects invalid states before execution
- 🧩 Extensible Functions – Easily add new math functions
The engine is built as a deterministic processing pipeline, where each stage has a single responsibility:
graph TD
A[Source String] --> B[Lexer]
B -->|Tokens| C[Parser]
C -->|AST| D[Validator]
D --> E[Evaluator]
D --> F[Differentiator]
F --> G[Simplifier]
G --> H[Printer]
E --> I[Numeric Result]
H --> J[Readable Expression]
- Lexer – Converts raw input into tokens
- Parser – Builds an Abstract Syntax Tree (AST)
- Validator – Ensures semantic correctness
- Evaluator – Computes numeric results
- Differentiator – Applies calculus rules
- Simplifier – Reduces expressions
- Printer – Converts AST back to readable form
statement -> assignment | expression
assignment -> IDENTIFIER "=" expression
expression -> additive
additive -> multiplicative ( ("+" | "-") multiplicative )*
multiplicative -> power ( ("*" | "/") power )*
power -> unary ( "^" power )?
unary -> "-" unary | primary
primary -> NUMBER | IDENTIFIER ( "(" argList ")" )? | "(" expression ")"src/main/java/pl/sky0x/tokenizer/
├── ast/ # AST nodes & operators
├── differentiation/ # Symbolic differentiation logic
├── evaluator/ # Numeric evaluation engine
├── functions/ # Built-in math functions
├── lexer/ # Tokenization
├── parser/ # Recursive-descent parser
├── pipeline/ # Orchestration layer
├── simplifier/ # Algebra simplification
└── validation/ # Error & semantic checks
Input: x = 5
x ^ 2 + 1
Output: 26.0
Input: x^2 + 2*x + 1
Output: 2*x + 2
- Product Rule
- Quotient Rule
- Power Rule
The engine applies these rules directly on the AST, ensuring correctness and extensibility.
- Java 21 – Core language
- Maven – Dependency management & build
- Recursive Descent Parsing – Custom parser implementation
- AST-based Architecture – Clean and scalable design
- JDK 21
- Maven 3.6+
git clone https://github.com/Skyy0x/math-tokenizer.git
cd math-tokenizer
mvn compile exec:java -Dexec.mainClass="pl.sky0x.tokenizer.Main"| Exception | Description |
|---|---|
| LexerException | Invalid tokens |
| ParserException | Syntax errors |
| ValidationException | Division by zero, undefined variables |
| FunctionException | Invalid function usage |
This project was built to demonstrate:
- Deep understanding of parsing and interpreters
- Ability to design scalable systems
- Writing clean, maintainable Java code
- Implementing non-trivial algorithms from scratch
Developed by sky0x