0% found this document useful (0 votes)
15 views25 pages

CC 3

The document discusses various parsing techniques, including bottom-up parsing and operator precedence parsing, detailing the actions involved such as shift, reduce, and error handling. It also covers the construction of transition diagrams and pseudo code for handling identifiers and numbers. Additionally, it explains the concept of Directed Acyclic Graphs (DAG) and quad structures for representing basic blocks in code optimization.

Uploaded by

omkarbunny12
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)
15 views25 pages

CC 3

The document discusses various parsing techniques, including bottom-up parsing and operator precedence parsing, detailing the actions involved such as shift, reduce, and error handling. It also covers the construction of transition diagrams and pseudo code for handling identifiers and numbers. Additionally, it explains the concept of Directed Acyclic Graphs (DAG) and quad structures for representing basic blocks in code optimization.

Uploaded by

omkarbunny12
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/ 25

BbDAe

Ddi/e
A;E/E
A {bia
E Bla

Augmente4 goammeris
IO
s'
BbDAe
BboAe
D’ Dd ; 3
II goto (Io ,s)
4
5
6 I23 goto (To.B)
E B 3B.
a 8
I3 goto(Io,bb)
B’bDAei
D ’ Od3 bla
1 bJa
14 qoto(3 .o)
BbD Ae
13:
AAe qotol 16,;)
D 0d ,albld
el;
J14 goto (11o ,o)
e;
E D ’ Did
B b DAe
eli A
A:E
albld
el;
e/;
ele,
IS: qoto(14 ,A) el;
BbA.e B, elj
B bOAe ,el:
el;
16 qoto (4,d)
LIS i goto (I2.E)
BDd; albld
It qotolTt,¬) goto(Ii2, 8)
AE , e/ qoto(L12 q) 3 19
I8: goto (I4.8) goto (I2 b) TIo
I9 gotolT4 , a) Îl6 tqoto (I2A)
Ea a/; B b DA e el;
II0 : goto( 1b) A A )E, el;
boAe el; goto (II4 ,d)16)
0 4.0d ; albl to CI14 ,¬|I)
albld go to (Lis,B|L/
Dil: gdte (Is e) goto (I is, a )"Ig
B b0 Ae. goto( Ii+,Jeio
LI2 i ge to CTES,;)
atbtt IIgoto (Ts, e)
e/; 6-bDAe.,el;
E
el; gpto (1ts, ;)u2
eli
BhDAe el;
and IIo
here .I3 |4 part
,24 and I some. Coe
IS and I|6 ane
and I a
I 8 ’ b . OAe a/bld
.

albld

I4|4; $fel:
B- 6Ae .albld
glD.d;
A’A;
el:
A’
el;
&lel;
el;
BbDAe
ISJ6 :
A A. ; E e

State Action
d
33]0
accept
2 414
SIG
414 53I0 S6
S)6 S12.

6 S13
RG R5

R&
R2
S9
13 419
R3 R3 R3
RS
SHI¾T REOUCe PARSER

Ibte is bottom up parsing method in which e


use a stack.

4 acthions used to implenent this pazser.

2.
Redu

error
&.
4.
aciept
shift achon
shiFted into stack then shift
IF input is
i6 taken.

moBches coith produchon on


". I¾ inout
in stack his production
then it is eplae coith
RHS action
this is reduce
acion ta ken.
error
ocCUTS then exextor
if erroY entry
entrg
Accept successFulo
reducing input
action
strint
is conside
IF we ave then accept
with start symbo
uce parsex for.
Construct Shift y ed
EE+E

Eid
is id tid+ id
ohexe sing
shif+
input shift
stack idtid t id Redue E’1d
+jdtid
did shift +
+id tids
shift
id t id Redu ce E’id
sE+
$Etid bjd Reduce EEtF
kids
<hift
shift
id
Reduce REid
2educe E’Ete
Acept .

S o sC a Ac
A9 bAlab
shing aaabb ccc
Stack Aectnput actio n
caebbceet aao bb cCc shift
Ga aabbccc shift
$ad abbccc sbift
Saaa bbccc shif
aqab bccc shif+
saa abb CCC Reduce 9-b
$ aaabA CCC Redluce AbA
aaoA Shit Sate
qaa Ac CC Red uce
aas
$ aasc redttshif
educe S asc
c
asC shift
S asC
aSd aAd accep
5A bAcbc
aa bbccdd
otack input Action
aa bbccdd shifh
abbccdds shiF+
daa bbccdds shitt
daab bccdds shifk
$aabb shif+
$aabbc cddd Aeduce A bc
$aa bA cddt shif
saab Ac dd A bAc
saa A dd s shift
as
sleduce saA
Shift
$ atepteduece sHasd
acept
S’ aB| bA
A’ alasl bAA
B b| bs aBB
baa bbu

asd loAd
Stac< in pu Action
baa tbas shir
qa bb at shift
Recteee A
A ba abba
shift
bba
shif
$ b aab bat
shif+
ba abb at 2educe
baa bba Redu(e Sba
B9 bs
$ baabs peduce s ag
baa B Redue
¢ bas
Aas
Reduce Sbn
bA accepE
Opesator Presidence Pazser (opp)
This i bottom: method in which we
indadte neloions between operato5.

here
oxe 3elations
< (less thon)
> (qreate thon)
Cequal to )

iS on eepression
c there is 0tb*c
beLe
hese hos highex precidence thon t.
elaton iS tK* t

-''(eaual to)
I# tuo teminds are sepoadted ty i vanriable
then use'= relatioo

- for example -
SaAb
here a ¢bb are 9epazated by A
do there is ''gelotion

also if there are adjusont terminal then ure


' melation
xample
S ’ cd
Consider
operator
presiden e
Higher
Associ
Right
LeYt
ahvihy
Intemediahe
Left
Lower
Lowest Non
unary
along with this precidencens
id aan identHfier has higher
all
has lower precladence of
C

id >c
opp for t , - * l T , id
drdw
id
< <
<
<

7
eY <
<
< erro
qiven steps to check opp (no+
,.frding lending trailing of all oriales.
,.And al pairs Such that a terminadl followed
Waoidble Vaiabe tolloued by terminal: and
by step 00.3
apply

3if pair iS Et + then


Trailing (E) >
+T then
< leading CT
table.
4.doao opp

&. (Üite doon esult

Note -
1f ther e ane more than d entries io one cell
then grammer is not opp

" Lending (A) ’ Aaj where Aaap where


d may be ang vamables
"Troili ng (A) ’ fa} oheve A daB lwhere

B may be any ayiables (e


0. find leacding g TsailingLending (s) :fa,b c.ef
Leadtng (P) =( bi Ciej
R ’ c 5d /e Ceoding (e) 1 ,ej
Trailirg CS) =faib d ,es
Trailíng CP) d
TruilimM(R)=
T
Asub,Supic?
’E Sabf sup
E sub ¬
subsup, trc} {sup sub

. sao CEG foy


E E+T /T
Leading
T T*F/E

id
<
<
<
7
id 7
<

draw opp fo
+ s /ss /id
Leading
t,ids
Trailin
J st 2)ts 3) s , 4) *s s) $$ s 6)
id

7
<

Not
11 Cs) /ala
Leading
2) T 3)CS
4)s ) s) $ 6)s
a

7 <

7
7@
<
77
L +RIR
Leading
Kt,id?aaj Troiling
Que.

LI+* ab

1d

b
7

not Opp
frs
code.
and Pseudo
digrorrs
Transition

2 idenifers
3 number
4Telotioral cperatozs
lor keyo
Fa
draw Trarnsiton diagam(d
(f else )

Ele
ele
L/1
slsa identifers.
transition diagra m fo
Que dvaw letter"aiglt

gue. daw TD or num bers syGlem:


yoiem
Numbe Numbes
(92)

Que daLw TD for melaton cperators

4
()
Pseudo code for kwid mTelahond operato.

sedu code folooing


>qetcha C);
funcion
o6 is Used to cssign a
pich wil be to a vasidblevdlue Of character
2)etun c);
his funchon is used to indicate
is Teturn at patHcular a value ohich
otate.
37 esrorC)a
this is used to shou eT0 entries
4) Yetra ctC)i
this is used to
indicate that a particular state is
Pinal state

(Onie pseudo code for keyoords Cif-else)


Pl
|Ele
S/s E/e wS
(4 as)

Stdte qo
C qetchar C)
then
goto staFe a|
else if Ele the
then gote state q4
Stale C-getchar)
ql

goto Stte q2

ese errorC)

State q2
c getcharc)
as/delimeter!
FCe = getchrf (

then
goto stahfe q3
else
erYoYC)
state 93
retraCHC)
ehurn (teyoond LE);
o ldenHfier'sletHer/
tettey digit

stak 40
getchar c)
C= lettey the
oto 91
else

stale qi cgetcharh
ite c 'lefes ldigiF Fhen
goho stat q2
elre
errocO
stak 92
retsact

Pseado
q
TehivnChdenhEi
code for nUmbe
er)
Numi Numbe
(90,
92)
Gtate qo

IF
gtchax();
C NumbeY then goto state a)
else
erorc))
cgetchen),
if C Numbe
else i Ci US
qoto Shate q1

eseractc);
Tetuonlumber:
a keudo code for elaion
Directed Acyclic Graph

)
(address cocde
In this block 3
we have
to
epresen+ qiven bosi,
given graphical form
bloclk into

2) TI BCi)
T1 : B * C

TI

draw OAG or

T2 CCi]
T3
T4 T2- T3
TS T2*T4
T6

by opplying Commn sub expression we


get
T6 T
TS

T4

)T3

T,16

Que A
Gd

Ct G

BT6

Q.
ts T¢
12- a+T1
T3 = e1
dt T3
Te:tT4
T3 t TS
FAG
Oue. praw OA G. for
given
basicbloclk n0t
Jn this case fo the give n exo
quadsaples Fo
we Constouct
erpes
columns opeTato
A Quadsa ple has 4 esultname
Opesanti operand2

3 eetm structure
Toiples has
operatcN Oberond operand: 2

irst we desiqn basie block


operator oprandi opesande esut.

A TI

T3
T3

TS

13 ^G
J3
ts
T6
T t TS
T2
TS

(4)T2
T3

Que a-b

a-TI d e AtA

T2-d *e aFNq
T2- d e A T3

T2-d T4
TS

opexato opeBandt operond2. oejul L


b
TI T2
T3
T3
d TS

T2 TS T6

e
Cat ) t Carc)
caw JAG fo
bt
nesult T2 t Catcod
o pe Opl 6p? TI
C

b
T3
cd T4
T3
TS
T4

T2

(+ TT3

S2]yt (ytx)/Cx-2) *(e-2)


oper op1 op2
X y+51/T2
X 2 T2
TY
T2 T3 TS
2

T TS
T6

TS
ivected fination
De
ynlax Csoo)
opimization technique
This is Code steps used
To dadw spp olloing
1. oite Symentic ondlyss expYession
fox given numnenical
2 coaw SDp
daaw spp fo

¬ ’ EtE
EEtE
E(e)
E id

Fyst (e convert iven cfainto symentic for


Rule lopexotion Symentic Rule

E e*E E-val- Eval y Eva


Erval- (E-val)
E’id C-val ’ idlexval

Eval S09

Gyal E-vSo0

lexual E-ualSo
idvalz0 dlvg1'so
¬t E/ E E /id

E val : 79

E.val=?t Eval =s
Eval: 9 idlv=s
id.luzg jd.lv:g.
EtT/T

E’E+T
E-vdl ||4

Eval g
E id tT

E’ id t id id Aual:9
id.luzg
E+T

E ’ jd *id tr
e d *jd t id

+
EsUal. 6o T-val. I3

T:val: 2 Fl Fval 19
Fval >(2 Jd.luzs ld-lu13

jd.lu=12
.g) E ’ TE!
El + JE/
G TE
E’TtIE
Ce) 7id

t id +&jdid e
Bal49

Erval
Fval g +
Eval=8 T).val:4o
jd-lu g T}val
id.lw * Eval:
/5
jd.lv

You might also like