Giter VIP home page Giter VIP logo

pascal0-compiler's Introduction

Pascal0-to-Assembly Compiler

Compiles Pascal0 to 64-bit NASM assembly code. Started as my final project for McMaster course 4TB3: Syntax-based Tools and Compilers. I've since expanded upon it with a full test suite, refactoring, optimizations, and and usability improvements.

Pascal0

A simplified and fully compatible subset of Pascal (i.e., works with any regular Pascal compiler), created by Dr. Emil Sekerinski for McMaster 4TB3.

Usage

Compile a Pascal0 source file to assembly with

python3 compile.py /path/to/my_p0_code.p [options]

There are example Pascal0 programs under test/test_programs.

Requirements

Requires Python 3+ to compile to assembly. 64-bit Linux with gcc and nasm is required to compile an executable file (not required by default).

Compiler Options

-h or --help: show the below option flags

-a or --asm: directory to save generated assembly file (default: current directory)

-e or --exec : directory to save the executable (default: none)

Testing

Testing is split into parsing/compiler-time error catching as well as behavior-driven testing of compiled executables. The latter is done by compiling the programs in test/test_programs, which cover all of the structures of the Pascal0 grammar and check for specific behaviors (e.g., passing arguments to procedures, local and global variable scope, code optimizations).

The test suite can be run by navigating to the test directory and running python3 test.py. I suggest using Coverage to verify test completeness. As is, tests cover 100% of code in the parser and code generator.

Further Reading

To learn more about the code generated, calling conventions, register usage, etc., you can view the original documentation here.

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.