GithubHelp home page GithubHelp logo

compilers-interpreters's Introduction

This is the final submission for the Spring 2013 Compilers & Interpreters course taught at JHU by Peter Froehlich. 

Throughout 8 total submissions I incrementally built a codebase for compiling/interpreting code written in a custom LL1 language called Simple to MIPS assembly. 

The original README is below. It focuses a little more on what was changed since the penultimate submission but should give some insight into how the codebase works.



Graham Smith
[email protected]

Assignment 8 Design=====================================

I went for the full 50 points in Language Options (implemented Local Variables,
Results, Parameters, Recursion, and 'Rest') and I went for 30 points in 
Implementation Options: I only added procedure functionality to the interpreter,
not the code generators. If no errors are found, it should total 80 points.

RUN CODE WITH -i ONLY, not -x or whatever.

I added full procedure functionality to the compiler stages up to and including
the interpretter. For the Scanner, the only change was the addition of 2 keywords:
PROCEDURE and RETURN.

For the parser, I had to add a procedure entry. I made 2 kinds for functions vs
procedures. each has a local scope and potentially instructions and a return
expression. The recursive descent parser works much as before. ProcDecl makes
an entry for any procedure while Call makes nodes for them. As with entries, there
are 2 kinds of nodes for functions/procedures. Nodes have a list of actuals (could
be empty) and a procedure entry (return expression and instrs can be reached through
the Node's entry). The LL1 conflicts are resolved by looking in the symbol table
to see whther or not the identifier is a procedure.

The interpretter now has 2 new nodes it can operate on, the 2 kinds of procedures.
both cases are very similar. In either case, the actuals are evaluated and temporarily
stored before we create a new Environment object for the local procedure scope. The global
scope is saved at all times, and the scope immediately outside the current one (recursion)
is temporarily saved. Boxes are made in the new environment and the previously evaluated
actuals are then stored in them either by value or reference as is appropriate (it's
a bit inaccurate to say the references are stored in the boxes. rather the references to boxes
replace the boxes in the target environment.) Then in either case the instructions are executed.
If after that the call is a function, the return expression is evaluated and put on the stack. 

compilers-interpreters's People

Contributors

gsmith98 avatar

Watchers

James Cloos avatar  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.