GithubHelp home page GithubHelp logo

plp1-basic-interpreter's Introduction

Review Assignment Due Date

CS 4850 PLp1 Rudimentary Interpreter Project

Due Date: Friday, March 29, 2024 @ 11:59pm.

Purpose

The purpose of this project is to gain experience in giving meaning to a programming language by interpreting expressions in PLp1.

Project Summary

In this project, you will need to implement an interpreter of the abstract syntax that you generated in Project 1. For full credit, you must use the visitor pattern we developed in class. Specifically, your interpreter must be able to

  1. Evaluate any abstract syntax generated for

    1. List, string, integer, floating-point and boolean constants,
    2. Arithmetic, relational and boolean expressions,
    3. If expressions, and
    4. Switch expressions
  2. Perform dynamic type checking according to the rules in the language definition document.

  3. Evaluate function invocations for the PLp1 language-defined function listed in Table~1 in the language definition document. You must catch any error that could occur in a language defined function and report a suitable error message. Specifically, no Java exception or error produced by performing a language defined function should be left uncaught. \end{enumerate}

Abstract Syntax Tree

I have provided my AST generator in the shell project on GitHub. I have used ANTLR v4 as a parser and scanner. The code for the AST is in src/ast. The ANTLR parser and scanner specification is in src/parser/PLp1.g4. All other files in src/parser are automatically generated by the ANTLR system.

Walking the AST involves the visitor pattern. The interface for a visitor pattern is in src/visitor/Visitor.java. An example implementation of that interface is in src/visitor/SourceVisitor.java. That visitor converts the AST back into its source text representation.

The table below gives the syntax and the AST representation for that syntax.

Non-terminal AST
$\mathbf{program}$ $P \rightarrow $\textbf{prog} ; (F ; | ; E )^+$
$\mathbf{functionDef}$ $ F \rightarrow $\mathbf{func} ; P_l ; E_l $
$\mathbf{paramList}$ $P_l \rightarrow I^*$
$\mathbf{expressionList}$ $E_l \rightarrow E^+$
$\mathbf{Expression}$ $E \rightarrow $\mathbf{mult} ; E ; E$
$\quad | \quad \mathbf{$div} ; E ; E$
$\quad | \quad \mathbf{$plus} ; E ; E$
$\quad | \quad \mathbf{$minus} ; E ; E$
$\quad | \quad \mathbf{$eq} ; E ; E$
$\quad | \quad \mathbf{$neq} ; E ; E$
$\quad | \quad \mathbf{$lt} ; E ; E$
$\quad | \quad \mathbf{$le} ; E ; E$
$\quad | \quad \mathbf{$gt} ; E ; E$
$\quad | \quad \mathbf{$ge} ; E ; E$
$\quad | \quad \mathbf{$or} ; E ; E$
$\quad | \quad \mathbf{$and} ; E ; E$
$\quad | \quad \mathbf{$assign} ; I ; E$
$\quad | \quad \mathbf{$if} ; E ; E ; E$
$\quad | \quad \mathbf{$call} ; E ; E_l$
$\quad | \quad \mathbf{$switch} ; (E ; E_l)^+$
$\quad | \quad \mathbf{$lambda} ; P_l ; E_l $
$\quad | \quad \mathbf{$let} ; (I E)^* ; E_l $
$\quad | \quad \mathbf{$not} ; E$
$\quad | \quad I ; | ; C$
$\langle \mathbf{ID} \rangle$ $I \rightarrow $\mathbf{id} ; @str$
$\langle \mathbf{constantExp} \rangle$ $C \rightarrow $\mathbf{int} ; @num$
$\quad | ; $\mathbf{float} ; @num$
$\quad | ; $\mathbf{list} ; C^*$
$\quad | ; $\mathbf{str} ; @str$

What to do

Write a visitor using the supplied interface to walk the AST and interpreter it for the subset of syntax listed above. You will also need to implement a base environment. I have provided a partial implementation in src/util.

Submission

Write all of your code in Java. Submit it via git.

plp1-basic-interpreter's People

Contributors

stevenmcarr avatar rlarabel avatar github-classroom[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.