Giter VIP home page Giter VIP logo

cool-stack-machine-interpreter's Introduction

Stack Machine with Cool

Cool means Classrom Object-Oriented Language and it is a language used in many Computer Science Compilers' courses to teach how to build a compiler from scratch. The language was designed by Alexander Aiken from Stanford University. In his own page he talks about Cool:

Cool is a small language designed for use in an undergraduate compiler course project. While small enough for a one term project, Cool still has many of the features of modern programming languages, including objects, automatic memory management, and strong static typing. Cool is built entirely on public domain tools; it generates code for a MIPS simulator, spim . Thus, the project should port easily to other platforms. The project has been used for teaching compilers at many institutions and the software is stable.

This program was the first assignment for my Compilers' course at UFMG: to build a simples stack machine using Cool. The operations are the following:

Command Outcome
int Push the number typed
+ Push the '+' signal
s Push the 's' command
e Evaluate the stack's head
d Prints the stack
x Finishes the program
  • The command e will evaluate the top of the stack. That means:
    • If the top is '+', it will adds the two subsequent elements, pop them, and push the result into the stack;
    • If the top is 's', it will remove the 's' itself and switch the two following elements;
    • If the top is a number or the stack is empty, nothings happens.

This program has some assumptions:

  • Only valid commands are entered by the user
  • The numbers are all positive

cool-stack-machine-interpreter's People

Stargazers

 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.