Nexus Math Engine is a command-line (CLI) mathematical expression interpreter developed in Java. It transforms character strings into recursive syntax trees for immediate evaluation.
The project follows SOLID principles and uses several design patterns to ensure component decoupling:
- Composite & Interpreter: Models equations as trees via the
INoeudandIExpressioninterfaces. - Chain of Responsibility: Manages operator precedence (+, -, *, /) via
ChaineOperateursandOperateurHandler. - Command Pattern: Encapsulates user actions in classes implementing
ICommande. - Dependency Injection: Assembles components in the
Mainclass for maximum decoupling.
- Expression evaluation: Supports standard arithmetic operators and parentheses.
- Variable management: Assign values to variables for use in subsequent calculations.
- Constant packages: Load immutable constants from external text files (e.g.,
pi,g). - Persistent history: Stores the last 20 expressions in
historique.txt, persisting after closing. - Syntax analysis:
analysecommand counts operators, numbers, variables, and constants used.
- Variables: Variable names must be at least one character, not start with a digit, and contain no spaces.
- Constants: Visually distinct from variables (prefix
[const]) and immutable after loading.
- Compile:
javac -d bin src/**/*.java - Run:
java -cp bin Main - Key commands:
calculer <expr>: Direct calculation.var <name>=<val>: Assignment.analyse <expr>: Expression statistics.histoire: Show history.quitter: Exit the program.
- History rotation: The oldest expression is automatically deleted once the 20-expression limit is reached.
- Constant precedence: If there is a name conflict in loaded files, the last value read is kept.