Upload
earl-gibbs
View
214
Download
0
Embed Size (px)
Citation preview
COMPILER OVERVIEW
Compiler Phases Syntactic Analysis (Lexing, Parsing) c = (a + b) * (a + b);
Compiler Phases Syntactic Analysis (Lexing, Parsing, AST) Semantic Analysis (Types, Scopes…)
Compiler Phases Syntactic Analysis (Lexing, Parsing, AST) Semantic Analysis (Types, Scopes…) Generate Intermediate Representation(IR)
t1 = a + bt2 = a + bt3 = t1 + t2c = t3
Compiler Phases Syntactic Analysis (Lexing, Parsing, AST) Semantic Analysis (Types, Scopes…) Generate Intermediate Representation(IR) Optimizationt1 = a + bt2 = a + bt3 = t1 + t2c = t3
t1 = a + bt3 = t1 + t1c = t3
Compiler Phases Syntactic Analysis (Lexing, Parsing, AST) Semantic Analysis (Types, Scopes…) Generate Intermediate Representation(IR) Optimization Code Generationt1 = a + bt3 = t1 + t1c = t3
lw $1, alb $2, badd $3, $1, $2add $4, $3, $3st $4, c
PHASE 1: SYNTACTIC ANALYSIS
Task 1: Lexing
#include <stdio.h>int main() {
printf(“Hello World!\n”);}
http://acm.sjtu.edu.cn/wiki/Compiler_2015:_Tokens
intmain(){printf(“Hello World!\n”);}
Task 2: Parseringintmain(){printf(“Hello World!\n”);}
http://acm.sjtu.edu.cn/wiki/Compiler_2015:_Grammar
Use context-free grammar to build Parse Tree(a.k.a. concrete syntax tree)Build Abstract Syntax Tree(a.k.a. syntax tree) by walking on Parse Tree
Tools & Grading Following tools are allowed:
lex / yacc / Quex / flex / bison re2c / lemon Jflex / CUP ANTLR (v4) Ragel
This phase will be manually judged in code review.
An Appetizer A toy compiler as a tutorial written by Xiao Jia Notice: you may not find IR phase in it. You will find it VERY IMPORTANT if you have no idea to start.
Description: http://acm.sjtu.edu.cn/wiki/Compiler_2015:_An_appetizer Source Code: https://github.com/stfairy/appetizer