Similar to the python interpretor, solves arithmetic, trigonometric and logarithmic expressions; stores and process variables and functions.
Functionalities:
- Users can enter expressions and get the evaluated result.
- Users can assign, save and update the value of a variable.
- Users can define and call functions.
- Users can import a file containing expressions and declarations, and process its contents
Major Classes and Interfaces :-
- Evaluable: This interface is implemented by all operators, variables, functions and numeric constants. It contains an evaluate method which returns a double value after evaluation.
- Evaluator: Tokenizes the expression string and creates an expression tree to evaluate.
- HashTable: Implements a hash table which maps variables to their corresponding values and functions to their corresponding expressions.
Some important functions in the code:
- makeTree() : Scans a tokenized linked list, categorizes the tokens into variable, function, operator or numeric value to construct an expression tree and returns an evaluable object as the root of the tree.
- evaluate() : This function is implemented by all evaluable classes like variable, function, numeric, and all operators. It evaluates the node and returns double value.
- generateHash() : It returns a unique hash key for a variable using quadratic probing.4. tokenize() : Accepts expression string entered by users and creates tokens based on operators, numeric values, variables, etc. Returns a linked list of tokens.
Other Features of the project:-
- Balanced parentheses are added to user input by addParanthesis() function to facilitate easy evaluation.
- Syntax errors are handled using the exception handling feature of Java.
- Other handled exceptions: Function redefinition, Function/Variable/File not found, Use of unknown symbols.
- User Interface: Prompts user to enter input using specific keywords like Func, import, exit.
***Run UserInterface.java to test the working***