compiler overview. compiler phases syntactic analysis (lexing, parsing) c = (a + b) * (a + b);
TRANSCRIPT
![Page 1: COMPILER OVERVIEW. Compiler Phases Syntactic Analysis (Lexing, Parsing) c = (a + b) * (a + b);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/1.jpg)
COMPILER OVERVIEW
![Page 2: COMPILER OVERVIEW. Compiler Phases Syntactic Analysis (Lexing, Parsing) c = (a + b) * (a + b);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/2.jpg)
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);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/3.jpg)
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);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/4.jpg)
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);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/5.jpg)
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);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/6.jpg)
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);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/7.jpg)
PHASE 1: SYNTACTIC ANALYSIS
![Page 8: COMPILER OVERVIEW. Compiler Phases Syntactic Analysis (Lexing, Parsing) c = (a + b) * (a + b);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/8.jpg)
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);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/9.jpg)
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);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/10.jpg)
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);](https://reader036.vdocuments.site/reader036/viewer/2022071808/56649edc5503460f94bed582/html5/thumbnails/11.jpg)
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