11
COMPILER OVERVIEW

COMPILER OVERVIEW. Compiler Phases Syntactic Analysis (Lexing, Parsing) c = (a + b) * (a + b);

Embed Size (px)

Citation preview

Page 1: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

COMPILER OVERVIEW

Page 2: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

Compiler Phases Syntactic Analysis (Lexing, Parsing) c = (a + b) * (a + b);

Page 3: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

Compiler Phases Syntactic Analysis (Lexing, Parsing, AST) Semantic Analysis (Types, Scopes…)

Page 4: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

Compiler Phases Syntactic Analysis (Lexing, Parsing, AST) Semantic Analysis (Types, Scopes…) Generate Intermediate Representation(IR)

t1 = a + bt2 = a + bt3 = t1 + t2c = t3

Page 5: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

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

Page 6: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

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

Page 7: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

PHASE 1: SYNTACTIC ANALYSIS

Page 8: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

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”);}

Page 9: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

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

Page 10: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

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.

Page 11: COMPILER OVERVIEW. Compiler Phases  Syntactic Analysis (Lexing, Parsing)  c = (a + b) * (a + b);

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