Code Monkey home page Code Monkey logo

p523-rust's Introduction

P523-Rust

P523 is a classic compiler course taught by R. Kent Dybvig. This repo implements the course using Rust, provides a framework to help you master P523.

You are expected to start from adventure, write your own code until you finally arrive at A15. It is not really scare as it sounds, since if you are able to pass the A1, you are able to pass A2, A3 and so on.

The P523 PDF files spreaded around the Internet is the main materials you have to read again and again. You can find them here. Asides, the reference codes serve as hints.

Adventure

Adventure is exactly same as a1. You are expected to master every line of code here.

main.rs             : 10
syntax.rs           : 56
parser.rs           : 181
compiler.rs         : 113
test.rs             : 132
----------------------------
total               : 492

Firstly, you should read the main.rs. It includes other modules, use a single interface compile to compile the program. The result is saved in "t.s".

Then, read the syntax.rs. There are two enums there. One is Expr, another is Asm. Your goal is to transform the Expr code into Asm code. The trait Display impl for Expr is for debug purpose, and for Asm is for generating assemble code.

And then you are ready to read parser.rs. Or you can just skip it if you don't care. You can copy mine into your folder. The parser simply transforms the string-form program into an abstract-syntax-tree Expr.

There are two classes defined in parser.rs, Scanner and Parser. Scanner travers through the string-form program and tokenizes it. A token consists of four parts: the string, the global index, line and column. The Scanner skips comment and newline. Parser parse the token stream using recursive-descent.

It is time to write your own Pass in compiler.rs. Since A1 is really simple, you are expected to understand the whole transformation. After that, you are really really ready for the P523 adventure.

Tests, you can understand them absolutely.

If you have any questions, please open a new issue at this repo.

By the way, yscheme.ss is a good reference.

Have a Good Time!

p523-rust's People

Contributors

moe-red avatar siriusdemon 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.