Welcome to the repository for a quarter-long project from CS 131: Programming Languages at UCLA! This project involves building a series of interpreters for the Brewin language, culminating in a final interpreter for a custom object-oriented language called Brewin#.
Over the course of the quarter, this project was built in four phases, with each version of the interpreter adding significant new features to the language.
- Brewin v1 (Project 1): A basic interpreter that supports variable assignments, the
print()andinputi()built-in functions, and simple integer arithmetic. - Brewin v2 (Project 2): Adds support for user-defined functions with parameters,
if/elsestatements,whileloops, areturnstatement, and boolean types. This version implements dynamic scoping. - Brewin++ (Project 3): Enhances the language with first-class functions (storing functions in variables, passing them as arguments, etc.), lambda functions with closures, pass-by-reference and pass-by-value parameter passing, and limited type coercion.
- Brewin# (Project 4): Introduces object-oriented programming features, including object instantiation (
@), member fields and methods, and prototypal inheritance.
This project is written in Python 3.11. The interpreter works by first using a provided parser (brewparse.py and brewlex.py) to generate an Abstract Syntax Tree (AST) from the Brewin source code. The interpreter then traverses and evaluates the nodes of the AST to execute the program.
interpreterv1.pytointerpreterv4.py: Python source files for each version of the interpreter.intbase.py: The base class for the interpreter, providing methods for I/O and error handling.brewparse.py&brewlex.py: The parser modules provided by the course staff.element.py: Defines theElementclass used to represent nodes in the AST.test_cases.txt: A file containing a set of test cases used to validate the interpreter.
The base code for this project, including the interpreter base class and parser modules, was provided by Carey Nachenberg and the CS 131 teaching assistants. The interpreter logic was developed as part of a student project.
This is a personal, educational repository and is not governed by an open-source license.