Acd Asaign2
Acd Asaign2
B> A?|S
F ’E
Elimination of left xecurssion:
qrammar production is in the form A-A|B
lhen the
ew non- termina A' the follooing
y inbroducinga by means of Moore's proposal
produchions re included
A->BA'
Alheve,Aj’xd<k
eliminate left recuYssion omon Ai production
F’(e)lid
A-eft Recuyssion!
A CFG is called lefi
xecuYSsion if a NI has a
left most symbol appears
alternative ls at the tme cf
deiyation eithex iynmediatelý Ccallecd dixectleft
thoough some clher NI definition (indiyect le p4 xecuYSsion)e
YeLurssiÝn)
Dixect left ecunSsion
A B
top pases
A
Siack
Fredictive pansex that is YeCUISS0ve descent parser nedinn
no back tyacking,an be constyucted for a class of qiamm
Called
1. The fyst ' ' in LL6) stands for scannin ilp Brôm
Left to ight The second Stands for heft most
deivation
for using one ip sumbol of Look abead at
each step to make parsing acion decisions
No left xecsive CoY) ambiqus qxammar an be LLC)
ÇYamnmmr ç'of LLG) if and onls if tuhenevex
A’JA ane this & disinct oduchions of qhe
follauing Conditions hold
1. FoY no terminal `a' do both
&EBdexive sbigs
beginning with A
aAA most one of aEB can dexie Hhe empa
a 8 B’E, then_ ß does not shing
derive any shing baginning
toi th termina in FolLOlwCA), like
uuise if < then Bdees
not dexive ans shing beginning aitha
texminal in FOMO[a)
Construcion of a paecictive parsing table:
Input - (yammar G
Output- pcase table 'M!
MeodFor each pxoluctionA of tk ammaY do
the follouing
FoY each
teminal a' in
|2
MCALa FIRSTC)add A’x to
J t ' is in FRSTC«), then for
in FoIOIN CA), add a each tesminal b'
Sf E is in FIRST Ax to M[A,b].
Ca) and in FOHOW CA), add
A>x to MA,$J aS well.
3f afte peofox M0nq the
at all in above thexe is no pacduchon
MA,a] then set M[ia] to
|depyesented by an empty enty in the talble)eyxoYCwhich noxmally
Procedune to construct LC) panse table:
Step1 Ihe qamar should not e left
LAmaiqus. xecurSsiCn (ox)
Stepa: alculate FIRST and FoLQal foY
Stepa consbuct a paxse table with non-Ne CuTSi ve qiamma
where noo NTOrexe tupleS. No-of
teYminals non-TmmAas
texmiAals_anc attibute
Stepu: EIL Hhe table using fhe procedure for COnshuchion of
pxedichive paxse table.
Problem!
Step 1' Eliminate eft secuassi&n fom Qammax
)E’E+1T
aftex eimination of left YeCuaSSin
E’+TEle
atex eliminaion of left
let ecuY SSi oY
T'ET'
E’ +Els
TET
FCe)lid
Step-a Calculate FIRST and FOM0
FiRSTCE)=CGd?
FIRST(T) ={*,s
FIRST (T)- FIRSTCF) -= iGid
FIRST (E)= {+st
EIRST CE] = FIRSTCT) = iGid?.
FonOk CE) = Follo (E) -{J$i
FOIJOC) EOllOW ):
ParseTable
id $
ETE' T
TTFTTFT'
T'
F >(¬)Fid
A’Aa
A>a
6b) Conchruct the LRlo) ikens fox the folloucing Gyammar
S>R
L’id
R>
A: PYoeduye to Construct LRO
Step 4: fonm the Auqmented quammar by dding
auqmented production.
Sepa: Inseit C)dot symbol to the Auqune ntal paadac on
Step 3: Ccnsbruct item6 by taveasing the do operator
in the poduction . Whadot is available Gefoxe NI,
appy clasure oparalion: cf maing the do
means
bypoduction.
Stepl Perfom goto opation
the
opeatox to next position to foy the Consbuchien
Step5: exform thc dataflow diacpam
items.
the tablestate, Action and columms and
Step.6: onstuct based on
divided
GoTo fuYther acion andGoTO aYe
tanninals_ non-temiale xespecively
nunbeig to the paoduction as RiRe to Rn.
Step: Give
Fox all the paduchon giuen in the qammar- Rstands fo
xeduce
Step8! Aciane amd GoD ae filled with state ame and ilp where
when teminals are tavezsed Shift opaxatos ae peafoymed when
NT taeed they aYe Rlled oibh item humbey The xeduce function
is fled foY Hhe item belouw,T where the poduchon s competels -
TYavetsed
Dataflos Dioqom:
Soution:
l *R
Cata flow Diaqpam:
s’s.
L
To
RL. Sl-R.
RL
S ’l-R L*R
S’R. |Lid
R
R L-*R"
R
L’id
T6 id id
Lid
Accept
Su S5
5
6 Ss S5 8
Y
Construct pasig table fox the qiven grammar
CLR pmcing
CaCld
A: Proceduve !
amay
Step-11 Iaiting Augmernted collection
of LRO) of canonical itene
Step-2: Finding
Step-3 Defining the tuo fumctions G0T0 ACTION in Hhe
CLR panse talole, He yeduchion is placed inM Look Ahaod
Symbal field'
Procedue to find Canonical Stems :
The camonical item is smilar to item tuheYe loak ahead sum
J
added topoduchicn,
Case 1
C>d
then B Did wtth FIRSTC) as lookahed.
Cace S:AdBcia
if B’D
S'’S$ Is
I
s'->-S,4 S->C-C
C->ac..
S’"CC,$ C->"aCf
C>-al,ald C>"do
I3
C’ *dald
aC,alda IB
c-dald
CLR- Ponce Table
ACTION GOTO
States
d C
I
2
S Su
accept
2 Se S4 5
S3 Sy
A: Paocedure:
l: zite augmented qrammar
9. To_ find canonical items for the qammAY
3: Defining 8 functions GoTOE_ACTION In cLR Parser
SAme
h. From_ CLR Conshruct LALR puser lby Combin
ttems with diffenent lokaheod
Solation: s'>s
S>AA
AaA
A’b
sS$
S>A-A. ASAA:,$
97 A aA$
A-bi |A’.aA,s A->aA$
S-’ AA,
foAaA,atb |A’b$
AaA,albl A>aAalb Ab$
A’-bi alb |A-b,alb aA
AaAa]b|
Abatb
Su
CLR-Pase Table
ACTIDN GOTO
STATES
A
I
2
S3 Sy
hccept
S
S6
Sy
5
6 S4
In the above CLR table the items of I3 and Is
ne similax Loith diffesent lcok ahead- Simillaxly
Ty and T4 , Tg and T9 .
as:
|Based on this the cLR table is modtfied
LALR Parse Table!
ti:= b+c
ta: t+d
ai= t
Implanentacion of thmee addve ss code :
’Thee addaess Code is an abstact fom of TC that
lcan be implernanted as an 3ecoyd with thc
addegs fecls
It has 3 epesentations:
)Quadruples:
z addzess code the insuchion doesn't speciy
Hhe zepsesentation of them in the data structure Jn
Compiles these insbucion can be implemented as object
(ox) as xeCox ds uith feels fox the opesator and opezands
Aquadzuples has u fkds, which 0e call opezand, arqument
1, nqument &TeSult
) Tiples
Sn this xepresertation it has onls 2fáds fre lds
opexatox arqument1, axqument a
) Sndinect triples
This consists of listing of poíntess to tipks, 3ather
Hhan aa listing of by themselves.
10)Produce quaduple,triples and indizect tipls for follouwing
exprecsion: aty)* Cy*z)+ (xy+z)
A:Three- addyesG code:
In Three -addyess_code foYM the most thyee -addess ane
used to Yepresent any statement
An addyoss can be a nam, a Constant and a compilez
genexated tempoxavy general vaviable.
Geneyal foYm a:bc
each instruction should contain at most and at most one
opesatoy in RHS