An interpreter for a functional programming language based on OCaml syntax.
The solution currently consists of 3 main modules:
- Parser - generated by the BNFC tool based on the
parser.cffile. - TypeChecker - enables static analysis of the program.
- Evaluator - executes the program after type consistency has been verified by the TypeChecker.
...along with a small PrettyPrinter module responsible for properly formatting output messages.
- Two value types in expressions:
intandbool - Arithmetic operations and comparisons
- Conditional
ifexpressions - Multi-argument functions and recursion
- Anonymous functions (lambdas), partial application, higher-order functions, and closures
- Static identifier binding (lexical scoping)
- Lists of any type, including lists of lists, lists of functions, and arbitrarily nested lists
- Pattern matching for values and lists (
[],x :: xs) - Syntactic sugar for defining list constants, e.g.,
[1, 2, 3] - General polymorphic and recursive algebraic data types (ADTs)
- Static typing
- Runtime error handling (thanks to static type checking, only two runtime errors can occur: division by zero and non-exhaustive pattern matching)
Note: A statement of the form
Exp ;;whereExpis any expression, will print the evaluated value of that expression.
-
Run
makein the root directory:make
-
Run the interpreter on a specific file:
./Interpreter path_to_file
Running ./Interpreter without any arguments allows you to enter code directly from the console (REPL mode).