Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CD 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

·

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
-

mainly focuses on the

started with #

-
It removes the # statements with new action .

P1 .
C

#.. -----
Actual
i >
Preprocessor >
-
code
#.. ----

So that
#- -
Compiler will
understand.

Preprocessor is responsible for understanding the

file inclusion .

= # include <Stdio h) . for this kind of file


# include (P1 C) .
we required linker

preprocessor can also do the


substitution
acro
=

· 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
.
-

Preprocessor is also help us to understandthe

ditional
macs

=> #if , #endif ,


#Jese edc .

preprocessor can also produce error if


any
command is not understable by the
preprocessor .
= #
include
stdio h > "missing .
&
It will
produce error
during compilation
# define only
max 100 .
8- >
semicolon
should not be here
.
·:
It will
produce an error .

Preprocessor is implemented inside the compiler.

② Compileri

secure
Absolute
C
-
Assemble
* some compiler also converts the

directly machine code .


c code into

-
It checks all the statements (code) and
if any error is present then it will produce
error after compilation otherwise it will

produce assembly code .

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

Variable (extern intoc)


line Ciles (functions ,
ed
.
cove all mal
references to

make executable code .

#commen
-

Linker link the neader file and source file and

so many files to make code usable or runnable .

- Stdio. I

* tanalRefor
=>
e

·
P2 . C

P2 external
Cy
.

file
Staio h.

x- external
variable .
⑤ Loaderi
-

It relocates the data/code.


-
It alters the address of data/address
of code.

Loader knows the address of data & code


which is in RAM and whenever we need

any data or code ,


Loader just load or make

it available for us
.

Eg
-

-
.

~ acty => EDDR ,,


1000]

Assembly
C code
Code

RAM
recolate the
addresses
& of code of data
This is
just
imaginary Scenario

compiler & assember only use symbols


know which
(0,3) because they don't

address is available .

inker & Loader both are static/dynamic


-

Before runtime & after runtime Linkerd Loader


is required.
Notes
Inasescomputer
# :
PhasesCompilerin
#

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(A) = GE] Collow (1) =


&$3

[t] follow (B)


=
[]
fi() =


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

Si (B) = Ga , <3 So (B) =


G$ 2) ,

= (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
-

Less popular of memory space.

# Entries of Le table

① shift Entories - shift items

items
State
& Entries - state

③ Accept entries + seS .

& Reduced Entries >


+
XeX .

⑤ Blank entries /errors)

① Shift Entry Tables


Core :

>
-
Every terminal transition in the
diagram will

give one shift entry


>
-
of shift entries of terminal transitions.
No . in table = no ·

of shift Of shift
shiftatshee
-
no
·
no .
no of
= I

entries of LR(0) entries SLR(1) entries LALRD)


t entries(gotoentry) Sor Tables

>
-
Every interminal transition in the
diagram will

give one state entry

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

entries of entries SLR(1) entries LALRD)

③eptanceEntry
LR Tables

>
- Find one state that has
(s'es ) .
item .
make
M[X $] entry
,
as ACCEPT
.

is.get e
table

& D Reduced Entry for LR(0)


-
Robotics

Wifi
car
controlling using

do

You might also like