You are on page 1of 19

" "


Programs, Interpreters and Translators
:Programming Languages
.
.
.
Assembly High Level Language
"" Machine
.Language Compiling
.Compiler
:Language Processors
Source Language
Source Program
.Target Program


.
.
Interpreter

.


.

JAVA JAVA
bytecodes .Virtual Machine
bytecodes
.
.
Modules
Preprocessor
.


.
Linker Loader
.

-
Analysis-Synthesis Model of Translation
Structure
-

:
.1 : Analysis Part Front End
.

Error Message
.

Data Structure .Symbol Table
.

Intermediate Representation

.
.2 :Synthesis Part Back End

.




.
Symbol Table
.


Analysis Part :
:Lexical Analysis
.Lexical Analyzer
:Syntax Analysis
.Syntactical Analyzer
:Semantic Analysis
.Semantic Analyzer
Synthesis Part :
:Intermediate Code Generation
.
Syntax Tree
.


Code Machine
.
.
:Code Optimization
.

:
.1

.
.2
.
.3
.
.4
.
.5
.
.6 .


Programming Languages Specifications
:Definition of Syntax
Syntax . Syntax

. symbols
Syntax .

FORTRAN, BASIC, C
. Syntax
Regular Expressions
.Backus-Naur Form Visual Languages
.
Syntax
. Syntax

Type-2

Grammar Context-Free Grammar


.
if-else JAVA :
if (expression) statement else
Concatenation : if
( )expression ) (statement else
) .(statement expr expression stmt statement
:
if (expr) stmt else stmt

Stmt

" "
.

..
. / /
:
.
:
= }{9 .................... 3 2 1
=

:
0 66091652314566 65 00000


.
:
.1 :Alphabet
.
.2 Syntax.
.3 Semantic.
:
.1 Syntactic Analysis
.
.2
.
.3 Ambiguity .
.4 Syntax Semantics
.

:Semantics and Pragmatics


Semantics Pragmatics

.
Semantics

Syntax.
Pragmatics

.


Formal Language Theory
) (Alphabets
) (Strings .
Symbol
.
.
a1,a2,..,an . a1a2-an
Empty String .
: } 1={a,..,z } 2={1,..,9:
abb 1
123 2
ba12 1 1
314


.
1 )2 U 1( 2 .

:Languages
L Subset *

Language L Sentence Word . String


{0,11,001} , {,10}, {0,1}* : *} {0,1
}. {0,1
} { .

} {

Union L1,L2 L1 U L2
L1 L2 }. {x x is in L1or X is in L2
L1, L2 Intersection L1L2
L1 L2 }{x x is in L1 and in L2
Complementation L L
L }. {x x is in * but not in L
: } L2= {, 01, 11} , L1= {, 0,1
}L1 U L2 = {, 0, 1, 01, 11
}L1 L2 = {
}L1 = {00,01, 10, 11, 000, 001, .
UL=L
L=
* =
* =
Difference L1 L2 ) (L1-L2 L1
L2 }. {x x is in L1 but not in L2
Cross Product L1 L2 ) (L1 L2
) (x,y x L1 y L2 :
} {(x, y) | x is in L1 and y is in L2
L1 Composition L2 ) (L1L2 :
} { xy | x is in L1 and y is in L2

: L1= {,1,01,11} : } L2={1,01,101 :


}L1 L2 = {, 11
}L2 L1 = {101
: } L1={,0,1 } L2= {01,11:
})L1 L2 = {(, 01), (, 11), (0, 01), (0, 11), (1, 01), (1, 11
}L1L2 = {01, 11, 001, 011, 101, 111
L - = L,
- L = ,
L = ,
{}L = L.
Li Composition i L L0 }, {
L0

..... L3 L2 L1 Kleene closure L *L

.
....... L3 L2 L1 positive closure L . L+
} L1= {,0,1 } L2={01,11 :
}L1 2 = {,0,1,00,01,10,11
}L2 3 = {010101,010111,011111,110101,110111,1111101,111111


Lexical Analysis
Scanning

.Lexemes Lexeme .Tokens
Token
.
.(token-name, attribute-value) :
) ( token-name
. ) (attribute-value entry
token . Semantic
Analyzer Code Generator .
Assignment Statement:
Position = initial + rate*60
Lexemes :
Position .1 Lexeme token ) (id, 1 id
( identifier variables constants
)functions 1
Position .
.2 = Lexeme token
>=< . token .
initial .3 Lexeme token )(id, 2
.4 + ><+
rate .5 )(id, 3
.6 * >*<
.6 60 ><60
Lexemes
:
>(id, 1) <=> (id, 2) <+> (id, 3) <*> <60

:
1 Position ..
..

initial

..

rate

tokens :
-

Keywords

Constants

Operators



.
.
.
:

x=y+1
tokens :
IDENTIFIER, EQUALS, IDENTIFIER, PLUS, INTCONSTANT, SEMICOLON

Syntax Analysis
Parsing
( ) Syntax Analyzer :
.1 Tokens
. :
Y=A+/B
scan
+ /
.
.2 .
Parser
tokens
. Syntax Tree
( ) Expression
. Statement
.
Position = initial + rate*60
* rate ) (id, 3
60
.
=
.Position
.
:


Semantic Analysis
Expression
( )
.
Syntax-Tree


.Intermediate Code
.

Index

.
rate, initial, Position 60
Checking Type *
rate 60
:


Intermediate Code Generation

. Syntax Tree
.

Generate
. :
.1
.2
.
Three-address Code ( operands
)
:
)t1=inttofloat(60
t2=id3*t1
t3=id2+t2
id1=t3
:
.1 assignment

.
.2 .
.3
.


Code Optimization

""

.
Code Optimizer 60

inttofloat
. 60.0 t3 id1
:
t1=id3*60.0
id1=id2+t1

Optimizing Compilers
Run-Time
.


Code Generator
Code Generator

.
.
.
R2, R1 :
LDF R2, id3
MULF R2, R2, #60.0
LDF R1, id2
ADDF R1, R1, R2
STF id1, R1
F
. id3 R2
60.0 # 60.0
.Immediate Constant
id2 R1
R2 . R1 id1
.


Symbol Table Management
Data Structure

.
. :
.1
.2 ( ..)
.3
.4
.5
( )

.


.

You might also like