Presentation is loading. Please wait.

Presentation is loading. Please wait.

Compiler Design Nai-Wei Lin Department of Computer Science National Chung Cheng University.

Similar presentations


Presentation on theme: "Compiler Design Nai-Wei Lin Department of Computer Science National Chung Cheng University."— Presentation transcript:

1 Compiler Design Nai-Wei Lin Department of Computer Science National Chung Cheng University

2 Chapter 1 Introduction to Compilers

3 3 Outline of This Chapter ♥Introduction to compilers ♥Introduction to compiler generators ♥Introduction to automatic tool generators

4 4 Programming Languages ♥Human uses human languages to communicate with each other –Chinese, English, French ♥Human uses programming languages to communicate with computers –Fortran, C, Java

5 5 Computer Organization Operating System (Low Level Language) Hardware Machine Compiler Applications (High Level Language)

6 6 Compilers Compiler Program written in High-Level Language Program written in Low-Level Language Error Message

7 7 Components of a Compiler ♥Analysis –Lexical Analysis –Syntax Analysis –Semantic Analysis ♥Synthesis –Intermediate Code Generation –Code Optimization –Code Generation

8 8 Lexical Analysis final := initial + rate * 60 id 1 := id 2 + id 3 * 60 Someone breaks the ice S o m e o n e b r e a k s t h e i c e Lexical Analysis

9 9 Syntax Analysis id 1 := id 2 + id 3 * 60 := id 1 + id 2 * id 3 60 Someone breaks the ice subjectverbobject sentence Syntax Analysis

10 10 Semantic Analysis := id 1 + id 2 * id 3 60 := id 1 + id 2 * id 3 60 i2r Someone plays the piano The piano plays someone (meaningful) (meaningless) Semantic Analysis

11 11 Intermediate Code Generation := id 1 + id 2 * id 3 60 i2r temp1 := i2r ( 60 ) temp2 := id 3 * temp1 temp3 := id 2 + temp2 id 1 := temp3 Intermediate Code Generation Someone breaks the ice 有人打破冰

12 12 Code Optimization temp1 := i2r ( 60 ) temp2 := id 3 * temp1 temp3 := id 2 + temp2 id 1 := temp3 Code Optimization temp1 := id 3 * 60.0 id 1 := id 2 + temp1 有人打破冰 有人打破沉默 Code Optimization

13 13 Code Generation temp1 := id 3 * 60.0 id 1 := id 2 + temp1 movf id 3, r2 mulf #60.0, r2 movf id 2, r1 addf r2, r1 movf r1, id 1 有人打破沉默

14 14 Metalanguages Metalanguage: a language used to define another language We will use different metalangauges to define the various components of a programming language so that these components can be generated automatically

15 15 Compiler Generators Compiler Generator Compiler Definition in Metalanguage Compiler Error Message

16 16 Definition of Programming Languages ♥Lexical analysis: regular expressions ♥Syntax analysis: context free grammars ♥Semantics analysis: attribute grammars ♥Intermediate code generation: attribute grammars ♥Code generation: tree grammars

17 17 Automatic Tool Generators Tool GeneratorTool Error Message Tool Definition in Metalanguage

18 18 Applications of Compilation Techniques ♥Web Browsers (HTML, XML, …) ♥Word Processors (postscript, pdf, …) ♥Computer-Aided Software Engineering (UML) ♥Computer-Aided Design (VHDL, Verilog, …) ♥Computer-Aided Manufacturing (Pattern Recognition)

19 19 Outline of This Course ♥Lexical analysis ♥Syntax analysis ♥Semantic analysis ♥Code generation


Download ppt "Compiler Design Nai-Wei Lin Department of Computer Science National Chung Cheng University."

Similar presentations


Ads by Google