yashkurkure / albatross_interpreter

An interpreter for the albatross programming language developed in CS473: Compiler Design - Fall 22 and CS476: Programming Language Design - Fall 22 at UIC.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Albatross Interpreter

Language spec

An interpreter for the albatross programming language developed in CS473: Compiler Design - Fall 22 and CS476: Programming Language Design - Fall 22 at UIC.

The interpreter is written using OCaml that uses sedlex (Lexer) and Menhir (LR(1) parser) opam packages.

The interpreter works in 4 stages:

  1. Lexing: extracting tokens

  2. Parsing: checking program syntax

  • AST generation
  1. Semantic analysis
  • Symbol resolution

  • Type checking

  1. Program evaluation: executes the program

Usage

Use the albatrossin.exe binary to execute programs.

./albatross.exe <program.albatross>

Try executing the programs in ./examples.

# factorial.albatross prints the factorials of 1-15
./albatrossin.exe ./examples/factorial.albatross


# pattern.albatross prints a * pattern
./albatrossin.exe ./examples/pattern.albatross

Note that the dune build system adds the .exe extension to the executable to maintain consistency accross Windows, Linux and MacOS. The extension .exe is meaningless to Linux and MacOS, but Windows requires it for executables.

Build Executable 🏗️

Prerequisites

Ocaml/Opam: Get Up and Running With OCaml · OCaml Tutorials

Dune Build: Install Dune

Build

Clone the project and cd into the project root:

clone git@github.com:yashkurkure/albatross_interpreter.git
cd ./albatross_interpreter

Build using Opam:

# Install project dependencies
opam install . --deps-only --with-test

# Build the project
opam exec -- dune build

Alternaitvely, build using Dune:

# Install project dependencies and build project
dune build

Building the project will create albatrossin.exe in the root of the project.

Executing using Dune 🏃

You can build and execute the project at once using dune.

dune exec albatrossin <program.albatross>

Testing

You can run test scipts for testing the parser, semantic analysis and execution stages.

The branches of this repository lexer_and_parser, semantic_analysis and master are symbolic to the stages this interpreter was developed in (master branch has everything till the execution stage).

Each branch has a runtests.sh script which executes the programs in the ./tests and compares the output with the expected output.

This repository also has github actions configured to run on push the runtests.sh script and check if all tests pass.

About

An interpreter for the albatross programming language developed in CS473: Compiler Design - Fall 22 and CS476: Programming Language Design - Fall 22 at UIC.

License:MIT License


Languages

Language:OCaml 97.7%Language:Standard ML 1.5%Language:Makefile 0.8%