Giter Club home page Giter Club logo

simcom's Introduction

simcom - A compiler and interpreter for the SIMPLE language

Author: Anthony Burzillo

A product of Peter Fröhlich's Spring 2013 Compilers and Interpreters class at Johns Hopkins.


Language

In our implementation, the SIMPLE language is a statically typed, imperative language with a single basic data type INTEGER as well as two constructive data types ARRAY and RECORD.

Check out the the grammar for the language, some of the tests, or the class website for more information about the SIMPLE language.

Executables

Consider the iffy program in tests/iffy.sim which writes 0 to the screen:

PROGRAM iffy;
  VAR x, y, z : INTEGER;
BEGIN
  x := 6;
  IF x MOD 200 >= 56 THEN
    WRITE 1
  ELSE
    WRITE 0
  END 
END iffy.

sc - the SIMPLE compiler

Print out all the tokens in a program:

$ ./sc -s tests/iffy.sim
PROGRAM@1
identifier<iffy>@1
;@1
VAR@2
identifier<x>@2
,@2
identifier<y>@2
,@2
identifier<z>@2
:@2
identifier<INTEGER>@2
...
WRITE@8
integer<0>@8
END@9
END@10
identifier<iffy>@10
.@10

Create a graphical representation of the symbol table (with dot installed):

$ ./sc -t tests/iffy.sim | dot -T jpeg > table.jpg

symbol table

Create a graphical representation of the syntax tree (with dot installed):

$ ./sc -a tests/iffy.sim | dot -T jpeg > tree.jpg

syntax tree

Run the program in with the interpreter:

$ ./sc -i tests/iffy.sim
0

Create lazy AMD64 assembly code and run:

$ ./sc -l tests/iffy.sim > iffy.s
$ gcc -o iffy iffy.s
$ ./iffy
0

Create intermediate code:

$ ./sc -m tests/iffy.sim
Binary(mov): $6 -> !0
Assign: !0 -> x
Binary(mov): $200 -> !1
Division: x / !1
Binary(mov): $56 -> !2
Compare: >%rdx !2
Conditional Jump: >= goto Label: 4540158288
Binary(mov): $1 -> !3
Write: !3
Unconditional Jump: goto Label: 4540158416
Label: 4540158288
Binary(mov): $0 -> !4
Write: !4
Label: 4540158416

Create the flow graph block representation of the program (with dot installed):

$ ./sc -f tests/iffy.sim | dot -T jpeg > flow_graph.jpg

flow_graph

test

This program runs all of the executables in tests/ and reports on any that fail to run. test can be given any option and that option will be run on each executable.

Run the testing suite:

$ ./test
$$  Test 'args' was successful.
$$  Test 'arrassi' was successful.
$$  Test 'read_in' was successful.
...
$$  Test 't2' was successful.
+++++++++++++++++++++++++++++++++++++++++++
27 tests were run with 27 succesful, 0 failed.

simcom's People

Stargazers

Anna Burzillo avatar

Watchers

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