Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University.

Similar presentations


Presentation on theme: "Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University."— Presentation transcript:

1 Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University

2 what Objects Requirements Why study compiler construction ? Compiler definition Compilation/trasnaltion steps (2014-1) Compiler2

3 Objects Basic knowledge Necessary tools Practical experience (2014-1) Compiler3

4 Requirements (1) Theoretical techniques Automata theory: 2.2, 2.3, 2.4, 3.2 Data structures Discrete mathematics Machine architecture Assembly language (2014-1) Compiler4

5 Requirements (2) Practical coding Planning Interaction between Structure of a compiler Design of the programming language (2014-1) Compiler5

6 Why study compiler construction ? (1) from “Basic Compiler Design” Computer science 분야에서 well-cultured 하기 위해 반드시 알아야 할 주제 Programmer, computer scientists 에게 중요한 도구 Compiler 작성에 사용되는 techniques 는 다른 용도로도 유 용한 기술이다. Domain-specific language 에 대한 compiler 나 interpreter 를 작성할 필요가 있을 수 있다. (2014-1) Compiler6

7 Why study compiler construction ? (2) From “Modern Compiler Design” Compiler construction is very successful branch of computer science Compiler construction has a wide applicability Compilers contain generally useful algorithms (2014-1) Compiler7

8 Why study compiler construction ? (3) Successful branch Proper structuring of the problem Analysis-synthesis paradigm Judicious use of formalisms Excellent standardized formalisms  reduce the effort to produce parts Regular expressions, context-free grammars  lexical, syntactic analysis (2014-1) Compiler8

9 Why study compiler construction ? (4)  Use of program-generating tools (2014-1) Compiler9 Program generator formalism program

10 Why study compiler construction ? (5) Wide applicability Reading structure data: read routines for HTML files, PostScript files, … Rapid introduction of new formats General file conversion problems Useful algorithms/data structures Hashing, precomputed tables, stack, garbage collection, dynamic programming, graph algorithms… (2014-1) Compiler10

11 Definition Programs that translate one language to another Source language, source code: C, C++, … Target language, target code: machine code, object code (2014-1) Compiler11 Compiler source code target code

12 Compilation/translation process (1) (2014-1) Compiler12 Scanning Parsing Semantic Analysis Source Code Tokens Syntax Tree Literal Table Symbol Table

13 Compilation/translation process (2) (2014-1) Compiler13 Error Handler Source Code Optimization Code Generation Target Code Optimization Annotated Tree Intermediate Code Target Code

14 Compilation/translation process (3) Scanning Lexical analysis Stream of character  token Example: a[index] = 4 + 2 a: identifier  symbol table [: left bracket index: identifier ]: right bracket =: assignment 4: number  literal table (ex: “ksd”) +: plus sign 2: number (2014-1) Compiler14

15 Compilation/translation process (4) Parsing Syntax analysis Structure of the program  grammatical analysis Parse tree (syntax tree) (2014-1) Compiler15 expression assign-expression expression subscript-expressionadditive-expression expression identifier index identifier a number 4 number 2 [] = +

16 Compilation/translation process (5) Abstract syntax tree (2014-1) Compiler16 assign-expression subscript-expressionadditive-expression identifier index identifier a number 4 number 2

17 Compilation/translation process (6) Semantic analysis Analysis of the static semantics Declarations Type checking Dynamic semantics  only in execution Attributes: extra pieces of information (2014-1) Compiler17

18 Compilation/translation process (7) (2014-1) Compiler18 assign-expression subscript-expressionadditive-expression identifier index identifier a number 4 number 2 int int array Annotated tree

19 Compilation/translation process (8) Source code optimization Wide variation in the kinds of optimization and the placement of the optimization phase Constant folding: 4 + 2  6 (2014-1) Compiler19 assign-expression subscript-expression identifier index identifier a number 6 int int array

20 Compilation/translation process (9) Intermediate code, intermediate representation Three-address code t = 4 + 2, a[index] = t t = 6, a[index] = t a[index] = 6 P-code Syntax tree (2014-1) Compiler20

21 Compilation/translation process (10) Code generation Target machine’s instruction Data representation Ex: assembly code (2014-1) Compiler21 MOV R0, index MUL R0, 2 MOV R1, &a ADD R1, R0 MOV *R1, 6

22 Compilation/translation process (11) Target code optimization Addressing mode Faster instruction Redundant code, unnecessary operations (2014-1) Compiler22 MOV R0, index SHL R0 MOV &a[R0], 6


Download ppt "Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University."

Similar presentations


Ads by Google