GithubHelp home page GithubHelp logo

yashton / compiler Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 588 KB

Python compiler

Makefile 0.33% Racket 5.68% Python 7.85% C++ 52.45% Component Pascal 11.13% Lex 3.57% LLVM 17.82% Shell 0.14% Scheme 1.04%

compiler's Introduction

Ashton Snelgrove
u0662114
[email protected]

Files:
Makefile - see below or run `make help` for info
ply/ - the PLY lexer/parser modules
pylex.py - source code implementing the lexer rules and execution
pyparse.rkt - racket source for derp parsing
python-ast.grm.sx - derp parsing productions
pytrans.rkt - HIR translator
pydesugar.rkt - LIR translator
pycps.rkt - CPS converter
readme - this file
tests/ - directory of test cases

Makefile options:
test - Run all test cases directly from Python source to cps
test/% - Translate tests/input/%.txt into cps
test-{lex, parse, trans, desugar, cps} - Run all cases for given conversion
test-{lex, parse, trans, desugar, cps}/% - Run specific case for conversion
diff/{lex, parse, trans, desugar, cps} diff all tests for conversion
test-rebuild - rebuild all test cases from files in tests/input
test-rebuild/{lex, parse, trans, desugar, cps} - rebuild for given conversion
test-create/% - create all tests for tests/input/%.txt
exec-{hir, lir, cps} - execute file on stdio
exec-{hir, lir, cps}/% - execute numbered test case
submit - create a compilers.tar.gz file for submission

The lexer is written for python 3.1.2, and was tested on a 64-bit Linux box. Should run fine on any machine running python 3. The lexer requires the PLY lexing module, which is included and referenced locally. Information about the PLY modules is at
http://www.dabeaz.com/ply/

Parser uses the derp tool, and the production matching is implemented in the python-ast.grm.sx file.

Translation is implemented in Racket and requires only the pytrans.rkt file.
Desugaring and CPS conversion also in Racket and only require their respective .rkt files.

Working:
Lexer has been updated to pass 90% of test cases.
Parser passes 100% of test cases.

Translator works for all test cases like the reference implementation except in two cases.

1. Assignment of indexed expressions, I include the right hand side in another let production, reducing the size of the final expression.

2. Global and local values are sometimes referenced in (define) and (let) statements out of order of occurrence. This is a side effect of the Racket (set) data type (see my post to the mailing list).

Desugar passes 100% of test cases.
In the reference implementation of (or ...) and (and ...) constructs, one desugars into a let form, while the other desugars in an if form. I've chosen to match the reference for ease of testing. Both transforms are implemented in the file and only need to be uncommented to use. (line 211)

CPS passes 100% of test cases.

Ashton Snelgrove
u0662114
[email protected]

compiler's People

Contributors

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