You are on page 1of 3

Co

mpi
l
erDe
sign/CS3002/
CSE&I
T/6t
h/2017

Mi
d-S
eme
ste
rEx
ami
nat
ion
S
cho
olo
fCo
mpu
terEn
gin
eer
ing
K
IITUn
ive
rsi
ty,Bh
uban
eswar
-24

Ti
me:
2hr
s Fu
llMar
k:25
(
Ans
werAnyf
iveQu
est
ionsi
ncl
udi
ngQ.
No.
1)

Q1)An
sweral
lque
sti
ons
. [
1×5
]
(a)
Defi
neaCompi
ler
.Cont
ras
tit
sfe
atu
reswi
thani
nte
rpr
ete
r.

(
b)Co
untt
hen
umbe
roft
oke
nsi
nth
efo
ll
owi
ngs
:

(
ipr
) i
ntf
("i
=%d,&i
=%x
",i
,&i
);

(i
i
)voidmai
n()
{
pri
ntf(“
Whatsup%d”
,++&&***a)
;/
*abc*/
}

(
c)Gi
venthefol
lo
win gex
pres
sio
ngr ammar:
E→ E*F| F+E| F
F→ id-F|i
d
Whataret
h epreceden
ceandas s
oc i
ati
vi
tyoft
heo
per
ato
rs*,+an
d-?

(
d)Dr
awat
ran
sit
iondi
agr
amt
ore
cogn
izeane
-mai
laddr
ess
.

(
e)Leftfactorthefol
l
owinggrammar.
r
expr → rexpr+r t
erm|rterm
rterm→r termrfact
or|rf
actor
r
factor→ rfacto
r*| r
pri
mary
r
primar→ a|
y b

Q2
)(a)Ex
plai
neac
hph
aseo
fco
mpi
l
erf
ort
hee
xpr
ess
iona:
=b+c*50. [
2]

(
b)Co n
sidert
hefol
l
owin
gGrammarwithst
artsymboA.
l [
1.5
×2]
A→( C)|0
C→C,A| A
(i
)Const
ructapar
setre
efor(
0,0)and(
0,(
0,0)
).

(
ii
)Co
nst
ruc
tal
eft
mos
tan
dri
ght
mos
tde
riv
ati
onf
ort
hes
tri
ng(
0,(
0,0)
).

Q3
)(a)
Jus
tif
yth
efo
ll
owi
ngs
. [
2]

(
i)
Lex
ical
Anal
ysi
ssh
oul
dbes
epar
ate
dfr
oms
ynt
axan
aly
sis
(
ii
)Var
iou
sphase
sofcompil
eraregr
oupe
dintopasse
sasback
endandfr
onten
d.
(
b)Whatarer
egul
arde
fin
iti
ons?Wri
teregu
lardef
ini
ti
onsf
orthef
oll
owi
ngs
:[1+1
+1]

(
i)Al
li
den
tif
ier
swi
th_ast
hef
ir
sts
ymbo
l.

(
ii
)Al
lr
eal
numbe
rswi
tho
pti
onal
frac
tio
nal
par
t

Q4)
(a)Whyi
nputbuf
fer
ingisrequi
redinl
exi
cal
anal
ysi
s?Ho
was
ent
ine
lish
andl
edi
n
pr
ocess
ingl
exe
mesduri
ngle
x i
calanal
ysi
s? [
1.5
]

(
b)Co
nve
rtt
hef
oll
owi
ngr
egu
lare
xpr
ess
ion(
a*|
b*)
*in
tode
ter
min
ist
icf
ini
teau
tomat
a.
[2.
5]

Q5)(
a)Con
struc
taDFAfort
herel
ati
onalo
per
ator
sinCl
angu
agebyc
learl
yme
nti
oni
ng
th
eretu
rnfun
ction
satt
hefi
nal
state
so ft
heDFA. [
2]

(b)
Co n
sidert
hefol
l
owinggrammar
A→aBe| cBd|C
B→ bB| є
C→ f
Writedowntheproce
duresfort
heno
nte
rmi
nal
soft
hegr
ammart
omak
ear
ecu
rsi
ve
descentpars
er.
[3]

Q6
.Gi
vent
hegr
ammar [
1.5
+1.
5+2
]

E→E+E|
E-E|
E*E|
E↑E|
E/E|
(E)|
d

(
a)Co
nve
rtabo
vegr
ammart
oun
ambi
guo
usgr
ammar
.

(
b)I
fre
sul
tof6
(a)i
sle
ftr
ecu
rsi
ve,mak
eitn
onl
ef
tre
cur
siv
e.

(
c)Fi
ndt
hef
ir
stan
dfo
ll
ows
etso
fth
ere
sul
tof6
(b)
.

(He
retheope
rat
o r
s*,-,+,and/havet
hei
rus
ual
mean
ingsan
d2↑3
=8an
dhash
igh
est
prec
ede
n c
eandisri
ghtassoc
iat
ive)

Q7
.(a)Wri
teaLEXPr
ogr
amt
oco
untt
hen
umbe
rofi
fandpr
int
fst
ate
men
tsf
romaco
de
wr
itteni
nafi
le
. [
2]

(
b)Fi
ndFIRS
Tan dFOLLOWS
etf
ort
hef
ol
lo
win
gGr
ammar
. [
1.5
×2]
(i
)S→ T;
S| ϵ
T→UR
R→ .T|ϵ
U→x |
y|[S]

(
ii
)S→aAbB|
bAaB|
cAbC|
ϵ
A→S
B→S
C→S