Compiler Design Lesson Plan 7th
Compiler Design Lesson Plan 7th
Compiler Design Lesson Plan 7th
LECTURE PLAN
SYLLABUS AS PER M.D. UNIVERSITY B.TECH (CSE) - SEMESTER VII SUBJECT: COMPILER DESIGN SUBJECT CODE: CSE-405 E
Unit1: Introduction To Compil r!: Compil r! "nd tr"n!l"tor!# n d o$ tr"n!l"tor!# !tructur o$ compil r :it! di$$ r nt p%"! !# Compil r con!truction tool!&
Unit': L (ic"l An"l)!i!: Rol o$ l (ic"l "n"l)* r# d !i+n o$ l (ic"l "n"l)* r# r +ul"r (pr !!ion! # Sp ci$ic"tion "nd r co+nition o$ to, n!# input -u$$ rin+# A l"n+u"+ !p ci$)in+ l (ic"l "n"l)* r& .init "utom"t"# con/ r!ion $rom r +ul"r (pr !!ion to $init "utom"t"# "nd /ic / r!"# minimi*in+ num- r o$ !t"t ! o$ D.A# Impl m nt"tion o$ l (ic"l "n"l)* r& Unit0: S)nt"( An"l)!i!: Rol o$ p"r! r!# cont (t $r Unit1: P"r!in+ T c%ni2u : S%i$t- r duc pr dicti/ p"r!in+& +r"mm"r!# d $inition o$ p"r!in+& p"r!in+# top do3n p"r !in+#
p"r!in+# op r"tor pr c d nc
Unit4: LR p"r! r!# SLR# LALR "nd C"nonic"l LR p"r! r& Unit5: S)nt"( Dir ct d Tr"n!l"tion!: S)nt"( dir ct d d $inition# con!truction o$ !)nt"( tr !# !)nt"( dir ct d tr"n!l"tion !c% m # impl m nt"tion o$ !)nt"( dir ct d tr"n!l"tion# t%r "ddr !! cod # 2u"drupl ! "nd tripl !& Unit6: S)m-ol T"-l 7 Error D t ction And R co/ r): S)m-ol t"-l !# it! cont nt! "nd d"t" !tructur $or !)m-ol t"-l !8 tr !# "rr")!# lin, d li!t!# %"!% t"-l !& Error!# l (ic"l p%"! rror# !)nt"ctic p%"! rror# ! m"ntic rror& Unit9: Cod Optimi*"tion 7 Cod G n r"tion: Cod + n r"tion# $orm! o$ o-: ct! cod # m"c%in d p nd nt cod # optimi*"tion# r +i!t r "lloc"tion $or t mpor"r) "nd u! r d $in d /"ri"-l !& T (t ;oo,!: < Compil r! Principl # T c%ni2u ! 7 Tool! - Al$r "d =& A>O# R"/i S t%i 7 ?&D& Ullm"n8 1@@9Addi!on A !l )& < Compil r D !i+n -) O&G& B",d # 1@@4# L"(mi Pu-l& R $ r nc ;oo,!: < T% or) "nd pr"ctic o$ compil r 3ritin+# Tr m-l") 7 Sor n!on# 1@94# Mc& Gr"3 >ill& < S)!t m !o$t3"r -) D%"md" # 1@95# MG>& < Principl ! o$ compil r D !i+n# N"ro!" Pu-lic"tion Not : Ei+%t 2u !tion! 3ill - ! t in "ll -) t% ("min r! t",in+ "t l "!t on 2u !tion $rom "c% unit& Stud nt! 3ill - r 2uir d to "tt mpt $i/ 2u !tion! in "ll&
INDEX
Sr. Contents 1 Focal Points in Lesson plans 2 3 ! & ) * + 1, 11 12 Syllabus as per M. D. University Teaching Methodology Teaching Plan
"e#erence boo$s % online sites #or help
'ssign(ent Details 'ssign(ents Se(inar Details Se(inar -oo$s re#erred #ro( Library 'ttendance Sheets Monthly "eport
'
13 1 1! 1&
MERI - CET DEPTT. OF COMPUTERR SCIENCE (B.Tech) F c!" P #$%& #$ Le&& $ '"!$
T% r mu!t - ) cont"ct 3it% / r) Stud nt in cl"!! room 3%il t "c%in+ t% m& Moti/"t t% !tud nt !o t%"t t% ) "cti/ l) p"rticip"t in cl"!! room 3it% l ctur r& .ir!t o$ "ll pr ! nt t% $r"m 3or, o$ t% topic& R /i 3 t% ,no3l d+ "-out t% topic 3%ic% 3 %"/ di!cu!! d& A$t r compl tion o$ "c% unit# not onl) t% "!!i+nm nt! 3ill - +i/ n t !t! 3ill "l!o - t", n& A$t r d li/ rin+ t% l ctur "!, "ll t% 2u !tion! r l"t d to topic "nd "!, $or t% ot% r ("mpl ! !tud nt! mi+%t ,no3& All t% num ric"l r l"t d to t%"t topic 3ill - !ol/ d out -) t% l ctur r on A%it ;o"rd& R /i!ion l ctur $or "c% unit %"! - n pl"nn d& Lin,! $or onlin !tud) m"t ri"l $or "ll import"nt !u-: ct! %"/ - n "dd d& Lin,! $or r !p cti/ !u-: ct! %"/ "l!o - n includ d&
TE(CHING METHODLOG)
S*+,ec%: COMPILER DESIGN S*+,ec% C .e: CSE-405 E B-!$ch: CSE Se/e&%e-: VII
EV(LU(TION ; !id ! t% ! m !t r nd ("min"tion# t% !tud nt! 3ill - continuou!l) "!! !! d durin+ t% cour! on $ollo3in+ -"!i!: S. $ . 1 ' 0 1 De&c-#'%# $ Mid t rm ("min"tion! Int rn"l "!! !!m nt DA!!i+nm nt E Att nd"nc F Cl"!! p r$orm"nc End ! m !t r ("min"tion T %!" M!-1& .#&%-#+*%# $ 'C 'C 1C 1CC 250
TE(CHING PL(N
S*+,ec%: COMPILER DESIGN S*+,ec% C .e: CSE-405 E B-!$ch: CSE Se/e&%e-: VII T %!" N . 3 Lec%*-e&: 50
De%!#"e. C *-&e O*%"#$e Unit1: Introduction To Compil r!: Compil r! "nd tr"n!l"tor!# n d o$ tr"n!l"tor!# !tructur o$ compil r :it! di$$ r nt p%"! !# Compil r con!truction tool!& Re3e-e$ce& ?&D& Ullm"n C%"pt r 1 O&G& B",d C%"pt r 1 Unit': L (ic"l An"l)!i!: Rol o$ l (ic"l "n"l)* r# d !i+n o$ l (ic"l "n"l)* r# r +ul"r (pr !!ion! # Sp ci$ic"tion "nd r co+nition o$ to, n!# input -u$$ rin+# A l"n+u"+ !p ci$)in+ l (ic"l "n"l)* r& .init "utom"t"# con/ r!ion $rom r +ul"r (pr !!ion to $init "utom"t"# "nd /ic / r!"# minimi*in+ num- r o$ !t"t ! o$ D.A# Impl m nt"tion o$ l (ic"l "n"l)* r& U$#%45: S6$%!7 ($!"6&#& !$. P!-&#$8 Tech$#9*e: Rol o$ p"r! r!# cont (t $r +r"mm"r!# d $inition o$ p"r!in+# S%i$t- r duc p"r!in+# op r"tor pr c d nc p"r!in+# top do3n p"r !in+# pr dicti/ p"r!in+& Unit1: LR p"r! r!# SLR# LALR "nd C"nonic"l LR p"r! r "nd S)nt"( Dir ct d Tr"n!l"tion!: S)nt"( dir ct d d $inition# con!truction o$ !)nt"( tr !# !)nt"( dir ct d tr"n!l"tion !c% m # impl m nt"tion o$ !)nt"( dir ct d tr"n!l"tion# t%r "ddr !! cod # 2u"drupl ! "nd tripl !& Unit4: S)m-ol T"-l # Error D t ction# Cod Optimi*"tion 7 Cod G n r"tion:: S)m-ol t"-l !# it! cont nt! "nd d"t" !tructur $or !)m-ol t"-l !8 tr !# "rr")!# lin, d li!t!# %"!% t"-l !& Error!# l (ic"l p%"! rror# !)nt"ctic p%"! rror# ! m"ntic rror# Cod + n r"tion# $orm! o$ o-: ct! cod # m"c%in d p nd nt cod # optimi*"tion# r +i!t r "lloc"tion $or t mpor"r) "nd u! r d $in d /"ri"-l !& T %!" N . 3 Lec%*-e& ?&D& Ullm"n C%"pt r 0 O&G& B",d C%"pt r ' ?&D& Ullm"n C%"pt r 1 O&G& B",d C%"pt r 0# 1 ?&D& Ullm"n C%"pt r 1# 4 O&G& B",d C%"pt r 4# 5 ?&D& Ullm"n C%"pt r 1C O&G& B",d C%"pt r 6# @# 1C 4C 1C 14 N . 3 Lec%*-e& 1C
(SSIGNMENT DET(ILS
S. N .
(&$/e$%
'
S p C5# 10
S p10# 10
S p 'C# 10
S p 'C# 10
S p '6# 10
Oct C1# 10
Oct C1# 10
Oct 11# 10
Oct 19# 10
Oct 19# 10
Oct '4# 10
No/ C1# 10
No/ C1# 10
No/ C9# 10
No/ 11# 10
(SSIGNMENT - 2
S*+,ec%: COMPILER DESIGN S*+,ec% C .e: CSE-405 E B-!$ch: CSE Se/e&%e-: VII
S*+/#%%e. % : M-.0.D#'*
A!!i+nm nt +i/in+ d"t
Au+ '0# 10
1& D !cri- di$$ r nt p%"! ! o$ " compil r 3it% t% % lp o$ " n "t di"+r"m&
'& A%"t "r !)nt"( tr !H >o3 t% ! c"n - con!truct dH 0& Di$$ r nti"t - t3 n p%"! "nd p"!! o$ " compil r& 1& ;ri $l) (pl"in t% t rm ICompil r 3ritin+ tool!J& 4& A%"t do )ou m "n -) cro!! compil"tionH ;ri $l) (pl"in& 5& A%"t "r "!! m-l r# compil r "nd int rpr t rH >o3 t% ! "r r l"t d to "c% ot% rH 6& Di!cu!! t% l (ic"l "n"l)!i! p%"! o$ t% compil r 3it% t% % lp o$ "n ("mpl & 9& A%"t do )ou m "n -) " tr"n!l"torH E(pl"in "n) t%r @& Di!cu!! "n) t3o pro-l m! 3%ic% "r 1C& A%"t "r t% c%"r"ct ri!tic! o$ " +ood tr"n!l"torH c"t +ori ! o$ tr"n!l"tor& ncount r d durin+ cod + n r"tion&
(SSIGNMENT - <
S*+,ec%: COMPILER DESIGN S*+,ec% C .e: CSE-405 E B-!$ch: CSE Se/e&%e-: VII
S*+/#%%e. % : M-.0.D#'*
A!!i+nm nt +i/in+ d"t
S p C5# 11
1& D !cri- "l+orit%m to con/ rt ND.A into D.A& '& Con!truct " $init "utom"ton "cc ptin+ t% ! t o$ "ll !trin+! o$ * ro! "nd on !8 3it% "t mo!t on p"ir o$ con! cuti/ * ro! "nd "t mo!t on p"ir o$ con! cuti/ on !& 0& A%"t i! t% import"nc o$ l (ic"l "n"l)* r in " compil rH 1& A%"t ! t! to !trin+! do t% $ollo3in+ R&E'! d !cri- & iF iiF K" -L K-G"L di+it Kdi+itLG M DCG'G1G5G9F 3% r di+it r pr ! nt! CG1G'G NN G@&
4& A%"t i! m "nt -) input -u$$ rin+H >o3 i! it u! $ul in d !i+n o$ l (ic"l "n"l)* rH 5& Arit t% "l+orit%m to minimi* t% num- r o$ !t"t ! in " D.A& Appl) t%i! "l+o to minimi* t% !t"t ! o$ t% $ollo3in+ D.A: S%!%e S%!-% A ; C D E ! ; ; ; ; ; I$'*%& + C D C E C
(cce'%
6& A%"t "r R +ul"r (pr !!ion!H Di!cu!! t% proc dur 3it% ("mpl con/ r!ion o$ r +ul"r (pr !!ion into $init "utom"t" "nd /ic -/ r!"& Al!o di!cu!! %o3 to minimi* t% num- r o$ !t"t ! o$ " D.A& 9& E(pl"in t% !)nt"( dir ct d tr"n!l"tion !c% m $or d !, c"lcul"tor& Al!o !%o3 t% ! 2u nc o$ mo/ ! -) p"r! r $or t% input !trin+ 0CG4E1O& @& E(pl"in t% !)nt"( dir ct d tr"n!l"tion !c% m $or d !, c"lcul"tor 3%ic% p r$orm! E# P op r"tion! o$ !impl d"t" t)p & Al!o comput '0E4P14O& 1C& Gi/ " p"r! tr $or t% input !trin+: i E i Q Di P iFR
(SSIGNMENT - 5
S*+,ec%: COMPILER DESIGN S*+,ec% C .e: CSE-405 E B-!$ch: CSE Se/e&%e-: VII
S*+/#%%e. % : M-.0.D#'*
A!!i+nm nt +i/in+ d"t
S p 'C# 10
1& A%"t do )ou m "n -) " p"r! tr H >o3 i! it dr"3nH E(pl"in 3it% !om " p"ir o$ t rmin"l! " "nd -&
("mpl &
'& D $in op r"tor pr c d nc +r"mm"rH >o3 op r"tor pr c d nc r l"tion! "r d $in d $or 0& A%"t i! " Top-Do3n p"r! rH Con!id r t% +r"mm"r S -S "S"G""& ;) tr"cin+ t%rou+% t% !t p! o$ " top-do3n p"r! r# 3%ic% tri ! "lt rn"t "S" - $or ""# !%o3 t%"t S !ucc d! on '#1 or 9 "T! -ut $"il! on 5 "T!& 1& A%"t do )ou und r!t"nd -) "m-i+uou! +r"mm"rH >o3 "m-i+uit) c"n - r mo/ dH E(pl"in 3it% ("mpl & 4& A%"t i! int rm di"t cod H A%"t int rm di"t cod ! "r u! d in compil r!H E(pl"in& 5& A%"t do )ou und r!t"nd -) " %"ndl H E(pl"in t% !t"c, impl m nt"tion o$ !%i$t r duc p"r! r 3it% t% % lp o$ ("mpl & 6& A%"t i! " cont (t $r +r"mm"rH Au+m nt d +r"mm"rH A%"t "r t% pro-l m! t%"t m") occur durin+ p"r!in+ o$ t% ! H Di!cu!! t% d t"il 3it% "n ("mpl & 9& E(pl"in pr dicti/ p"r! r& Al!o (pl"in !%i$t r duc p"r!in+& @& A%"t "r 2u"drupl !# tripl ! "nd indir ct tripl !H Gi/ 1C& E(pl"in r cur!i/ -d !c nt "nd pr dicti/ p"r!in+& ("mpl !&
(SSIGNMENT - 4
S*+,ec%: COMPILER DESIGN S*+,ec% C .e: CSE-405 E B-!$ch: CSE Se/e&%e-: VII
S*+/#%%e. % : M-.0.D#'*
A!!i+nm nt +i/in+ d"t
Oct C1# 10
1& Arit t% "l+orit%m $or con!truction o$ SLR p"r!in+ t"-l & Arit t% ! t! o$ LRDCF it m! $or t% +r"mm"r EUEETVT TUTP.V. . U DEF T U id '& S%o3 t%"t t% $ollo3in+ +r"mm"r S U A"G-AcGdcG-d" AUd I! LALRD1F -ut not SLR D1F& 0& Con/ rt t% r +ul"r (pr !!ion D"E-FP"-"D"E-FP into t% corr !pondin+ D.A& 1& Con!id r t% +r"mm"r S U DLF V " L U L# S V S "F A%"t "r t% t rmin"l!# non-t rmin"l! "nd !t"rt !)m-olH -F .ind p"r! tr $or t% $ollo3in+ ! nt nc !: iF D"#"F iiF D"# DD"#"F#D"#"FFF cF Con!truct " l $tmo!t d ri/"tion $or "c% o$ t% ! nt nc ! in D-F "-o/ & 4& E(pl"in t% $unction o$ LR p"r! r!& Gi/ "l+orit%m $or con!tructin+ SLR p"r!in+ t"-l & Al!o con!truct t% SLR t"-l $or +r"mm"r: W UW ET W UT T UTP. T U. . U DWF . U id 5& Arit 2u"drupl !# tripl ! "nd indir ct tripl ! $or t% -D" E -F P Dc E dF D" E - E cF (pr !!ion:
1C
6& Con!id r t% +r"mm"r S U " V X V DTF T U T# S V S .ind t% ri+%t mo!t d ri/"tion $or D"#D"#"FF& 9& Con!id r t% +r"mm"r S U " V X V DTF T U T# S V S S%o3 t% !t p! o$ " !%i$t-r duc p"r! r $or t% ri+%tmo!t d ri/"tion& @& Con!id r t% +r"mm"r E U TET ETU E TT V E T U .TT TTU P .TT V E .U DEF V id Comput .IRST "nd .OLLOA $or "c% non-t rmin"l o$ "-o/ +r"mm"r& 1C& Con!truct " p"r!in+ t"-l $or "-o/ &
(SSIGNMENT - 5
S*+,ec%: COMPILER DESIGN S*+,ec% C .e: CSE-405 E B-!$ch: CSE Se/e&%e-: VII
S*+/#%%e. % :M-.0.D#'*
11
1& E(pl"in in d t"il l"- lin+ "l+orit%m u! d in cod + n r"tion& '& A%"t "r t% cont nt! o$ " !)m-ol t"-l H Gi/ " -ri $ d !cription o$ "c%& 0& >o3 !)m-ol t"-l !p"c c"n - r -u! d& Gi/ !om 1& A%"t "r !)m-ol t"-l !H E(pl"in t% ir !i+ni$ic"nc & 4& Arit " d t"il d not on rror d t ction "nd r co/ r)& 5& Arit "-out cod optimi*"tion& 6& A%"t i! m "nt -) r +i!t r "lloc"tionH A%) i! con!id r d to - import"ntH 9& A%"t do )ou m "n -) p p%ol optimi*"tionH A%"t "r t% "r "! 3% r it c"n - "ppli dH @& A%"t i! t%r pro+r"m!& 1C& Arit !%ort not ! on t% $ollo3in+: "F -F Pro-l m! in cod + n r"tion R +i!t r "lloc"tion "nd r +i!t r "!!i+nm nt "ddr !! cod H Arit "n) $i/ common ,ind o$ t%r "ddr !! !t"t m nt! $ound in ("mpl &
(SSIGNMENT - =
S*+,ec%: COMPILER DESIGN S*+,ec% C .e: CSE-405 E B-!$ch: CSE Se/e&%e-: VII
S*+/#%%e. % :M-.0.D#'*
A!!i+nm nt +i/in+ d"t
No/ C1# 10
1'
'& Arit t% "l+orit%m $or con!truction o$ SLR p"r!in+ t"-l & Con!truct t% SLR p"r!in+ t"-l $or t% +r"mm"r& EUAETVT TUTP.V. . U DEFGid 0& A%"t i! di$$ r nc - t3 n rror r p"ir "nd rror r co/ r)H A%"t o$ t% "d/"nt"+ ! o$ rror r p"ir o/ r rror r co/ r) do )ou con!id r mmo!t import"nt: iF to )ou p r!on"ll)& iiF to (p ri nc d pro+r"mm r!& iiiF to no/ic pro+r"mmin+ d t"il!& E(pl"in 3%)H 0& E(pl"in In!truction /"ri"-l ! "nd $orm! o$ o-: ct cod & 1& Con!truct " DAG $or t% $ollo3in+ -"!ic -loc,: D :Y ; P C E :Y A E ; ; :Y ; P C A :Y E D 4& A%"t "r t% di$$ r nt t)p ! o$ rror! t%"t c"n occur: A%"t r m di"l "ction do ! " compil r t", in "c%H 5& Arit " SCANNER $or .ORTRAN t%"t u! ! loo, "% "d to d t rmin t% n (t to, n& U! "n input -u$$ r& 6& Comp"r t% c"p"-iliti ! o$ cont (t $r +r"mm"r! "nd r +ul"r (pr !!ion!&
9& Arit " top-do3n tr"n!l"tion !c% m to produc 2u"drupl ! $or ;ool "n E(pr !!ion!& @& Di!cu!! rror r co/ r) in op r"tor pr c d nc p"r!in+& 1C& A%"t do )ou m "n -) induction /"ri"-l H E(pl"in t% proc !! o$ induction /"ri"-l limin"tion&
10
SEMIN(R DET(ILS
S*+,ec%: COMPILER DESIGN S*+,ec% C .e: CSE-405 E B-!$ch: CSE Se/e&%e-: VII
S. N . 1 ' 0 1 4 5 6 9
T '#c
G- *' >R ""$ ?#&e@ 1-1 4-9 @-1' 10-15 16-'C '1-'1 '4-'@ 0C-01
P- ' &e. D!%e Au+ '5# 10 S p '# 10 Au+ @# 10 S p 15# 10 S p '0# 10 S p 0C# 10 Oct 6# 10 Oct 11# 10
Compiler and translators Lexical analysis Syntax analysis and parsing techniques Di erent !arieties o parsers
Impl m nt"tion o$ !)nt"( dir ct d tr"n!l"tion
11
Oct '1# 10
14