cd question bank part a

Upload: richa-agarwal

Post on 04-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 CD Question Bank PART A

    1/5

    kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk06kCSk63k:kCOMPILERkDESIGNkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkQUESTIONkBANKkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkPARTkAkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkUNITkIkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkIntroduction,kLexicalkAnalysis:k

    k

    OBJECTIVE:kThiskunitkdiscusseskaboutkdifferentksystemksoftwares,kthekstructurekofkcompilers,klexicalkanalysis,kaklexer,k&kto ens.k

    1kWhatkareklanguagekprocessors?k

    2kBrieflykexplainkakstrategyktokreducektheknumberkofkpasses.kk

    3kBrieflykexplainkthekfollowingk:k

    i)kLEXk

    ii)kYACCkk

    4kWhatkiskthekneedkforkakmultipasskcomplier?kExplain.k

    5kDistinguishkbetweenkakphasekandkakpass.k

    6kWhatkdokyoukmeankbyksyntactickanalysis?kDiscuss.k

    7kDiscusskinkdetail,kthekevolutionkofkprogrammingklanguages.k

    8kDefinekinkdetailkthekvariouskcompilerkkconstructionktools.k

    9kConsiderkthekstatementkgivenkbelow.k

    WhilekXk>kYkandkXk=kY3-6kdok

    X:k=kXkYk

    Forkthiskstatement.kGivekthekoutputskafterkeachkofkthekfollowingkphases.k

    ki)kLexicalkanalysisk

    kii)kSyntaxkAnalysisk

    kiii)kIntermediatekcodekgenerationk

    kiv)kCodekoptimizationk

    10kExplainkwithkthekbloc kdiagram,kdifferentkphaseskofkakcomplier.k

    11kBrieflykexplainkthekneedkofkmultipasskinkakcompiler.k

    12kExplainkinkdetailkaklanguagekkprocessingksystem.k

    13kWhatkdokyoukmeankbyksemantickanalysis?kExplainkinkdetail.k

  • 7/31/2019 CD Question Bank PART A

    2/5

    14kExplainkinkdetailkthekanalysiskksynthesiskmodelkofkcompilation.k

    15kExplainkinkdetailkthekintermediatekcodekgenerationkphase.k

    16kDiscusskaboutkvariouskissueskofklexicalkanalysis.k

    17kWhatkiskmeantkbykinputkbuffering?kExplainkthekbufferkpairskschemekforkrecognizingklexemes.k

    18kWritekthektransitionkdiagramktokrecognizek

    i.kRelationalkoperatorskk=,k=k

    ii.kIdentifierskandkKeywords.k

    19kWhatkiskakloo kaheadkoperator?kWithkexamplekshowkhowkthiskoperatorkmaykbekusedktoksolveklexicalkanalysiskproblems.k

    20kBrieflykexplainkthekusekofktransitionkdiagramkinkconstructingkaklexicalkanalyzerkwithkank

    example.k

    21kConstructkaktransitionkdiagramktokrecognizekthekto enskgivenkbelow:k

    i)kKeywords:kBEGINkENDkii)kIntegerkconstantk

    iii)kIdentifierk

    kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkUNITkkIIk,IIIkandkIVkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkSyntaxkAna

    lysis:k

    k

    OBJECTIVE:kThiskunitkdiscussesksyntaxkanalysis,kcontextkkfreekgrammars,kwritingkakgrammar,ktopkkdownkparsing,kbottomkkupkparsing,kLRkparsing,kusingkambiguouskgrammars,k&kparsekgenerators.k

    22kDefinek:k

    i.kleftkmostkderivationk

    ii.krightkmostkderivationk

    iii.kParsektreek

    23kYourkarekgivenkthekgrammar:k

    Sk.kak/kbk/k(L)k

  • 7/31/2019 CD Question Bank PART A

    3/5

    Lk.kL,kSk/kSk

    Givekleftkmostkderivationkforktheksentencek((a,kb),ka)k

    24kDefinekambiguitykandkshowkthatkthekgrammarkbelowkiskambiguousk

    Ek.kEk+kEk/kEk*kEk/k(E)k/kid.k

    25kGivekankunambiguouskgrammarkforkthekaboveklanguageksuchkthatk

    i)k+khaskhigherkpriorityk

    ii)k*khasklesskpriorityk

    kiii)kBothkarekrightkassociative.k

    26kBrieflykexplainkthekproblemskassociatedkwithktop-downkparsing.k

    27kConstructkLL(I)kparsingktablekforkthekgrammar.k

    Sk.kictkSS1k/ak

    S1k.keSk/kk

    IskthekgrammarkLL(I)?k

    28kWritekaknotekonkerrorkrecoverykinkLRkparsers.k

    29DefinekLL(I)kgrammar.kGivekconditionskforkakgrammarktokbekLL(I)kbasedkonkFIRSTkandkFOLLOWSksets.k

    30kBrieflykexplainkthekruleskforkbuildingkoperatorkprecedencekrelationskfromkprioritykandkassociativity.k

    31kGivenkthekgrammark

    Ek.kTk+kEk/kTk

    Tk.kTk*kFk/kFk

    Fk.k(E)k/kidk

    i)kMa ektheknecessarykchangesktokma ekitksuitablekforku(1)kparsing.k

    ii)kForkthekresultingkgrammar,kconstructkFIRSTkandkFOLLOWksetskandkLL(1)k

    kparsingktable.k

    32kGivenkthekgrammark

    Ek.kEk+kTk/kTk

    T.Tk*kidk/kidk

    i.kConstructksetskofkLR(1)kitemsk

  • 7/31/2019 CD Question Bank PART A

    4/5

    ii.kConstructkcanonicalkLR(1)kparsingktablek

    kiii.kIskthekgrammarkLALR(1)?kJustifykyourkanswer.k

    33kShowkthatkthekgrammarkbelowkiskambiguous.k

    Ek.kEk*kEk/kEk+kEk/k(E)k/kidk

    Givekankunambiguouskgrammarkforkthekaboveklanguageksuchkthatk

    i.k+khaskhigherkpriority.k

    kii.k*kandk+karekrightkassociative.k

    34kConstructkSLR(I)kparsingktablekforkthekgrammar.k

    Ek.kEkTk/kTk

    kTk.kidk+kTk/kidk

    35kGivektheklimitationskofkSLR(I)kparsers.k

    36kBrieflykexplainkthekerrorkdetectionkandkrecoverykinkLRkparsers.k

    37kWithkakschematickexplainkthekrolekofkakparser.kListkandkexplainkvariouskerrorkrecoverykstrategieskofkakparser.k

    38kWhatkiskthekneedkofkleftkfactoringkandkleftkrecursionkelimination?kExplainkwithkexamples.k

    39kClearykdefinekruleskforkfindingkFIRSTkandkFOLLOWksets.kDeterminekthekFIRSTkandk

    FOLLOWSksetskforkthekgrammar.k

    Ek.kTE1,kE1k+kTE1k/k,kTk.kFT1,kT1k.k*FT1k/k,kFk.k(E)k/kid.k

    40kfindkLR(0)kitemskofkthekgrammark

    Sk.kLk=kR,kSk.kR,kLk.k*R,kLk.kidkRk.kL.k

    VerifykwhetherkthiskgrammarkiskSLRk(1)korknot.k

    41kWhatkdokyoukmeankbykleftkrecursion?kGivekankalgorithmkforkeliminatingkleftkrecursionk

    fromkakgrammar.kUsingkthekalgorithm,keliminatekleftkrecursionkfromkthekgrammarkgivenkbelow.k

    Sk.kCkfk/kgk

    kCk.kChk/kSlk/k.k

    42kExplainkhandlekandkhandlekpruning.kHowktheykarekusedkinkthekstac kimplementationkofk

  • 7/31/2019 CD Question Bank PART A

    5/5

    shiftk-kreducekparsing?kExplainkwithkthekgrammarkEk.kEk+kEk/kEk*kEk/k(E)k/kidkandkthekinputkstringkid1k+kid2k*kid3$.k

    43kWhatkarekFIRSTkandkFOLLOWkfunctions?kExplainkhowktheykarekcomputed.k

    44ShowkthatkthekgrammarkgivenkbelowkisknotkankSLRkgrammarkbykshowingkthatkthekparsingktablekhaskakshift/reducekconflict.kCompletekthekparsingktable.k

    Sk.kLk=kRk

    Sk.kRk

    Lk.k*Rk

    Lk.kidk

    kRk.kLk

    47kConstructkakcanonicalkLRkparsingktablekforkthekgrammarkgivenkbelowk

    Sk.kCCk

    kCk.kcCk/kd.k

    48kForkthekfollowingkgrammar,kconstructkthekcanonicalkparsingktable:k

    S1k.kS,kSk.kCC,kCk.kcCk/kdk

    49kDesignkankalgorithmkforkconstructingkLALRkparsingktable.k