Giter VIP home page Giter VIP logo

nice9's Introduction

Nice9 Compiler

Compiler written in Ruby that compiles a C-like language named Nice9 to TM (Tiny Machine) code. This was written as part of a compiler construction course I took but I have modified the grammer to discourage its reuse by future students.

Tiny Machine is a assembly-like language written by Kenneth Louden and modified by Robert Heckendorn for teaching compiler construction. To run TM code you must compile the included C program.

Nice9 requires two Ruby files to run:

  1. nice9.rex.rb - This is the scanner, generated partially from Ruby Rex but modified heavily. Should be used as is.
  2. nice9.tab.rb - Generated from the nice9.racc grammar file using Ruby Racc...

Racc takes a Yacc-like grammer file and generates a Ruby parser from it. To build nice9.tab.rb from the grammar file, do the following:

racc nice9.racc

A shell script is provided to run the parser from the command line. Just execute 'nice9'. Example:

nice9 output.tm < input.9

Nice9 Testing

  1. Several usable sample programs (author unknown) included in the samples directory
  2. Run ./test.py (requires Python) to execute an extensive test suite. Original test suite provided by Michael Wright (https://github.com/mdwrigh2).

TM Optimizer

Use the tmo program to optimize the TM code output from the compjiler. Performs full control-flow and data-flow (live variable) analysis. The following optimizations are supported:

  1. Dead/unreachable code elimination
  2. Common subexpression elimination
  3. Copy propagation
  4. Constant propagation
  5. Jump chaining

Jumps based on dynamic registers or values loaded from memory, as commonly used for procedures, are not supported and will cause Tmo to exit immediately.

The programs bsort.tm and sieve.tm (use tm "-a 20000000" optiomake sure to un) generated from the Nice9 samples demonstrate many optimizations with high instruction counts.

Tmo requires two Ruby files to run:

  1. tmo.rex.rb - This is the scanner, generated partially from Ruby Rex but modified heavily. Should be used as is.
  2. tmo.tab.rb - Generated from the tmo.racc grammar file using Ruby Racc...

Racc takes a Yacc-like grammer file and generates a Ruby parser from it. To build tmo.tab.rb from the grammar file, do the following:

racc tmo.racc

A shell script is provided to run the parser from the command line. Just execute 'tmo'. Example:

tmo bsort_optimized.tm < bsort.tm

Software Requirements

  1. Ruby version 1.8.7 or newer
  2. Ruby racc (1.4.6)
  3. Tiny Machine - included, original version at http://marvin.cs.uidaho.edu/~heckendo/CS445/tm.c

nice9's People

Stargazers

 avatar

Watchers

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