CD 1
CD 1
CD 1
Tompiler
Design
-
Introduction
-
Translators
-
phases of compiler
-
Errors
Symbol table
#
Translators
ion from one form to another form
translator Target
T
source -
->
code Code
>
-
Examples of Translators :
Compiler
①
② Interpreter
⑤ preprocessor
⑨ Assembler
⑤ Editor
⑧ Linker/Loader
etc .
>
-
C
Language processing system
com
/" Executablee
Compilationpress :
Editor
codeprocesse embl-
Linker Executable
&
(code
compiler
- >
-
machine
-
Loader Code
① Preprocessorie
It statements which
-
started with #
-
It removes the # statements with new action .
P1 .
C
#.. -----
Actual
i >
Preprocessor >
-
code
#.. ----
So that
#- -
Compiler will
understand.
file inclusion .
· J
of preprocessor
output
Eddie maa
int A
[max] ;
Preprocessor
>
int
void main()
A C00],;
E E
-
S invoked
int < = 100
c code
or :
sourca -
Actual
I code
This code
compiler can't understand is understable
this code
by compile
.
-
ditional
macs
② Compileri
secure
Absolute
C
-
Assemble
* some compiler also converts the
-
It checks all the statements (code) and
if any error is present then it will produce
error after compilation otherwise it will
what is compiler ?
-
=> It takes
is a
program (machine code) that
input as
C
Program and it converts into
Assembly code .
a
prog . compile - assembly programs
-nigh amode
pie wombly
code
(m/c dependent)
(m/c dependent) code
code
code
③ Assembler
is
(Relocatable code)
Assembly - sembler >
-
MC code
①
line Ciles (functions ,
ed
.
cove all mal
references to
#commen
-
- Stdio. I
* tanalRefor
=>
e
·
P2 . C
P2 external
Cy
.
file
Staio h.
x- external
variable .
⑤ Loaderi
-
it available for us
.
Eg
-
-
.
Assembly
C code
Code
RAM
recolate the
addresses
& of code of data
This is
just
imaginary Scenario
address is available .
A - Aablade
A - Cde A
A-abA'lE
St salAbS A
At aalb
5-
Sa/Ab
ollod imp
for syntax Analysis
① follow (1 [B]
=
follow (A)
=
Sist (B1 =
2 bY
fi(t) =
Gas
Collow 1) = follow (s) =
&$3
Si (B) =
Gb}
② Si(sl =
[b} follow (S1 =
&$3
first (B) 563
GE] follow (1)
=
Si(A) =
=
follow (s)
= <$3
[b] follow (B)
=
fi() =
③
S (5) = GE} follow (S1 = <$)
④
Si (5) =
Ea by, follow (S1 = &$3
SiCA) =
SEY Collow (A) =
(a)
follow (B)
=
Gb}
fi() =
2- ]
⑤
& (5) = Ea .
b ,
c ,
El follow (sl :
[$3
Si(A) =
GE cy , follow (1) = Sa $} ,
follow (B) 2 $ by
SE]
=
,
fi() =
⑧ Fi(s) =
(a 1) ,
Fols) = GB ,
9
.
1 ,
13
⑦ Fis() =
Ga3 Fo(s) = 2$ 93 ,
⑧ Si(s) =
[a , c, d ,
b , 23 follow (S1 = [$3
2 $ d3
GE ch Collow (1) 9
Si(A) = ,
= , ,
follow (B) G$ b d)
(E d]
=
, ,
fi(B) = ,
⑨ <$ 23
Si(E) =
<( , i} Fo(E) = ,
& (R) =
Et #1 ,
Fo() = <$ .
) 3
FoLT) 2 13
37 :3
= +
Si (T) =
,
=
2 +, # 3
Foly)
fily) =<*, #3
& *, #3
= 4) i) Fo(F) =
Si(F) ,
G(s) = Ga ,
c , d3 G(s) = \$ , 23
= (d +) Ga c3
Si(p)
,
So(D) = ,
- left to right scanning
Le Left most derivation
Panser
I
--
Non-recursive
Recursive descent
descent
- Table
-
Procedur
Fi(s) =
(a b c -]
=>
,
, ,
Fi (l = Ga z] ,
Fi(B) =
[b EY ,
Ga b =3 fo(s) = G$3
② Sill = . ,
fi (A) = Ga e) ,
So(A) = 2b , E}
Si(B) = (b z] ,
fo(B) = G$3
>
Reverse of RMD >
- for Bottom up parsing .
/SR-parser
SR palsen
-
> Time complexity. (0 (3)
=
scar -
emai
operator
(iv)Cre
~
precedence
parser
CRRD
SLRD LALRII
LR()
Ab/BC
⑧
-
-S
A
+ a Be .
A A
- .
a
a
B
-
8/22
Lecture
11 -
#
CHRI -> LAUR(I)
-less space
- more space
powerful -
less powerful
more
CLR1)
-
than
than LALRII)
because
-
more popular
-
# Entries of Le table
items
State
& Entries - state
>
-
Every terminal transition in the
diagram will
of shift Of shift
shiftatshee
-
no
·
no .
no of
= I
of terminal tranahins.
of state
>
-
No . entries in table = no non
of State
>
-
no of state of state of state
no
.
no no
entries CLRI)
LR(0)
I
③eptanceEntry
LR Tables
>
- Find one state that has
(s'es ) .
item .
make
M[X $] entry
,
as ACCEPT
.
is.get e
table
Wifi
car
controlling using
do