Giter Club home page Giter Club logo

bpl-compyler's Introduction

bpl

A compiler for Bob's Programming Language, a simple, C-like language. Implemented for the Spring 2014 CS331 course at Oberlin College.

Currently, this compiler generates GAS instructions, so it is only capable of running on Linux machines that are capable of compiling GAS instructions.

Written in Python 2.7.6.

Structure

The compiler consists of 4 modules:

  1. a lexical scanner that tokenizes text files
  2. a recursive descent parser that constructs abstract syntax trees from token streams
  3. a type checker that traverses abstract syntax trees to catch type errors
  4. a code generator that converts type-correct ASTs to GNU AS instructions.

The code is organized as follows:

.                           # top-level directory.  Run tests from here!
├── README.md
├── bplc                    # bpl compilation script. Use this to compile .bpl files!
├── setup.py                # installation script
└── bpl                     # bpl python package
    ├── __init__.py
    |
    ├── compiler.py         # compiler module, combines scanner, parser, type checker, and code generator
    |
    ├── scanner             # scanner package
    │   ├── __init__.py
    │   ├── scanner.py
    │   ├── token.py
    |
    |── parser              # parser package
    │   ├── __init__.py
    |   |── parser.py
    |   |── parsetree.py
    |
    |── type_checker        # type checker package
    │   ├── __init__.py
    |   |── type_checker.py
    |
    |── code_generator      # code generator package
    │   ├── __init__.py
    |   |── code_generator.py
    |
    └── test                # test package
        ├── __init__.py
        ├── example.bpl
        ├── scanner_test.py
        ├── parser_test.py
        ├── type_checker_test.py
        └── code_generator_test.py

(credit to @dan-f for this diagram and the structure of this README)

Installation

To install the bpl package and bplc compiler script, run the setup.py script from the top-level directory as follows:

$ python setup.py install

Running the Compiler

To run the compiler, run the bplc script as follows:

$ bplc <filename>

If you can't install bpl or simply don't want to, you can still run the bplc script from the top-level directory:

$ ./bplc <filename>

This will generate a binary output file named a.out. If you want to specify an output file name, you can use the "-o" flag as follows:

$ bplc <filename> -o <output_filename>

If you want to stop the compilation process at assembly generation, you can use the "-s" flag:

$ bplc <filename> -s

This will generate a GAS file named <filename>.s.

Tests

To test a module foo, run the following command from the top-level directory:

$ python -m bpl.test.foo_test <filename>

bpl-compyler's People

Contributors

oshoham avatar

Watchers

 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.