0% found this document useful (0 votes)
47 views

CD Mid1 Answers

The document summarizes the key phases of a compiler: 1. Lexical analysis - Scans characters and generates tokens. 2. Syntax analysis - Parses tokens and checks syntax. 3. Semantic analysis - Checks meaning and resolves symbols. 4. Intermediate code generation - Converts input into intermediate code. 5. Code optimization - Improves intermediate code performance. 6. Code generation - Produces target code like assembly or machine code.

Uploaded by

Dilip Raju
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

CD Mid1 Answers

The document summarizes the key phases of a compiler: 1. Lexical analysis - Scans characters and generates tokens. 2. Syntax analysis - Parses tokens and checks syntax. 3. Semantic analysis - Checks meaning and resolves symbols. 4. Intermediate code generation - Converts input into intermediate code. 5. Code optimization - Improves intermediate code performance. 6. Code generation - Produces target code like assembly or machine code.

Uploaded by

Dilip Raju
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Erplafn each phase olo Compik x

phase o ComptleT
Sourte ppsam

lexical Analyze7
Sntax Anauyzey

Semantic Analyzer
ETro
hardits
Smbo nte rnediate Code Geneotor
Pable
cOde ptimization

Cocde Generator

laraet pmqram
1xical Anayze 1g
1E is alko Called Scanne
i be pmce O ealinghe ChaaCters om
lelt to ight anod gmcep fota toEens
bouing a Coeci
meanin
Synta nakzr
Secomd phase pthe Compilea aen
Lnoon as parse) t qeisthe tokeo
m the lexico Sseam as inpu
analyze2 pthe Cornpik and aen ega
Suntan taee Cpa se tzee) as the Gutput_
3Semantic Analyze
Tt fs the thid gtageof the Compiler it
getrinut
om-theSyataaunalyzer Atorce treL an chech
LOethen gaenn Systems CoTct_pr nof meanimg
fallp
atermediate Code Generato
4 aLcthphase o the Campller
qeis input
mm the Sematic aaltia and
Canveak inpuE ob
Pucpt as dexmedtate Code Such a
2 alen Crde
Code ptimizatbn
R is Rth phase of the
n
Comptlez
he ntem0eciate Code and
it qi npd
pmducos optimiZed
intermediate code- na Outpuct
6 Cocle Gereyation
ghs inputmm heCodo
taaget cade O obiocttade as Dptimization and pmduo
Sunbol toble mapagemert aresult
Sqmbaltabe is Med isto store all the imtormafi nn
ahau idenidten sed n the Dgann data Shuctre
Containin etorcd on cach Suct
8 Eam Hand loonitien
i
Each phad Can enCocinten eToD& atten
_a phse mLut hadle the detecting
o
cC
Enum to eal (60)

Cads optimizafion

tiol3*num
1did ft

Code Gabion

LDF ida
mul nun
LDF 3 id
ADO F2T-
YF d

a
about input buffaring
Input Bucetng
As chorocters areteaopnn f u t 2aht atght4adh
aah
chasacten Stosed io the lter n dosm ancawingd
_aschoLon belau
token
faroord Ponfe

-Look ahecad poiates

Begin ig of the
token
butlen cherne
that eonaidea
LL inmdua_a Loo
then Constdaa
lange lpok aheadsSaf lyu
hardles lange
and inmpming inuolving
SepThe'that vestima
SauesKme b
b
cheching t cnd ohuten
Budiens divide into 2 N-chomcder_halve o
Choonbeloo

E M C +22
lexem ouo

binmer
Look ahead Cade h Sentinel
Sotch tonmd4
Cale eo
onaarcd a t end o 4St uflen)
Tead buffer
tora rd begtnoing o 2nd
buffen:
elf(fomdond it at endDfd buffem
2e/oad buffes,
doaudaobegiann o1buffa

clse e e of ithin_a huffea maaks th erd oL h


temimte LA
haeak
Lase cto the othea charackeas

2hErplain the uw0king ofa LEX Tool


king ofa LEx inal

E fs aComputen pmapa that geneaates leaicelPnalLze


Est a Spectdication Ofexialanalyzea ií prepared b4
Cxdatiag a_prnagonlez lin lz lauang then le
unErDugh
mun loa Cornpt Le tn_pmduce pnaaam
hen
Len. Len Compiles let .C
nloy.csCompilen a . Dut (LA)
iP stream a. Out Sequenie-bfFoeeres
ndule_an ahleck_pmaxam a.but which is the
Lanicaanalze tha
tanttortmi an tnpu
Tofens
1OEenA
Sequanu
i n t o _a
Stream
Le panaamtomat

dedintien

es

1 usea Submutines

3 Conside the grammar


ESE+TT
T LF/F
F(E)Ld
Testan praltcfive posing table ad check Be qtNen_
gmmmaY 1L) px Dot
nCadure to so lve
step 1 Eliminat Anbuiquitylatt eCunsim And
Leftac tm
tepalculate£TPST nd folloO- the ambf eyuls
q1ammarchtnined
tepaonzlnuct a torae table
Step: Elimimatinq gecuTATo
E TE

T ET
T ET|
F (E)d
step:Calculating PIesT and oLLO
£TRST CE FTRSTT)-£IRSTLE) = , 1d}
fTRST(T=i*S
TeST E) =\tuE
folLoo
follow E) - , S
fOLLOLO (TD-Fouowa)= t
foLCovo CA t * ,),$}
epa Consimctiag a parke tabe

N 1d C
E ETE ESTE'

E E
T
TFT
T TETAFT| T T>
F Fid F-(E)
Th given opmmman a LLO graMmaa beCau
hare is no ony sakhifECondkct
cent_parsez dor thbe
theecrstve de
Defgn
qmamman

TTF/E
F-C id
kcurstve ACadpnsen aithouf
daon4PKG
the techhatgue ol Top
2 H uca
hacktracking
Ppegnmed b esve lawauag PHS pducbions
Odpduéion
the sting RHS
Theatpbol_
C o e c t alternateVe
t
Lunfquely_deteamine the
OH
choose mIsen
approacb eCtasive aloceit
Themaian
Lwith a nCe dure
iS to_gelate Cach NT
Eaomple
p stream a the
lookahead= a
matchL)_
Ook ahead==+
match
Void A
Chop.se_AnA-pnduchov_A X, X--
or i t o k)_
i ( f s a nan teamiaal)
Call pncadue X O
e ke Ai equalk the carceot ilp SymbDl a)
_adiant the 1p to the Atat umol
elke returns to yAnothe A pmducHon
an e o has OCCued

Given_pamnma
EETT
TTAF |F
f (E)lfd
A ten femorin lotecunAron
PTE'
4TE

T fT
TAETls
F (E) lid.

pan CeoluYe EC)

TO
E TE
pecdue E ) _

P Symbol-fthu
Aol vant
TO
E'O

TfT
pncecure TO_

fO
TO;

ifilp Sqmbol= thin


adVonco
fO
TO:

f 1d
(E)
pncdue£O

ifp Symbpl='fd then


advar
i p Sumhd thn
ad van Lo c)
EO
4 Yp prabol then
advanteE
else

CTOTO
eroT

Lbsha what you uocenstand by lafE factoiogperorm


ft sacto tor the qaamma
Aabblaslcdglcdk.b.ledfe
Left facoaing
l e t s aMne tot in a
panmAthwe f
dnduction 2ule fo

The parsel_qenenotedpT thts kind o groroay


iS mot efRctent ai it équttres
back tracking
forthis zeasnn tn awnidthis_p0hem nudd
tn Leftfaco th qaamar
de Collectall pmductin
To f t facto aqammar beqinLwith
dame H.cand
that haue the
RH6
SameSymbolk in the
zing iatSinga prda-
2Coobine theCommon
N Snbol tn the
Cfion thtn_append a he
pmductipn
Codo this neLO
a_neLDSet Ot pTDductton
inally oe Caxeate
neoNT r Cach these guffu
using thic
Commpn Pmoluctions

A ten_llt actnsdin te ahoveaomar etomu


A dXA
A
Aab6lablcdeBrdglcdle
AsaA1cd Az

5 Constuct CLR poasing tabeothe gteD


S2CC
qiammal_
C-aCd
papcedu j CLR paqsing
Stepwailing agumauted oomma)
step2: RO callecMon o tp tem to be
found
step3TDeftotogtwofancttons qoto andoctions in
CLR paasing tahle
Tp addlonkabead oith tbe productto
Case 1A BC, a.

add 8.Dd w?6 £neSTCO 91 Jonk ohoad


Spmho
Calc A d a
hens aftea Bnathing there then look
ahtad o theprevfouupmducon i added
i ,B Da
ca se3x the pmduckinn A3a/h
add P a
b a nak ahaad of peshus
pwaluction.

Step: AdS a9nkuted pmdlution


S CC

C ac

C d
tep finaing 1iem&
S
T
s.S 3a.GtP

3aC, c-.a0, C-3ac.


6 ag alA C.4

Cdalda
SaGf Cd
4a/dpaSacyaaF

d.,ald
Panse table
State PCHfon 20to
C
S3 Sy 2

accept
2
S S 5
S3 8

S6
T3
6oSurmMariZe abou LR ponsng2
LR payse Can be Concnucdad to reoqo7t
Vactuallyall
pmgpannrnine lauqLLage Caunstnuet -or Lohich_CEG Can

LR

LR C SLRUD CLRD LnLRO)

The LR pariog metbod the most qenehal nm-bork


ocE ing SR pasing metbad nuda
2LR paTKeT_Can detecE Suntacic e t r as Soon as
pocsEhleto do SCan pLdt tn_zht
panse
pansen qammane Can dlui hes mara
than LL granomans
lsqagas
LR standi foY Lft-to-ight scaning O th tp
b Houo YACC a i l esolve the ar Sing4 QcHon Confrcs
and thea ermm accovez4
YACC
yet fnothea Compfley-Compiler. _
DE tavatlable ba the Commena_om the unfque
Sptern and as been ucd to help im imdeted
9many pomduuctionConpilexs
Yacc tramslate
Yacc hansla y

y.tab.t
ustna LACP mLthod
CCytab.c-ly Jib Conta Ina
a.Out p irq papgro
Yacc Cpeciiatton
Tanslate Yarc Compikr tab.
tob.C Cocopiler S a . O u

ioput a.0ut b u t p u b
Teating an Tlo fanllatnr h yal
declasation

translation ulo

Supporin Cneline
Yacc w-th Ambfq ous
The LALR the agoaitmmk
LOf6 neKatis unt6 acion-
passing
unlen othnuais nktaated
tha psing ackín yacc wi esplued al
. Yecdua reduta Contlkc igna the nbe
Contlict fs tvad by Chopsing sthe
ConIrc tin pncuctfon
ted onyall
s tfn yal
Spectlicabtm.
2shiPE gduce
A shifE edue LonflicE_i e3Dlveol inPavoun
thie ule e solve the Shif-t xedule
danglinq else_amhiguity_Coaneckly
The yoacc uil aetoven by
a
educinga the ewY fp
to eolue noma oasing.

You might also like