This is an interpreter for the language Brewin made for the class CS 131 at UCLA in the Fall 2024 Quarter taught by Carey Nachenberg!
The parser and lexer are provided by the course organizers and can be found here Brewin Interpreter Starter.
The various specs are linked here:
Essentially, v1 supports basic code execution in the main function with dynamically typed variables and no conditionals. There are simple built-in functions like inputi for inputing numbers and printing as well as a few operators.
v2 supports function definitions and control flow which includes if statements and for statements as well as returns. This brings about proper scoping within functions and code blocks as well as implementing requisite mechanisms for argument passing and managing scopes.
v3 is for Brewin++, a departure from the dynamically-typed versions that come previous as it enforces static typing of variables, arguments, and return types. Additionally, there are user-defined types in the form of structs which use pass-by-reference semantics. Additionally there are coercions for integers and booleans. There are void functions and seperately NIL values for structs and different handling for equality between structs of different types and NIL values.
v4 is for Brewin#, another spin-off of Brewin which supports need semantics and lazy evaluation as found in languages like Haskell. This means that expressions are not evaluated until they are necessarily used and then cached for further use. This requires mechanisms for snapshotting the environment and passing storing references to the cached versions of inner expressions in nested expressions. Another major feature is exception handling with the inclusion of try-catch handling of exceptions. Short-circuiting is also implemented to avoid unnecessary evaluations in AND and OR expressions.
Each version of the interpreter can be found within the corresponding interpretervN.py file and can be run with the provided main function below it to execute a given Brewin program.
A provided autograder can be found here which acts as a harness to execute a collection of tests for each version of the interpreter. The test cases can be viewed in plaintext alongside their intended outputs.
Again, credits for the interpreter base and parser and lexer as well as the autograder goes to course organizers!