Skip to content

Interpreter of an OCaml-like language written in Haskell

Notifications You must be signed in to change notification settings

bartekryba/ocaml-interpreter

Repository files navigation

OCaml (like) Interpreter

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.cf file.
  • 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.

Language features and constructs

  • Two value types in expressions: int and bool
  • Arithmetic operations and comparisons
  • Conditional if expressions
  • 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 ;; where Exp is any expression, will print the evaluated value of that expression.

How to run

  1. Run make in the root directory:

    make
  2. 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).

About

Interpreter of an OCaml-like language written in Haskell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages