P523 is a classic compiler course taught by R. Kent Dybvig.

Overview

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!

You might also like...
ArbOS operating system, to run at Layer 2 on Arbitrum chains. Also a compiler for Mini, the language in which ArbOS is written.

ArbOS and Mini compiler ArbOS is the "operating system" that runs at Layer 2 on an Arbitrum chain, to manage the chain's operation, maintain security,

The Rust Compiler Collection is a collection of compilers for various languages, written with The Rust Programming Language.

rcc The Rust Compiler Collection is a collection of compilers for various languages, written with The Rust Programming Language. Compilers Language Co

A rust version of "the super tiny compiler"

The (Rust) super tiny compiler This project is a rust version of the super tiny compiler (the original one (JS) was created by Jamie Kyle). The output

Rust lib for fetching official protoc (Protocol Buffer compiler) releases

protoc-fetcher Rust library for fetching official Protocol Buffer compiler (protoc) releases, pegged to a specific version. protoc-fetcher downloads a

A additional Rust compiler pass to detect memory safe bugs of Rust programs.

SafeDrop A additional Rust compiler pass to detect memory safe bugs of Rust programs. SafeDrop performs path-sensitive and field-sensitive inter-proce

Harvest Moon: (More) Friends of Mineral Town event script compiler

mary This is a script compiler for Harvest Moon: Friends of Mineral Town and Harvest Moon: More Friends of Mineral Town for the GBA. The end goal is f

The compiler for Gera, a statically typed and garbage collected programming language.

Gera The compiler for Gera, a satically typed and garbage collected programming language. Currently WIP (Work in progress). Progress This is a rough o

C-like language compiler, the final project of ZJU Compiler Principle course
C-like language compiler, the final project of ZJU Compiler Principle course

cc99 cc99 (not cc98.org) is a C-like language compiler, which is the final project of ZJU Compiler Principle course. It supports many of the C99 langu

Rust Programming Fundamentals - one course to rule them all, one course to find them...

Ultimate Rust Crash Course This is the companion repository for the Ultimate Rust Crash Course published online, presented live at O'Reilly virtual ev

A tool & library to help you with the compiler course.

Compiler Course Helper Support: eliminate left recursion (require grammar with no cycles or ϵ-production) calculate nullable, first sets, follow, sets

This is a simple implementation of the classic snake game in rust
This is a simple implementation of the classic snake game in rust

My snake game Looks like this. This is with Roboto Mono Nerd Font. If you use a different font it may look different or distorted. Install rust In ord

The classic tetris game written in Rust using ncurses
The classic tetris game written in Rust using ncurses

tetris.rs This is the classic tetris game I wrote to have a bit of fun with Rust. Installation and playing cargo install --

fcp is a significantly faster alternative to the classic Unix cp(1) command
fcp is a significantly faster alternative to the classic Unix cp(1) command

A significantly faster alternative to the classic Unix cp(1) command, copying large files and directories in a fraction of the time.

Classic snake in RUST!
Classic snake in RUST!

rusty_snake Classic snake game built in Rust using Piston Window. Running the game Requirements Rust Cargo Steps to run git clone https://github.com/c

👾 The classic Space Invaders game made in rust!
👾 The classic Space Invaders game made in rust!

👾 Invaders The classic space-shooter game now in your terminal! And the good part: made in Rust! ❕ This game was made during the course Ultimate Rust

An extremely ridiculous weekend project that tries to do user-mode emulation of PowerPC executables for classic Mac OS

An extremely ridiculous weekend project that tries to do user-mode emulation of PowerPC executables for classic Mac OS, to run the CodeWarrior C++ compiler without faffing about with SheepShaver or QEMU.

Watch classic spongebob from the terminal
Watch classic spongebob from the terminal

Watch classic spongebob from the terminal! Remake of the original spongbob cli written in py by TrakBan

A game inspired by the classic atari game: demon attack
A game inspired by the classic atari game: demon attack

rusty_demon_attack A game inspired by the classic atari game: demon attack You can play the game in the web!

Owner
Sirius Demon
I like Lisp but Lisp like (sea)
Sirius Demon
A tool & library to help you with the compiler course.

Compiler Course Helper Support: eliminate left recursion (require grammar with no cycles or ϵ-production) calculate nullable, first sets, follow, sets

水夕 4 May 2, 2022
Watch classic spongebob from the terminal

Watch classic spongebob from the terminal! Remake of the original spongbob cli written in py by TrakBan

Ali™ 14 Dec 6, 2022
The best Intermediate Rust course out there!

Ultimate Rust 2: Intermediate Concepts This is the companion repository for the Ultimate Rust 2: Intermediate Concepts (the followup to the popular Ul

Nathan Stocks 155 Jan 4, 2023
Free Rust 🦀 course in English 🇬🇧

Learn Rust ?? Free Rust ?? course in English ???? This course was inspired by Dcode Before starting to learn a programming language, you need to under

Skwal 10 Jul 5, 2022
Rust Crash Course, by BPB Publications

Rust Crash Course Grasp the fundamentals of programming in Rust and put your knowledge to use. This is the repository for Rust Crash Course ,published

BPB Online 9 Nov 26, 2022
This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust to everyone.

Comprehensive Rust ?? This repository has the source code for Comprehensive Rust ?? , a four day Rust course developed by the Android team. The course

Google 5.2k Jan 3, 2023
Course Material for Ardan Labs - Ultimate Rust: Foundations

Ultimate Rust 1: Foundations Presented by Ardan Labs, Ultima Rust: Foundations gives you a "zero to hero" class to get you started with Rust. You'll l

Herbert 9 Mar 8, 2023
Take your first step in writing a compiler. Implemented in Rust.

first-step-rust Take your first step in writing a compiler, using Rust. Building from Source Make sure the Rust toolchain is installed on your compute

PKU Compiler Course 13 Aug 28, 2022
Bril: A Compiler Intermediate Representation for Learning

Bril: A Compiler Intermediate Representation for Learning Bril (the Big Red Intermediate Language) is a compiler IR made for teaching CS 6120, a grad

Lesley Lai 0 Dec 5, 2022
The first cesil transpiler/compiler in 50 years!

CesilC CESIL, or Computer Education in Schools Instruction Language, is a programming language designed to introduce pupils in British secondary schoo

null 5 Aug 6, 2022