Introduction to Compilers : Second Edition

Embed Size (px)

DESCRIPTION

Introduction to Compilers : Second Edition 4th Year

Text of Introduction to Compilers : Second Edition

FANNIA BACKBONE

:

Compilers Introduction | Mr_Ahmed Elmasry;Eng_Nazira alshaar

Table of Contents ................................................................................................2 : 2................................................................. : Our Goals 2.................................................................................... :Computer ( : Machine Code ) ...................................................................4 : ......................................................................................4 : ...................................................................................................4 5..................................................................... :Assembly language 5..................................................................... : high level language 5............................................................. :Non procedural language 5................................................... :Natural language : ................................................................................................6 6......................................................................... :Algorithm ...............................................................................7 9......................................................................................... Compilers : 01................................................ Cousins Of Compilers : 01........................................................................Compiler Stages :..................................................................................60 : ..............................................................................................90 : .........................................................................................................12 : ........................................................................................02 : .................................................. .Error! Bookmark not defined

1

: : Our Goals Compilers Hardware Operating System . . : . " " . Hardware Drivers . :Computer , Computer Compute , Processing Storing Retrieval , . Wikipedia : , . ................................................. 2

. Machine Code , 0{ }1 . 0-0 Motherboard , 0-2 .

1-1 : Motherboard .

1- 2 : 3

( : Machine Code ) " " Low Level Language , Microprocessor , , Binary Code . Physical Addresses .Resources . . Abstraction : :

1-3 :

1-3: .

4

:Assembly language

Hardware dependent , . : high level language : . Procedural language

. hardware independent . :. Pascal language :Non procedural language

, OOP , . Objects . Objects :Natural language

.

1-4 :

5

: : . Games Business Applications .Operating Systems . . . Java ++ C 6VB . Visual Basic Dot Net . .

:Algorithm Wikipedia : . . Algorithm : ( )Decision . Loops 6

Problem .

Flowcharts Pseudocode UML . : . : . . : . .Loops :

1-5 : 7

1-5 :

1. : Edit Program

H.L.L : }{Notepad, Notepad++, Any IDE Code Editor .Source Code

2. : Compilation : Compiler Source Code Machine . Code 3. : Compile Errors : .

4. : Testing : .

5. . Logical Errors : Runtime Errors . . 1-5 .

8

. Java

,Notepad ,++ Notepad any java IDE Code Editor ,Eclipse

NetBeans.

1 - 6 .

.

Compilers

Source Language . Target Language High Level Programming . Languages C ++ C . Machine Language . Executable file

OffLineSource Code Compiler Target Code Executable File

1-7.

Error Messages 1 - 7 :

9

Compiler Construction Virtual Machine java 1-8 .

1 - 8 : .

: Cousins Of Compilers

:

Source Code Object Code . Basic Quick Basic . . . : 11 51 . On LineSource Code

Interpreter

Interpreter Output

Data

11

Loader . Loaders Disks . " Assembly Assembler .asm . . . ++.CCode.as

Assembler

Code.obj

11

Linker .exe ( ) Built-in Functions :

( Decompiler) . Deassembler . Security . Java Virtual Machine

21

: Compiler Stages 1-7 Black Box . Compiler Stages : .i

: . Analysis Phase : Front End . :. Syntheses : Back End " ".

.ii

1-9 : 31

. 1

Source Code2

Lexical Analyzer3 List of Valid Tokens

Syntax Analyzer5 Parse Tree

4

Semantic Analyzer7 Annotated Parse Tree

6

Int. Code Generator9

8

Intermediate Representation "In Memory"

Code Optimizer1

10

Optimized IntermediateRepresentation "In Memory"12

Target Code Generator13A File in Machine Code Format 1-11-:

14

1

3

2

5

4

7

6

9

8

1

01

1

21

1-11- :

51

: : : Source Code

High level Languages . : : Lexical Analyzer

. source code . Tokens

1-11: Source Code Tokens

: . .Token Type " " .

61

: Syntax Analyzer

:Parser .

. Parser " " " " . Parse Tree . Grammar if ++ C " " while loop . : . . C# Or Java if VB .

Syntax in Visual Basic Syntax in C# & Java

71

"":

Context, Checker or Semantic Analyzer . Statements " " . : ( ) X * Y X , Y :

: : Code Generation

Operating System . : Java Virtual . Virtual Machine : winX68 o winX64 o81

: Code Optimization

" " 1 0 . : :1. : Symbol Table

: . List Of Tokens . . Variable Scope . " " " "Data Type " "" Variable Scope " :

2. : : Error Handling

. . .91

:

:

06 * Position = initial + Rate

12

: . Computer . Machine Language , . Compiler Construction . " "Procedural , . Procedural OOP . 1. 2. 3. 4. 5.

6. 7. 8. 9. 11. 11. 21. 31. 41.

.

" "

. .

Symbol Table Error Handling . : 5. Code Generator 1. Parser 6. Target Code 2. Context Analyzer 7. Symbol Table 3. Intermediate 8. Front End Represention 9. Back End 4. Code Optimization 11. Parse Tree : Position = initial + Rate * 60 X = a + B / 13

51.

12

: .Editors &a