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:
-
Lexing: extracting tokens
-
Parsing: checking program syntax
- AST generation
- Semantic analysis
-
Symbol resolution
-
Type checking
- Program evaluation: executes the program
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.
Ocaml/Opam: Get Up and Running With OCaml · OCaml Tutorials
Dune Build: Install Dune
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.
You can build and execute the project at once using dune.
dune exec albatrossin <program.albatross>
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.