0% found this document useful (0 votes)
29 views10 pages

CD Unit-1 Imp Question & Answers

The document discusses various compiler construction tools, including lexical analyzers, syntax analyzers, and code generators. It explains the roles of compilers and interpreters, highlighting their differences and the processes involved in recognizing tokens and managing buffers. Additionally, it outlines the phases of a compiler, such as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and final code generation.

Uploaded by

vaishnavi j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views10 pages

CD Unit-1 Imp Question & Answers

The document discusses various compiler construction tools, including lexical analyzers, syntax analyzers, and code generators. It explains the roles of compilers and interpreters, highlighting their differences and the processes involved in recognizing tokens and managing buffers. Additionally, it outlines the phases of a compiler, such as lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and final code generation.

Uploaded by

vaishnavi j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Ontt>1

construction tools
A llsrte
atte
shåt otes on aConpiles
Bootst
tsapping cc0ss compiler ?

Cornpiler constructfon tools


A tprvduces Jexical analyzers
gererat
-

i) Sconhe
a ieqular expreseion.
fro prduces suntax
t Outornatically
C:) Povger genetatol
-

qramatica descsiptior).
analyze1S fom a
hat produce
engines
drected tsansloation
Syntax
-

Cit:) collecfion db voutines


a (code generato)
aereratois)
-

AutornatiC code
Code generaloi tool collection ules.
Code generato) frpn a
podduces
itfactlitates the
CV Data- flow oanalysis engines
gathering of tnfimation an
an
t prDvídees
Comptler congtruction tool K vai Ous
outines fo) constructing
integrated set
phasès Compiler

)Boots topping a self compilina


self compi la
technique 46 producin g
is the
It
compiler
oritten in he sourCe Prgramiring
Cornpiley ie
tends to conpile
fhat it
Xanguage
S
t 1s a proce sss in ohich simple Language
anguage
translate mõe Cornplicated program which
used t o
in turn may 'handle fo
moe Cornplicated prograr.
X new lawguage
implemerta ion
onguag8
M z arqet code
XMZ
Xyz + YMM =

c) Cxoss CornpieX
a Compiler that Tuns on one
is
AA crosS
CrOSS compile8
code fo anuther machine.
machine
achine & pmduces ohject
The caoss Compi ler is usecd o mplemert the compiler
e
tohteh fes characterized b Jonguages
ihe Sourcearguage
) he taxget Janguage
uhich t s wten Ccompiler)
i h e ianguage 'in

ls
LSN
Cornpilex
Conpiler Ptonguage
oritten in
longun
onquoe
machine Code N.
thot prnduce olp language

LSurce language S Conpiler Nlarget language


S DTiten in
SSMM Cornpler ta language
M Thot produces olP lanquage
Songuage M

machine code M.

LMN = LSN + SMM

M M) Rus LSN throug SMM to pduce


LMN

DiPterentiate Conpile nterpretes ?


A Compiley Interpreter

Converts erAre Source Converts ne by Stne


pbgram imo target long. into torget loriage
2. Reautres more memoy . Reautres less memoy
3. Faster than nterpreter . Slover han Compiler
. Not debugger.
a
4 Debugger by default
5 Displays ertà after splays exvor aftes
comp:tng9 ertre prograr.
Compiling a line.
6. Condi tional control stotements 6 CondiHonal controf
are etecuted faster in
Statements are exerute
Sloer în this.
Object code 1s generated No obfect code s
ofter eiecuk'ion aP
9enerated.
etire proaram.
BASIC, LISP
Eq C, c ++
Eplain about ecogniztion of tokens?
A10 recogmize to kens thexe are two step s
Design d tvanschon dagram
Cti)implemertaion o 4rnskion diagrarr.
Transtion diagram
Keqular expressions
are represented using transtion
t has collection of hodes circles
diagramn
called States
thot could occur
aCondiion
Each Stote repvesetS
loolkan9 t
dur ng the prDcess Scanring the P
a lexeme that matches one 8eeral potterns.
stast with ether a'
Ca+6) a*, here exp. ca
b&folowed by null any ro a'
lere indicotes inital State
U n d i c a t e s n a l state

State dtagam nAutomata


t migrt be a a ,ba, ,Qaa baa
odds & idertifter .
Kecognition of teserved m

similar Jdeniter
dertifterS are .

Kesexved wdids &


whereas
S Cornbsination of characters, digits
are conbinatton oF character s
esesved wdds
letter digit install id)
teter
O, return aet token (1,
other
Start
stalernent int abc
int b ,C
e take a
will take a a s ip å as
Tom above dagram. ?t
it1s a letter t ll move to next State.
whi.ch is mot a letter (o)
Aftex a we have
lo n a l state and letter a'
digt, so t il nove

imoved Symbr table, after Teading ftnal


to
du trtalstate and the prpcesS
Stote, tt agan goes
is sepeoated
Thexe are a woySto handle eeetved DOvds
o d s nd
nd

identitterS
* Install eseöved uwords n Sunbol table inttially
iitially 1:,
i.e,
3a Keywords are installed ulhen an dentitier is

Pound nstall ad(


Found, sll be called td insert 'rfômation
obout idertifler ito ymbol table. get Token( )
idertiftess vohins leteme 1 seseT Ved wdd
o d cd)
c8)

identifter
Create sepoate tvansithon dtagrarn each keyodd.

St Of Cnot aleter/ ctg:t)


Start

)Eplain about p buPlers &Sentinels oth he help


help
of Pseudo code
(8)
buffess re gequired and explain about sentinels
along wth pseudo code
*Keadng the Souxce program & dtvidtng into
lexerneS operoion s Speeded by lp buffe
fovuavcd p
Buffer 1
e *Ci 2 eo 8uffer 2
leserme begin. ptr
h e Stoterments are moved to buffer, in which
each buffes reads N characterS at a time . After
seadtng N characters that buffer will be seloaded
wth another stoterment
fewer han tN characters remain in the p fle,
hen a spl choracter eOF s represented which
i s end o buPfer.
tlere aPonters to the P ae mantatned

leiemoe begin ponter ohtch mauks he begming


of 1he CuYent lexeme.

fovwaad pointer ohich scans ahead unti


pattesn match is -found.
ffouard poirter s about to move past he hakfuny
mak,te tight half s tlled oith
characteS e
mew
P
second buPfer 1sPRled.
Dreod antages
oPookahead t tmtted
Ihe amourt
impossible to
Thts ltmited lookahead may take
tn Situatitons uwhere he lenqth
ecogni ze he tokens
of lexeme is longer than the lerqth oP the buffer

SentinelS
advancees one
step ahead,
When Foward pointer
buffer is loaded
t t bufer ts completed hen econd

f o each character tead, two tasks are perfomed.

One for end of the buffer


read.
hat character is
One fS determinin9
Cusrent character
*EuPPer end test is combined wth
we extend each buffer to hold a sertine
test,
Character at e end

fouard
M eofc* 2 ieofeo
lexeme begn
Sentinel is spl chaacter that can't' be post The

SOurce program and t's character ts eof".


end oo
Ary eofthat
*Ay appeors other than at fhe
buPfex meonsthat the p 's at the end

Algotthm otorard pointer


SuottchC* foduoard ++)
ca se eof
s at end of Arst buffer) {
f Pdwad
load second buffer,
of second buFfer
fovuard begirning

1s at end of econd buffe«) {


else if (foawad
deload -rst buffer
foauoaud beginn'ng of tost buffer
buffex he
fhe end
else * eof wthin a masks

of input*
tesmnate lexical analysi5
break

Erplain 3olea lexical analyzer


eaploin about esponsibilittes of Scanner (8) Xerica
analyze
h e matn tosk of letical analyzer s to tead
nd he
P charactess of he Souuce program, qroup hern
iryto leerres &
produce op as a
sequence*
tokensfo each lexeme in the Source Pram
*hese tokens ve Set to
Parser fo tax anadyss.
lexical analqzer discovesS a lexeme
identiPter, it sends it to sumbo Constitutng an
his Symbol toable table
an
identifer ohich 9useful
S
P nfämatton
neede to pass tegardrg
Pax Ser pasS toto the

Source
exical token
Program Analyzer kk Sntar SematHc
8etnet Tokent)halyzer Analyze
Identifier

Symbot
e t Next Tokend Table
ead characters Comand cauges the
Cauges he lexical
lexical analyzer p
he next lexeme
frorn t s ilp utl
P untl 1t
anayze
it can identify
& pmduce
fS 1t the next idenit
token
lexicoal analyzex also
pefdms othe tasks
eliminating whtte spaces taskstketke
blank
Comment ines. Spaces and
anc
ulhot iS Compiler and explain about
Variou9
phases oP
Compiler with an
example?
A * Compiler is a translator First t idertifies
the essos & f there are no eszoss then
only it convestS high-evet lanquoges to low
level languages
t translateS the Complete rogram).
SOurce prpgiam ( c

Compile

larget pDgram (obj. file)


The various phases of Compiler are
exica Anolyzer (Scanning)
Syrta Analyzerarstn
Sernantic -Aralyzer (Type checking)
4rtermediate code generatol
5Code optmizer
6Code generato
Stoucture Sousce Prgra

LextcodAnalyze |
Tokens
Syntax Analuzer
parse tree / Syrta tree

Semanti c -Analyzer
Modifed syrox tree

Uneomediata codo generatoD

Sumbo Itemedtatt cods


Table Code Optimizer Hlardler

optimized code
Code Generatð)

Target onquonee
ig Compilation Prpcess Structure
.exicol -Arotyres
s also coalted Scanner.
exical Analyre
tis he sphase of the front end pror ess 1he
iS tu e a d
be
Tbe
main t0sk of he leticol onalyzer

P choactees df he SoNce pmrarn.

2 Suntox Anatuzex
t S knowor a s ar Ses
he nd phase the
front end prce
tis syntazes
accept tokens Vesrfy h e the
*Syntax -Anayzex cosectt
tokens ohelfer 1hey are Syrtactically
he
not

3 Semanttic Analyzes -
I the d phase of a compiler
neaning off
o the Syntax
Suntax
&is used to vesity the
to another data type
*tt Convests one data type

ntesnedtate Code genesatð


s the 1 phase aP the bacc end prpceSS
the modi-led syrta tgee
Suta tsee Then
Then
s used to accept
* intesmediate code
prDduce oP as

5 Code ptimizer
*It S the d phase bacE - end prDce SS
of the

hemoves unnecessary Code


tne &arange
ar Tange
1h1s phase to Speed -up h e execution
&totements
fhe sequence
t h e program
the AunninA me the
T e
Code optimizes improve
A0xget prparan
Generato -
6 Code
phase in he
tina compiler desian.
* he iS
ntermediat Code
b e code Optirni zer ocepts
*
uhtch i generated from the fiont
seprecertaton
end the compiles
C 0tb+5

<> {b,3 <+


C,1 : > <a,29
leica int to loat (5-6)
Analyzea

Syntax
Analyzer

a1>

b,3
Sem antic
Ahalyzer

a2

b,3 5.0
Jnteirnediat
Code Generator
t int to float (5:0)
b3tt
t3 Ott

Code Optimizer

t bzt int to float (s-0)


C aa+t
Code
9enerato
D b3
ADD bg 5 . d

ADD Q2b3
St C

You might also like