




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
ConceptsofProgrammingLanguages程序設(shè)計(jì)語言原理-復(fù)習(xí)ReviewChapter1:
PreliminariesMotivationProgrammingDomainsLanguageEvaluationCriteriaInfluencesonLanguageDesignLanguageCategoriesLanguageDesignTrade-OffsImplementationMethodsProgrammingEnvironments
程序設(shè)計(jì)語言原理-復(fù)習(xí)1.3LanguageEvaluationCriteriaReadabilityThemostimportantcriteriumFactors:OverallsimplicityToomanyfeaturesisbadMultiplicityoffeaturesisbadOperatoroverloadingOrthogonalityMakesthelanguageeasytolearnandreadMeaningiscontextindependentArelativelysmallsetofprimitiveconstructscanbecombinedinarelativelysmallnumberofwaysEverypossiblecombinationislegalLackoforthogonalityleadstoexceptionstorules正交性:指只用該語言的一組相對(duì)少量的基本結(jié)構(gòu),經(jīng)過相對(duì)少的結(jié)合步驟,就可構(gòu)成該語言的控制結(jié)構(gòu)和數(shù)據(jù)結(jié)構(gòu)。而且,它的基本結(jié)構(gòu)的任何組合都是合法和有意義的。count=count+1count+=1count++++count程序設(shè)計(jì)語言原理-復(fù)習(xí)1.3LanguageEvaluationCriteriaReadabilityWritabilityReliabilityCost程序設(shè)計(jì)語言原理-復(fù)習(xí)1.5LanguageCategoriesImperativeCentralfeaturesarevariables,assignmentstatements,anditerationC,PascalFunctionalMainmeansofmakingcomputationsisbyapplyingfunctionstogivenparametersLISP,Scheme程序設(shè)計(jì)語言原理-復(fù)習(xí)1.5LanguageCategoriesLogicRule-basedRulesarespecifiedinnospecialorderPrologObject-orientedEncapsulatedataobjectswithprocessingInheritanceanddynamictypebindingGrewoutofimperativelanguagesC++,Java程序設(shè)計(jì)語言原理-復(fù)習(xí)1.7ImplementationMethodsCompilationTranslatehigh-levelprogramtomachinecodeCCOBOLAdaSlowtranslationFastexecutionBottleneck:thespeedoftheconnectionbetweenacomputer’smemoryanditsprocessor.TheVonNeumannbottleneckhasbeenoneofthePrimarymotivationsfortheresearchanddevelopmentofparallelcomputers.程序設(shè)計(jì)語言原理-復(fù)習(xí)Chapter2:EvolutionofthemajorprogramminglanguagesZuse’sPlankalkulMinimalHardwareProgramming:PseudocodesTheIBM704andFORTRANFunctionalProgramming:LISPTheFirstStepTowardSophistication:ALGOL60ComputerizingBusinessRecords:COBOLTheBeginningsofTimesharing:BASICEverythingforEverybody:PL/IReview程序設(shè)計(jì)語言原理-復(fù)習(xí)9.TwoEarlyDynamicLanguages:APLandSNOBOL10.TheBeginningsofDataAbstraction:SIMULA6711.OrthogonalDesign:ALGOL6812.SomeEarlyDescendantsoftheALGOLs13.ProgrammingBasedonLogic:Prolog14.Hisotry’sLargestDesignEffort:AdaObject-OrientedProgramming:SmalltalkCombiningImperativeandObject-OrientedFeatures:C++Programmingtheworldwideweb:JavaReview程序設(shè)計(jì)語言原理-復(fù)習(xí)Chapter5:Names,Bindings,TypeChecking,andScopesIntroductionNamesVariables(屬性,別名,左值,右值P183)TheConceptofBinding(動(dòng)態(tài)和靜態(tài)綁定、生命周期)TypeCheckingStrongTypingTypeCompatibilityScopeScopeandLifetimeReferencingEnvironmentsNamedConstantsVariableInitializationReview程序設(shè)計(jì)語言原理-復(fù)習(xí)5.2Names(cont.)SpecialwordsAnaidtoreadability;usedtodelimit(界定)orseparatestatementclausesDef:A
keywordisawordthatisspecialonlyincertaincontexts.i.e.inFORTRAN:RealVarName(Realisdatatypefollowedwithaname,thereforeRealisakeyword)
Real=3.4(Realisavariable) Disadvantage:poorreadabilityDef:Areservedwordisaspecialwordthatcannotbeusedasauser-definedname程序設(shè)計(jì)語言原理-復(fù)習(xí)5.3VariablesAvariableisanabstractionofamemorycellVariablescanbecharacterizedasasextuple(六個(gè)部分)ofattributes:(name,address,value,type,lifetime,scope)Name-notallvariableshavethem(anonymous(匿名的))程序設(shè)計(jì)語言原理-復(fù)習(xí)
兩個(gè)變量具有按名等價(jià)的類型當(dāng)且僅當(dāng)它們一起被說明,或者用相同的類型標(biāo)識(shí)符說明,即對(duì)應(yīng)的類型名相同。如:typeTisarray[1..100]ofINTEGER;(Ada)
x,y:array[1..100]ofINTEGER;(P198)z:array[1..100]ofINTEGER;r,w:T;i,j:FLOAT;按名等價(jià):
r與w,i與jx與y、x與z按名不等價(jià),z與r按名不等價(jià).按名等價(jià)(Nametypecompatibility)程序設(shè)計(jì)語言原理-復(fù)習(xí)
兩個(gè)變量具有按結(jié)構(gòu)等價(jià)的類型當(dāng)且僅當(dāng)變量的所有分量有相同類型的值集。在上例中,u和v第二個(gè)分量的值集是相同的,所以按結(jié)構(gòu)等價(jià)。
x和u呢?按結(jié)構(gòu)等價(jià)雖然第二個(gè)分量的值均為整數(shù),但其類型不同,所以不是按結(jié)構(gòu)等價(jià)的。程序設(shè)計(jì)語言原理-復(fù)習(xí)兩個(gè)變量具有按定義等價(jià)的類型當(dāng)且僅當(dāng)兩個(gè)變量有完全相同的類型(包括相同的域名)。除類型名外的其他特征均相同者即視為按定義等價(jià)。如typecomplex=recordre:int;im:intend;Typerational=recordnominator:int;denominator:1..299999end;
按定義等價(jià)(declarationequivalence)程序設(shè)計(jì)語言原理-復(fù)習(xí)programexample;vara,b:integer;……
proceduresubl;varx,y:integer;begin{subl}…..1end;{subl}
proceduresub2;varx:integer;……
proceduresub3;varx:integer;begin{sub3}……2end;{sub3}
begin{sub2}……..3
end;{sub2}begin{example}……4end.{example}Point
Referencing
Environmentxandyofsubl,aandb
ofexample2xofsub3,(xofsub2ishidden),aandbofexample3xofsub2,aandbofexample4aandbofexampleInastatic-scopedlanguage程序設(shè)計(jì)語言原理-復(fù)習(xí)voidsubl(){inta,b;
…….1}/*endofsubl*/voidsub2(){intb,c;
……2
subl();}/*endofsub2*/voidmain(){intc,d;
……3
sub2();}/*endofmain*/
Point
ReferencingEnvironment1aandbofsub1,cofsub2,dofmain,,(cofmainandbofsub2arehidden)2bandcofsub2,dofmain,(cofmainishidden)3canddofmainFunctioncall:Main--->sub2---->sub1Inadynamic-scopedlanguage程序設(shè)計(jì)語言原理-復(fù)習(xí)Chapter6:DataTypes1.Introduction2.PrimitiveDataTypes3.CharacterStringTypes4.User-DefinedOrdinalType:5.ArrayTypes6.RecordTypes7.UnionTypes8.SetTypes
10.PointerTypes(懸掛指針P263)Review程序設(shè)計(jì)語言原理-復(fù)習(xí)Chapter7:ExpressionsandAssignmentStatementsIntroductionArithmeticExpressions(函數(shù)副作用)OverloadedOperators(操作符重載)TypeConversionsRelationalandBooleanExpressionsShort-CircuitEvaluationAssignmentStatementsMixed-modeAssignmentReview程序設(shè)計(jì)語言原理-復(fù)習(xí)6.10PointerTypesPointerProblemsDanglingPointers(懸掛指針):isapointerthatcontainstheaddressofaheap-dynamicvariablethathasbeendeallocated(解除分配).
Danglingpointersaredangerous
thelocationmayhavebeenreallocatedthevalueofthenewheap-dynamicvariablewillbedestroyedstoragemanagertofail
LostHeap-dynamicVariables:isanallocatedheap-dynamicvariablethatisnolongeraccessibletotheuserprogram.Suchvariablesarecalledgarbage(垃圾)程序設(shè)計(jì)語言原理-復(fù)習(xí)OperandEvaluationOrder
Ifneitheroftheoperandsofanoperatorhassideeffects,thenoperandevaluationorderisirrelevant(不相關(guān)的)
Sideeffects
Def:
functional
side
effect,occurswhenthefunctionchangeseitheroneofitsparametersoraglobalvariable
Example
a=10;10+5=15(fromlefttoright)b=a+fun(a);20+5=25(fromrighttoleft)funreturnsthevalueofitsargumentdividedby2andchangesitsparametertohavethevalue207.2ArithmeticExpressions
程序設(shè)計(jì)語言原理-復(fù)習(xí)7.3OverloadedOperatorsArithmeticoperatorsareoftenusedformorethanonepurpose.Multipleuseofanoperatoriscalledoperator
overloading
x=&y
(1)Binaryoperator:AND(2)Unaryoperator:theadrressofthatvariableTwoproblem(1)Detrimental(有害的)toreadability(2)someerrorundetectedbythecompiler.程序設(shè)計(jì)語言原理-復(fù)習(xí)Chapter8:Statement-LevelControlStructuresIntroductionCompoundStatementsSelectionStatementsIterativeStatementsUnconditionalBranchingGuardedCommandsConclusions
Review程序設(shè)計(jì)語言原理-復(fù)習(xí)Chapter9:SubprogramsIntroductionFundamentalsofSubprograms(parameterprofile,prototypeFormalparameters,actualparameter,positionandkeywordP..)3.DesignIssuesforSubprograms4.LocalReferencingEnvironments(localvarialbe,advantage..)5.Parameter-PassingMethods6.OverloadedSubprograms(定義)7.GenericSubprograms8.SeparateandIndependentCompilation9.DesignIssuesforFunctions10.AccessingNonlocalEnvironments(P388)(nonlocalvariable,globalvariable)11.User-DefinedOverloadedOperators12.Coroutines
Review程序設(shè)計(jì)語言原理-復(fù)習(xí)9.1IntroductionTwofundamentalabstractionfacilities(設(shè)施)canbeincludedinaprogramminglanguage:processabstractionanddataabstractionProcessabstractionhasbeenacentralconceptinallprogramminglanguages.Thefirstprogrammablecomputer,in1940,hadthecapability(能力)ofreusingcollectionsofinstructioncardsatseveraldifferentplacesinaprogramwhenthatwasconvenient(方便的)Thisreuseresultsinseveraldifferentkindsofsavings,frommemoryspacetocodingtime.Thisincreasesthereadabilityofaprogram.程序設(shè)計(jì)語言原理-復(fù)習(xí)BasicDefinitions(con.)ForexampleFORTRAN:SUBROUTINEADDER(parameters)
Ada:procedureADDER(parameters)C:voidadder(parameters)Theparameter
profile(參數(shù)輪廓)
ofasubprogramisthenumber,order,andtypesofitsformalparameters(形式參數(shù)).Theprotocol(協(xié)議)
ofasubprogramisitsparameterprofileplus,ifitisafunction,itsreturntype.9.2FundamentalsofSubprograms程序設(shè)計(jì)語言原理-復(fù)習(xí)Parameters
Therearetwowaysthatasubprogramgains(得到)accesstothedata:Throughdirectaccesstononlocal(非局部的)variables
ThroughparameterpassingParameterpassingismoreflexible(靈活的)thandirectaccesstononlocalvariables.Extensive(大量)accesstononlocalscancausereducedreliability(可靠性)Theparametersinthesubprogramheaderarecalledformal
parameters.Theyareboundtostorageonlywhenthesubprogramiscalled.9.2FundamentalsofSubprograms程序設(shè)計(jì)語言原理-復(fù)習(xí)Parameters(Con.)
Subprogramcallstatementsmustincludethenameofthesubprogramandalistofparameterstobeboundtotheformalparametersofthesubprogram(actual
parameters.).positional
parameters:thecorrespondence(對(duì)應(yīng))betweenactualandformalparametersisdonebysimpleposition
keyword
parameters:thenameoftheformalparametertowhichanactualparameteristobeboundisspecifiedwiththeactualparameter.(Ada)9.2FundamentalsofSubprograms程序設(shè)計(jì)語言原理-復(fù)習(xí)Variablesthataredefinedinsidesubprogramsarecalledlocalvariables.(eitherstaticorstackdynamic)Stackdynamiclocalvariablesareboundtostoragewhenthesubprogrambeginsexecutionandunboundfromstoragewhenthatexecutionterminates.Advantagesofstack-dynamiclocalvariables:flexibilitythestorageforlocalvariablescanbeshared.Disadvantagesofstack-dynamiclocalvariables:thereisthecostofthetimerequiredtoallocate,initialize,anddeallocate
accessestostack-dynamiclocalvariablesmustbeindirect(間接)subprogramscannotbehistorysensitive
9.4LocalReferencingEnvironments程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-ValueThevalueoftheactualparameterisusedtoinitializethecorrespondingformalparameterActsasalocalvariableinthesubprogramPass-by-valueisnormallyimplementedbyactualdatatransfer.Thedisadvantage:AdditionalstoragefortheformalparameterThestorageandthemoveoperationscanbecostlyiftheparameterislargePass-by-valueisimplementedbytransmittinganaccesspathtothevalueoftheactualparameterrequirethatthevaluebeinawrite-protectedcell
9.5Parameter-PassingMethods程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-ResultPass-by-resultisanimplementationmodelforout-modeparameters.NovalueistransmittedtothesubprogramThecorrespondingformalparameteractsasalocalvariable,justbeforecontrolistransferredbacktothecaller,itsvalueispassedbacktothecaller'sactualparameter
AlsorequirestheextrastorageandthecopyoperationsBeingimplementedbydatatransfer,theproblemisinensuringthattheinitialvalueoftheactualparameterisnotusedinthecalledsubprogram.9.5Parameter-PassingMethods程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-Result(con.)Oneproblemwiththepass-by-resultmodelisthattherecanbeanactualparametercollisionsub(p1,p1)(調(diào)用語句中)AssumingthetwoformalparametershavedifferentnamesTheorderinwhichtheactualparametersareassigneddeterminestheirvalueBecausetheorderisusuallyimplementationdependent,portability(可移植性)problemscanoccurthataredifficulttodiagnose(診斷)
Anotherproblemistochoosetwodifferenttimestoevaluatetheaddressesoftheactualparameters(atthetimeofthecalloratthetimeofthereturn)9.5Parameter-PassingMethodsForexample:
list[index]Ifindexischangedbythesubprogram,thentheaddressoflist[index]willchangebetweenthecallandthereturn程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-Value-ResultPass-by-value-resultisanimplementationmodelforinout-modeparametersinwhichactualvaluesaremoved.Acombinationofpass-by-valueandpass-by-result.Pass-by-value-resultissometimescalledpass-by-copybecausetheactualparameteriscopiedtotheformalparameteratsubprogramentryandthencopiedbackatsubprogramtermination.Disadvantagesofrequiringmultiplestorageforparametersandtimeforcopyingvalues.Theproblemsassociatedwiththeorderinwhichactualparametersareassigned.9.5Parameter-PassingMethods程序設(shè)計(jì)語言原理-復(fù)習(xí)COPY機(jī)制:機(jī)制實(shí)參進(jìn)入時(shí)出去時(shí)功能功能傳值方式表達(dá)式X:=實(shí)參
傳結(jié)果方式變量實(shí)參:=x傳值--結(jié)果方式變量X:=實(shí)參實(shí)參:=x傳值方式、傳結(jié)果方式、傳值--結(jié)果方式通稱為傳遞形式參數(shù)的COPY機(jī)制。形參x被指定為被調(diào)用過程的一個(gè)局部變量;進(jìn)入時(shí)將實(shí)參值復(fù)制給x,出去時(shí)將x的值復(fù)制給實(shí)參。X如同一個(gè)局部變量一樣,它的值可以取出和更新,進(jìn)入時(shí)創(chuàng)建出去時(shí)刪除。9.5Parameter-PassingMethods程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-ReferenceThepass-by-referencemethodtransmitsanaccesspath,justanaddresstothecalledsubprogram.Advantagesisthatthepassingprocessitselfisefficient,intermsofbothtimeandspace.Duplicatespaceisnotrequired,norisanycopying.Disadvantageslikelybeslowerbecauseindirectaddressingifonlyonewaycommunicationtothecalledsubprogramisrequired,Inadvertent(不注意的)anderroneous(錯(cuò)誤的)changesmaybemadeAnotherseriousproblemofpass-by-referenceisthataliasescanbecreated.9.5Parameter-PassingMethods程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-ReferenceseveralwaysaliasescanbecreatedCollisions(沖突)canoccurbetweenactualparametersvoidfun(int*first,int*second)fun(&total,&total)Collisionsbetweenarrayelementscanalsocausealiasesfun(&list[i],&list[j])ifI==jCollisionsbetweenarray-elementparametersandelementsofarrayspassedasarray-nameparametersfun1(&list[i],&list)9.5Parameter-PassingMethods程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-Referenceseveralwaysaliasescanbecreated(con.)Collisionsbetweenformalparametersandnonlocalvariables9.5Parameter-PassingMethodsint*global;voidmain(){extern
int*global;……
sub(global);
}voidsub(int*local){externint*global;……}Insidesub,localandglobalarealiases.程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-NamePass-by-nameisaninout-modeparametertransmissionmethod.Whenparametersarepassedbyname,theactualparameteristextuallysubstitutedforthecorrespondingformalparameterinallitsoccurrencesinthesubprogram.Apass-by-nameformalparameterisboundtoanaccessmethodatthetimeofthesubprogramcall,buttheactualbindingtoavalueoranaddressisdelayeduntiltheformalparameterisassignedorreferenced.9.5Parameter-PassingMethods程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-Name(con.)
Iftheactualparameterisascalarvariable(標(biāo)量變量),thenpass-by-nameisequivalenttopass-by-reference.Iftheactualparameterisaconstantexpression,thenpass-by-nameisequivalenttopass-by-valueIftheactualparameterisanarrayelement,pass-by-namemaybedifferentfromanyothermethodIftheactualparameterisanexpressionthatcontainsavariable,pass-by-nameisagaindifferentfromanyothermethod9.5Parameter-PassingMethods程序設(shè)計(jì)語言原理-復(fù)習(xí)ImplementationModelsofParameterPassing
Pass-by-Name(con.)9.5Parameter-PassingMethods
beginLIST[1]:=2;LIST[2]:=2;GLOBAL:=1;SUB(LIST[GLOBAL])
end;procedureBIGSUB;integerGLOBAL;integer
arrayLIST[1:2];procedureSUB(PARAM);integerPARAM;beginPARAM:=3;GLOBAL:=GLOBAL+1;PARAM:=5end;List[1]=3;List[2]=5;程序設(shè)計(jì)語言原理-復(fù)習(xí)Def:An
overloaded
subprogramisasubprogramthathasthesamenameasanothersubprograminthesamereferencingenvironment.Everyversionofanoverloadedsubprogrammusthaveaunique(唯一的)protocol;Itmustbedifferentfromtheothersinthenumber,order,ortypesofitsparameters,orinitsreturntypeifitisafunction.C++,Java,andAdaincludepredefinedoverloadedsubprograms.InAda,thereturntypeofanoverloadedfunctionisusedtodisambiguate(消除…的歧義)calls.
9.7OverloadSubprograms程序設(shè)計(jì)語言原理-復(fù)習(xí)Thecapabilityofcompilingpartsofaprogramwithoutcompilingthewholeprogramisessentialtotheconstructionoflargesoftwaresystems.Thepartsofprogramthatcanbecompiledaresometimescalledcompilationunits(編譯單元).Thetermseparatecompilation(分別編譯)
meansthatcompilationunitscanbecompiledatdifferenttimes,buttheircompilationsarenotindependentofeachotherifeitheraccessesorusesanyentitiesoftheother.9.9SeparateandIndependentCompilation程序設(shè)計(jì)語言原理-復(fù)習(xí)Usingwith,theprogrammerspecifiestheexternalunitsthatthecodeinthecompilationmustaccess
withGLOBALS,TEXT_IO;procedureEXAMPLEis
……endEXAMPLE;FORTRAN90alsoallowsseparatecompilationofitssubprogramsandmodules.Withindependent
compilation,programunitscanbecompiledwithoutinformationaboutanyotherprogramunits.9.9SeparateandIndependentCompilation程序設(shè)計(jì)語言原理-復(fù)習(xí)Def:Thenonlocal
variablesofasubprogramarethosethatarevisiblewithinthesubprogrambutarenotlocallydeclared.Def:
Global
variablesarethosethatarevisibleinallprogramunits.Theprimaryproblemasthemeansofnonlocalvariablesharingstaticscoping
Agooddealofprogramstructuremaybedictated(指定)bytheaccessibilityofsubprogramsandnonlocalvariablestoothersubprograms,ratherthanbywell-engineeredproblemsolutionsmoreaccesstononlocalsisprovidedthanisnecessary(P204)9.11AccessingNonlocalEnvironments程序設(shè)計(jì)語言原理-復(fù)習(xí)Chapter10:ImplementingSubprogramsTheGeneralSemanticsofCallsandReturns(子程序的聯(lián)接,call,returnP400)ImplementingFORTRAN77Subprograms(activationrecordinstance,靜態(tài)鏈,動(dòng)態(tài)鏈)ImplementingSubprogramsinALGOL-likeLanguagesBlocksImplementingDynamicScopingReview程序設(shè)計(jì)語言原理-復(fù)習(xí)10.1TheGeneralSemanticsofCallsandReturns
Asubprogramcallmustincludethemechanism
-Iflocalvariablesarenotstatic,itmustcausestoragetobeallocatedforthelocalsdeclaredinthecalledsubprogramandbindthosevariablestothatstorage-Itmustsavetheexecutionstatusofthecallingprogramunit-Itmusttransfercontroltothecodeofthesubprogramandreturntotheproperplacewhenthesubprogramexecutioniscompleted.-Thecallmustcausesomemechanismtobecreatedtoprovideaccesstononlocalvariablesthatarevisibletothecalledsubprogram.
程序設(shè)計(jì)語言原理-復(fù)習(xí)10.1TheGeneralSemanticsofCalls
andReturns
AsubprogramReturnmustincludethemechanismIfthesubprogramhasparametersthatareoutmodeandareimplementedbycopyFirst,movelocalvaluesoftheassociatedformalparameterstotheactualparametersNext,ItmustdeallocatethestorageusedforlocalvariablesandrestoretheexecutionstatusofthecallingprogramunitThen,returnthemechanismusedfornonlocalreferencestotheconfigurationithadbeforethecallFinally,
controlmustbereturnedtothecallingprogramunit程序設(shè)計(jì)語言原理-復(fù)習(xí)10.2ImplementingFORTRAN77
SubprogramsActivationrecord
instance(活動(dòng)記錄實(shí)例)
isaconcrete(具體的)exampleofanActivationRecord
程序設(shè)計(jì)語言原理-復(fù)習(xí)10.2ImplementingFORTRAN77
SubprogramsCommonstorage程序設(shè)計(jì)語言原理-復(fù)習(xí)Thereturnaddressoftenconsistsofapointertothecodesegmentofthecallerandanoffsetaddressinthatcodesegmentoftheinstructionfollowingthecall(調(diào)用語句之后那條指令的偏移地址)Thestatic
link(sometimescalledastatic
scopepointer)
pointstothebottomoftheactivationrecordinstanceofanactivationofthestaticparentThedynamic
linkisapointertothetopoftheactivationrecordinstanceofthecaller10.3ImplementingSubprogramsin
ALGOL-likeLanguages
程序設(shè)計(jì)語言原理-復(fù)習(xí)Considerthefollowingprocedure
proceduresub(vartotal
real;part:integer);varlist:
array[1..5]ofinteger;sum:real;
begin....end;
TheactivationrecordforsubisshowninFigure10.4.10.3ImplementingSubprogramsinALGOL-likeLanguages
程序設(shè)計(jì)語言原理-復(fù)習(xí)10.3ImplementingSubprogramsin
ALGOL-likeLanguages程序設(shè)計(jì)語言原理-復(fù)習(xí)10.3ImplementingSubprogramsin
ALGOL-likeLanguagesintfactorial(intn){1if(n<=1)return1;elsereturn(n*factorial(n–1));2}voidmain(){intvalue;
value=factorial(3);3}Recursion程序設(shè)計(jì)語言原理-復(fù)習(xí)10.3Implementing
Subprograms
in
ALGOL-like
Languages程序設(shè)計(jì)語言原理-復(fù)習(xí)程序設(shè)計(jì)語言原理-復(fù)習(xí)程序設(shè)計(jì)語言原理-復(fù)習(xí)10.3ImplementingSubprogramsin
ALGOL-likeLanguages(staticchains)Def:A
static
chainisachainofstaticlinksthatconnectcertainactivationrecordinstancesinthestack.Def:staticdepthbeanintegerassociatedwithastaticscopethatindicates(指出)howdeeplyitisnestedintheoutermost(最外層)scope.Becausethenestingofscopesisknownatcompiletime,thecompilercandeterminenotonlythatareferenceisnonlocalbutalsothelengthofthestaticchainneededtoreachtheactivationrecordinstancethatcontainsthenonlocalobject.程序設(shè)計(jì)語言原理-復(fù)習(xí)10.3ImplementingSubprogramsinALGOL-likeLanguages(staticchains)ThelengthofthestaticchainneededtoreachthecorrectactivationrecordinstanceforanonlocalreferencetoavariableXisexactlythedifference(差值)betweenthestatic_depthoftheprocedurecontainingthereferencetoxandthestatic_depthoftheprocedurecontainingthedeclarationforx.Thisdifferenceiscalledthenesting_depth(嵌套深度),
or
chain_offset(鏈偏移),
ofthereference.Itisrepresentedbyanorderedpairofintegers(chain_offset,local_offset)程序設(shè)計(jì)語言原理-復(fù)習(xí)InprocedureSUB1,ReferencetothevariableAatpoints1:(0,3)(local)Atpoints2:(2,3)(twolevelsaway)(BIGSUB)Atpoints3:(1,3)(onelevelaway)(BIGSUB)MAIN_2----------------0
BIGSUB---------------1
SUB1---------------2
SUB2---------------2
SUB3-----------3
程序設(shè)計(jì)語言原理-復(fù)習(xí)ComparethestaticchaininganddisplaymethodsThecostofaccessinglocalsisthesameforthetwomethodsReferencestononlocalsthatareonlyonestaticlevelawaytakethesametimeforbothmethods,butiftheyaremorethanonestaticlevelaway,theywillbefasterwithadisplaybecausenochainmustbefollowed.
10.3
ImplementingSubprogramsinALGOL-likeLanguages(display)程序設(shè)計(jì)語言原理-復(fù)習(xí)Thereareatleasttwodistinct(截然不同的)waysinwhichnonlocalreferencesinadynamic-scopedlanguagecanbeimplemented:deepaccess(深訪問)andshallowaccess(淺訪問).Whenaprograminalanguagethatusesdynamicscopingreferstoanonlocalvariable,thereferencecanberesolvedbysearchingthroughthedeclarationsintheothersubprogramsthatarecurrentlyactive,beginningwiththeonemostrecentlyactivated.10.5ImplementingDynamicScoping程序設(shè)計(jì)語言原理-復(fù)習(xí)Chapter11:AbstractDataTypeTheConceptofAbstraction(Abstractkinds)2.Encapsulation(encapsulation,)3.IntroductiontoDataAbstraction(abstractdatatype)4.DesignIssues6.ParameterizedAbstractDataTypesReview程序設(shè)計(jì)語言原理-復(fù)習(xí)11.1TheConceptofAbstractionAnabstractionisavieworrepresentationofanentitythatincludesonlytheattributesofsignificanceinaparticularcontext.Abstractionisaweapon(武器)againstthecomplexity(復(fù)雜性)ofprogramming;itspurposeistosimplifytheprogrammingprocess.Thetwofundamentalkindsofabstractionincontemporary(當(dāng)代的)programminglanguagesareprocessabstractionanddataabstraction.程序設(shè)計(jì)語言原理-復(fù)習(xí)11.2EncapsulationDef:AnencapsulationisagroupingofsubprogramsandthedatatheymanipulateWhenthesizeofaprogramreachesbeyondafewthousandlines,twopracticalproblemsappear:modularizationproblemrecompilationproblemAnencapsulationsolvesbothofthepracticalproblemsdescribedabove.程序設(shè)計(jì)語言原理-復(fù)習(xí)11.3IntroductiontoDataAbstractionDef:Anabstractdatatype(anencapsulation),includesonlythedatarepresentationofonespecificdatatypeandthesubprogramsthatprovidetheoperationsforthattype.Object:AninstanceofanabstractdatatypemotivationfordataabstractionAweaponagainstcomplexityAmeansofmakinglargeand/orcomplicatedprogramsmoremanageable程序設(shè)計(jì)語言原理-復(fù)習(xí)Chapter12:SupportforObject-orientedPrograms1.Introduction2.Object-OrientedProgramming3.DesignIssuesforObject-OrientedLanguages9.SupportforObject-OrientedProgramminginC++10.SupportforObject-OrientedProgram
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 餐廳臨時(shí)出租協(xié)議書
- 針灸推拿醫(yī)生協(xié)議書
- 裝修公司學(xué)徒協(xié)議書
- 營(yíng)運(yùn)車輛入股協(xié)議書
- 銀行貸款免還協(xié)議書
- 餐廳經(jīng)營(yíng)轉(zhuǎn)讓協(xié)議書
- 食品貨車司機(jī)協(xié)議書
- 閑置水廠合作協(xié)議書
- 音樂機(jī)構(gòu)入股協(xié)議書
- 酒店投資合伙協(xié)議書
- 防雷日常管理制度
- DB23T 3711-2024市縣級(jí)礦產(chǎn)資源總體規(guī)劃編制技術(shù)規(guī)程
- 智能座艙域控制器液冷散熱設(shè)計(jì)及仿真研究
- 2025年沈陽汽車城開發(fā)建設(shè)集團(tuán)有限公司招聘筆試參考題庫(kù)含答案解析
- 田徑理論考試復(fù)習(xí)題庫(kù)300題(含各題型)
- 泛海三江JB-QGL-9000、JB-QTL-9000、JB-QBL-9000火災(zāi)報(bào)警控制器
- 員工團(tuán)建就餐合同
- 電氣工程及其自動(dòng)化畢業(yè)設(shè)計(jì) 基于PLC的噴涂機(jī)器人控制系統(tǒng)的設(shè)計(jì)
- 滑雪培訓(xùn)服務(wù)合同
- 肌肉注射課件(共45張課件)
- 工程經(jīng)濟(jì)學(xué)(青島理工大學(xué))知到智慧樹章節(jié)測(cè)試課后答案2024年秋青島理工大學(xué)
評(píng)論
0/150
提交評(píng)論