Documentation
This commit is contained in:
parent
c1b05097e3
commit
67e2f3c0c1
17 changed files with 127 additions and 0 deletions
16
README.md
Normal file
16
README.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Compiler design homework assignment
|
||||
|
||||
The goal is to create a compiler from a subset of Java (JavaLi) to 32bit Intel assembly. The structure is the following:
|
||||
|
||||
* HW0: write an assembly program that reads numbers (not graded). [PDF](./docs/hw0.pdf)
|
||||
* HW1: implement a code generator that translates assignment statements to IA32. [PDF](./docs/hw1/hw1.pdf)
|
||||
* HW2: construct a lexer (lexical analyzer) and a parser (syntax analyzer) for the complete JavaLi programming language. [PDF](./docs/hw2/hw2.pdf)
|
||||
* HW3: develop a semantic analyzer. [PDF](./docs/hw3.pdf)
|
||||
* HW4: build a IA32 back-end for the compiler, a generator of IA32 for the complete JavaLi language. [PDF](./docs/hw4.pdf)
|
||||
* HWB: implement as many optimizations as possible (focusing on speed and correctness). [PDF](./docs/hw5.pdf)
|
||||
* HWC: review the code of other teams for HW1 and write up a report. [PDF](./docs/hwc.pdf)
|
||||
* HWD: review the code of other teams for HW4 and write up a report. [PDF](./docs/hwd.pdf)
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2018 Carlos Galindo, Levin Moser, teaching group of Compiler Design (ETH Zürich). All rights reserved.
|
BIN
docs/HW3-slides.pdf
Normal file
BIN
docs/HW3-slides.pdf
Normal file
Binary file not shown.
BIN
docs/HW4-slides.pdf
Normal file
BIN
docs/HW4-slides.pdf
Normal file
Binary file not shown.
BIN
docs/HW5-slides.pdf
Normal file
BIN
docs/HW5-slides.pdf
Normal file
Binary file not shown.
BIN
docs/hw0.pdf
Normal file
BIN
docs/hw0.pdf
Normal file
Binary file not shown.
BIN
docs/hw1/HW1-SS18.pdf
Normal file
BIN
docs/hw1/HW1-SS18.pdf
Normal file
Binary file not shown.
BIN
docs/hw1/HW1-SS18.pptx
Normal file
BIN
docs/hw1/HW1-SS18.pptx
Normal file
Binary file not shown.
49
docs/hw1/SimpleVisitor.java
Normal file
49
docs/hw1/SimpleVisitor.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
import java.lang.*;
|
||||
|
||||
abstract class TreeNode {
|
||||
public int key;
|
||||
public TreeNode leftchild;
|
||||
public TreeNode rightchild;
|
||||
|
||||
public TreeNode(int k, TreeNode left, TreeNode right) {
|
||||
key = k;
|
||||
leftchild = left;
|
||||
rightchild = right;
|
||||
}
|
||||
}
|
||||
|
||||
class BlueNode extends TreeNode {
|
||||
public BlueNode(int k, TreeNode left, TreeNode right) { super(k, left, right); }
|
||||
}
|
||||
|
||||
class GreenNode extends TreeNode {
|
||||
public GreenNode(int k, TreeNode left, TreeNode right) { super(k, left, right); }
|
||||
}
|
||||
|
||||
class Visitor {
|
||||
public void visit(TreeNode node) {
|
||||
System.out.print(node.key + ": ");
|
||||
|
||||
if (node instanceof BlueNode)
|
||||
System.out.println("Blue");
|
||||
else if (node instanceof GreenNode)
|
||||
System.out.println("Green");
|
||||
|
||||
if (node.leftchild != null) visit(node.leftchild);
|
||||
if (node.rightchild != null) visit(node.rightchild);
|
||||
}
|
||||
}
|
||||
|
||||
public class SimpleVisitor {
|
||||
public static void main(String [] args) {
|
||||
TreeNode root = new BlueNode(1,
|
||||
new GreenNode(21,
|
||||
new BlueNode(31, null, null),
|
||||
new GreenNode(32, null, null)),
|
||||
new GreenNode(22,
|
||||
new BlueNode(33, null, null),
|
||||
new GreenNode(34, null, null)));
|
||||
Visitor v = new Visitor();
|
||||
v.visit(root);
|
||||
}
|
||||
}
|
62
docs/hw1/VisitorPattern.java
Normal file
62
docs/hw1/VisitorPattern.java
Normal file
|
@ -0,0 +1,62 @@
|
|||
import java.lang.*;
|
||||
|
||||
abstract class TreeNode {
|
||||
public int key;
|
||||
public TreeNode leftchild;
|
||||
public TreeNode rightchild;
|
||||
|
||||
public TreeNode(int k, TreeNode left, TreeNode right) {
|
||||
key = k;
|
||||
leftchild = left;
|
||||
rightchild = right;
|
||||
}
|
||||
|
||||
public abstract void accept(Visitor v);
|
||||
}
|
||||
|
||||
class BlueNode extends TreeNode {
|
||||
public BlueNode(int k, TreeNode left, TreeNode right) { super(k, left, right); }
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.blueNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
class GreenNode extends TreeNode {
|
||||
public GreenNode(int k, TreeNode left, TreeNode right) { super(k, left, right); }
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.greenNode(this);
|
||||
}
|
||||
}
|
||||
|
||||
class Visitor {
|
||||
public void blueNode(BlueNode node) {
|
||||
System.out.print(node.key + ": ");
|
||||
System.out.println("Blue");
|
||||
|
||||
if (node.leftchild != null) node.leftchild.accept(this);
|
||||
if (node.rightchild != null) node.rightchild.accept(this);
|
||||
}
|
||||
|
||||
public void greenNode(GreenNode node) {
|
||||
System.out.print(node.key + ": ");
|
||||
System.out.println("Green");
|
||||
|
||||
if (node.leftchild != null) node.leftchild.accept(this);
|
||||
if (node.rightchild != null) node.rightchild.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class VisitorPattern {
|
||||
public static void main(String [] args) {
|
||||
TreeNode root = new BlueNode(1,
|
||||
new GreenNode(21,
|
||||
new BlueNode(31, null, null),
|
||||
new GreenNode(32, null, null)),
|
||||
new GreenNode(22,
|
||||
new BlueNode(33, null, null),
|
||||
new GreenNode(34, null, null)));
|
||||
root.accept(new Visitor());
|
||||
}
|
||||
}
|
BIN
docs/hw1/hw1.pdf
Normal file
BIN
docs/hw1/hw1.pdf
Normal file
Binary file not shown.
BIN
docs/hw2/HW2-slides.pdf
Normal file
BIN
docs/hw2/HW2-slides.pdf
Normal file
Binary file not shown.
BIN
docs/hw2/hw2.pdf
Normal file
BIN
docs/hw2/hw2.pdf
Normal file
Binary file not shown.
BIN
docs/hw3.pdf
Normal file
BIN
docs/hw3.pdf
Normal file
Binary file not shown.
BIN
docs/hw4.pdf
Normal file
BIN
docs/hw4.pdf
Normal file
Binary file not shown.
BIN
docs/hw5.pdf
Normal file
BIN
docs/hw5.pdf
Normal file
Binary file not shown.
BIN
docs/hwc.pdf
Normal file
BIN
docs/hwc.pdf
Normal file
Binary file not shown.
BIN
docs/hwd.pdf
Normal file
BIN
docs/hwd.pdf
Normal file
Binary file not shown.
Loading…
Reference in a new issue