Skip to content

aseseri/CS131-Brewer-Interpreter

Repository files navigation

CS 131: Brewin Interpreter Project

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#.

Project Overview

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() and inputi() built-in functions, and simple integer arithmetic.
  • Brewin v2 (Project 2): Adds support for user-defined functions with parameters, if/else statements, while loops, a return statement, 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.

Technical Details

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.

Repository Contents

  • interpreterv1.py to interpreterv4.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 the Element class used to represent nodes in the AST.
  • test_cases.txt: A file containing a set of test cases used to validate the interpreter.

Attribution

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.

Note

This is a personal, educational repository and is not governed by an open-source license.

About

Created an interpreter for the Brewin programming language from the CS 131 course, implementing features from basic arithmetic to advanced concepts like first-class functions, closures, and prototypal inheritance.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages