程序設(shè)計語言原理-復(fù)習課件_第1頁
程序設(shè)計語言原理-復(fù)習課件_第2頁
程序設(shè)計語言原理-復(fù)習課件_第3頁
程序設(shè)計語言原理-復(fù)習課件_第4頁
程序設(shè)計語言原理-復(fù)習課件_第5頁
已閱讀5頁,還剩74頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

ConceptsofProgrammingLanguages程序設(shè)計語言原理-復(fù)習ReviewChapter1:

PreliminariesMotivationProgrammingDomainsLanguageEvaluationCriteriaInfluencesonLanguageDesignLanguageCategoriesLanguageDesignTrade-OffsImplementationMethodsProgrammingEnvironments

程序設(shè)計語言原理-復(fù)習1.3LanguageEvaluationCriteriaReadabilityThemostimportantcriteriumFactors:OverallsimplicityToomanyfeaturesisbadMultiplicityoffeaturesisbadOperatoroverloadingOrthogonalityMakesthelanguageeasytolearnandreadMeaningiscontextindependentArelativelysmallsetofprimitiveconstructscanbecombinedinarelativelysmallnumberofwaysEverypossiblecombinationislegalLackoforthogonalityleadstoexceptionstorules正交性:指只用該語言的一組相對少量的基本結(jié)構(gòu),經(jīng)過相對少的結(jié)合步驟,就可構(gòu)成該語言的控制結(jié)構(gòu)和數(shù)據(jù)結(jié)構(gòu)。而且,它的基本結(jié)構(gòu)的任何組合都是合法和有意義的。count=count+1count+=1count++++count程序設(shè)計語言原理-復(fù)習1.3LanguageEvaluationCriteriaReadabilityWritabilityReliabilityCost程序設(shè)計語言原理-復(fù)習1.5LanguageCategoriesImperativeCentralfeaturesarevariables,assignmentstatements,anditerationC,PascalFunctionalMainmeansofmakingcomputationsisbyapplyingfunctionstogivenparametersLISP,Scheme程序設(shè)計語言原理-復(fù)習1.5LanguageCategoriesLogicRule-basedRulesarespecifiedinnospecialorderPrologObject-orientedEncapsulatedataobjectswithprocessingInheritanceanddynamictypebindingGrewoutofimperativelanguagesC++,Java程序設(shè)計語言原理-復(fù)習1.7ImplementationMethodsCompilationTranslatehigh-levelprogramtomachinecodeCCOBOLAdaSlowtranslationFastexecutionBottleneck:thespeedoftheconnectionbetweenacomputer’smemoryanditsprocessor.TheVonNeumannbottleneckhasbeenoneofthePrimarymotivationsfortheresearchanddevelopmentofparallelcomputers.程序設(shè)計語言原理-復(fù)習Chapter2:EvolutionofthemajorprogramminglanguagesZuse’sPlankalkulMinimalHardwareProgramming:PseudocodesTheIBM704andFORTRANFunctionalProgramming:LISPTheFirstStepTowardSophistication:ALGOL60ComputerizingBusinessRecords:COBOLTheBeginningsofTimesharing:BASICEverythingforEverybody:PL/IReview程序設(shè)計語言原理-復(fù)習9.TwoEarlyDynamicLanguages:APLandSNOBOL10.TheBeginningsofDataAbstraction:SIMULA6711.OrthogonalDesign:ALGOL6812.SomeEarlyDescendantsoftheALGOLs13.ProgrammingBasedonLogic:Prolog14.Hisotry’sLargestDesignEffort:AdaObject-OrientedProgramming:SmalltalkCombiningImperativeandObject-OrientedFeatures:C++Programmingtheworldwideweb:JavaReview程序設(shè)計語言原理-復(fù)習Chapter5:Names,Bindings,TypeChecking,andScopesIntroductionNamesVariables(屬性,別名,左值,右值P183)TheConceptofBinding(動態(tài)和靜態(tài)綁定、生命周期)TypeCheckingStrongTypingTypeCompatibilityScopeScopeandLifetimeReferencingEnvironmentsNamedConstantsVariableInitializationReview程序設(shè)計語言原理-復(fù)習5.2Names(cont.)SpecialwordsAnaidtoreadability;usedtodelimit(界定)orseparatestatementclausesDef:A

keywordisawordthatisspecialonlyincertaincontexts.i.e.inFORTRAN:RealVarName(Realisdatatypefollowedwithaname,thereforeRealisakeyword)

Real=3.4(Realisavariable) Disadvantage:poorreadabilityDef:Areservedwordisaspecialwordthatcannotbeusedasauser-definedname程序設(shè)計語言原理-復(fù)習5.3VariablesAvariableisanabstractionofamemorycellVariablescanbecharacterizedasasextuple(六個部分)ofattributes:(name,address,value,type,lifetime,scope)Name-notallvariableshavethem(anonymous(匿名的))程序設(shè)計語言原理-復(fù)習

兩個變量具有按名等價的類型當且僅當它們一起被說明,或者用相同的類型標識符說明,即對應(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;按名等價:

r與w,i與jx與y、x與z按名不等價,z與r按名不等價.按名等價(Nametypecompatibility)程序設(shè)計語言原理-復(fù)習

兩個變量具有按結(jié)構(gòu)等價的類型當且僅當變量的所有分量有相同類型的值集。在上例中,u和v第二個分量的值集是相同的,所以按結(jié)構(gòu)等價。

x和u呢?按結(jié)構(gòu)等價雖然第二個分量的值均為整數(shù),但其類型不同,所以不是按結(jié)構(gòu)等價的。程序設(shè)計語言原理-復(fù)習兩個變量具有按定義等價的類型當且僅當兩個變量有完全相同的類型(包括相同的域名)。除類型名外的其他特征均相同者即視為按定義等價。如typecomplex=recordre:int;im:intend;Typerational=recordnominator:int;denominator:1..299999end;

按定義等價(declarationequivalence)程序設(shè)計語言原理-復(fù)習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è)計語言原理-復(fù)習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è)計語言原理-復(fù)習Chapter6:DataTypes1.Introduction2.PrimitiveDataTypes3.CharacterStringTypes4.User-DefinedOrdinalType:5.ArrayTypes6.RecordTypes7.UnionTypes8.SetTypes

10.PointerTypes(懸掛指針P263)Review程序設(shè)計語言原理-復(fù)習Chapter7:ExpressionsandAssignmentStatementsIntroductionArithmeticExpressions(函數(shù)副作用)OverloadedOperators(操作符重載)TypeConversionsRelationalandBooleanExpressionsShort-CircuitEvaluationAssignmentStatementsMixed-modeAssignmentReview程序設(shè)計語言原理-復(fù)習6.10PointerTypesPointerProblemsDanglingPointers(懸掛指針):isapointerthatcontainstheaddressofaheap-dynamicvariablethathasbeendeallocated(解除分配).

Danglingpointersaredangerous

thelocationmayhavebeenreallocatedthevalueofthenewheap-dynamicvariablewillbedestroyedstoragemanagertofail

LostHeap-dynamicVariables:isanallocatedheap-dynamicvariablethatisnolongeraccessibletotheuserprogram.Suchvariablesarecalledgarbage(垃圾)程序設(shè)計語言原理-復(fù)習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è)計語言原理-復(fù)習7.3OverloadedOperatorsArithmeticoperatorsareoftenusedformorethanonepurpose.Multipleuseofanoperatoriscalledoperator

overloading

x=&y

(1)Binaryoperator:AND(2)Unaryoperator:theadrressofthatvariableTwoproblem(1)Detrimental(有害的)toreadability(2)someerrorundetectedbythecompiler.程序設(shè)計語言原理-復(fù)習Chapter8:Statement-LevelControlStructuresIntroductionCompoundStatementsSelectionStatementsIterativeStatementsUnconditionalBranchingGuardedCommandsConclusions

Review程序設(shè)計語言原理-復(fù)習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è)計語言原理-復(fù)習9.1IntroductionTwofundamentalabstractionfacilities(設(shè)施)canbeincludedinaprogramminglanguage:processabstractionanddataabstractionProcessabstractionhasbeenacentralconceptinallprogramminglanguages.Thefirstprogrammablecomputer,in1940,hadthecapability(能力)ofreusingcollectionsofinstructioncardsatseveraldifferentplacesinaprogramwhenthatwasconvenient(方便的)Thisreuseresultsinseveraldifferentkindsofsavings,frommemoryspacetocodingtime.Thisincreasesthereadabilityofaprogram.程序設(shè)計語言原理-復(fù)習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è)計語言原理-復(fù)習Parameters

Therearetwowaysthatasubprogramgains(得到)accesstothedata:Throughdirectaccesstononlocal(非局部的)variables

ThroughparameterpassingParameterpassingismoreflexible(靈活的)thandirectaccesstononlocalvariables.Extensive(大量)accesstononlocalscancausereducedreliability(可靠性)Theparametersinthesubprogramheaderarecalledformal

parameters.Theyareboundtostorageonlywhenthesubprogramiscalled.9.2FundamentalsofSubprograms程序設(shè)計語言原理-復(fù)習Parameters(Con.)

Subprogramcallstatementsmustincludethenameofthesubprogramandalistofparameterstobeboundtotheformalparametersofthesubprogram(actual

parameters.).positional

parameters:thecorrespondence(對應(yīng))betweenactualandformalparametersisdonebysimpleposition

keyword

parameters:thenameoftheformalparametertowhichanactualparameteristobeboundisspecifiedwiththeactualparameter.(Ada)9.2FundamentalsofSubprograms程序設(shè)計語言原理-復(fù)習Variablesthataredefinedinsidesubprogramsarecalledlocalvariables.(eitherstaticorstackdynamic)Stackdynamiclocalvariablesareboundtostoragewhenthesubprogrambeginsexecutionandunboundfromstoragewhenthatexecutionterminates.Advantagesofstack-dynamiclocalvariables:flexibilitythestorageforlocalvariablescanbeshared.Disadvantagesofstack-dynamiclocalvariables:thereisthecostofthetimerequiredtoallocate,initialize,anddeallocate

accessestostack-dynamiclocalvariablesmustbeindirect(間接)subprogramscannotbehistorysensitive

9.4LocalReferencingEnvironments程序設(shè)計語言原理-復(fù)習ImplementationModelsofParameterPassing

Pass-by-ValueThevalueoftheactualparameterisusedtoinitializethecorrespondingformalparameterActsasalocalvariableinthesubprogramPass-by-valueisnormallyimplementedbyactualdatatransfer.Thedisadvantage:AdditionalstoragefortheformalparameterThestorageandthemoveoperationscanbecostlyiftheparameterislargePass-by-valueisimplementedbytransmittinganaccesspathtothevalueoftheactualparameterrequirethatthevaluebeinawrite-protectedcell

9.5Parameter-PassingMethods程序設(shè)計語言原理-復(fù)習ImplementationModelsofParameterPassing

Pass-by-ResultPass-by-resultisanimplementationmodelforout-modeparameters.NovalueistransmittedtothesubprogramThecorrespondingformalparameteractsasalocalvariable,justbeforecontrolistransferredbacktothecaller,itsvalueispassedbacktothecaller'sactualparameter

AlsorequirestheextrastorageandthecopyoperationsBeingimplementedbydatatransfer,theproblemisinensuringthattheinitialvalueoftheactualparameterisnotusedinthecalledsubprogram.9.5Parameter-PassingMethods程序設(shè)計語言原理-復(fù)習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è)計語言原理-復(fù)習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è)計語言原理-復(fù)習COPY機制:機制實參進入時出去時功能功能傳值方式表達式X:=實參

傳結(jié)果方式變量實參:=x傳值--結(jié)果方式變量X:=實參實參:=x傳值方式、傳結(jié)果方式、傳值--結(jié)果方式通稱為傳遞形式參數(shù)的COPY機制。形參x被指定為被調(diào)用過程的一個局部變量;進入時將實參值復(fù)制給x,出去時將x的值復(fù)制給實參。X如同一個局部變量一樣,它的值可以取出和更新,進入時創(chuàng)建出去時刪除。9.5Parameter-PassingMethods程序設(shè)計語言原理-復(fù)習ImplementationModelsofParameterPassing

Pass-by-ReferenceThepass-by-referencemethodtransmitsanaccesspath,justanaddresstothecalledsubprogram.Advantagesisthatthepassingprocessitselfisefficient,intermsofbothtimeandspace.Duplicatespaceisnotrequired,norisanycopying.Disadvantageslikelybeslowerbecauseindirectaddressingifonlyonewaycommunicationtothecalledsubprogramisrequired,Inadvertent(不注意的)anderroneous(錯誤的)changesmaybemadeAnotherseriousproblemofpass-by-referenceisthataliasescanbecreated.9.5Parameter-PassingMethods程序設(shè)計語言原理-復(fù)習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è)計語言原理-復(fù)習ImplementationModelsofParameterPassing

Pass-by-Referenceseveralwaysaliasescanbecreated(con.)Collisionsbetweenformalparametersandnonlocalvariables9.5Parameter-PassingMethodsint*global;voidmain(){extern

int*global;……

sub(global);

}voidsub(int*local){externint*global;……}Insidesub,localandglobalarealiases.程序設(shè)計語言原理-復(fù)習ImplementationModelsofParameterPassing

Pass-by-NamePass-by-nameisaninout-modeparametertransmissionmethod.Whenparametersarepassedbyname,theactualparameteristextuallysubstitutedforthecorrespondingformalparameterinallitsoccurrencesinthesubprogram.Apass-by-nameformalparameterisboundtoanaccessmethodatthetimeofthesubprogramcall,buttheactualbindingtoavalueoranaddressisdelayeduntiltheformalparameterisassignedorreferenced.9.5Parameter-PassingMethods程序設(shè)計語言原理-復(fù)習ImplementationModelsofParameterPassing

Pass-by-Name(con.)

Iftheactualparameterisascalarvariable(標量變量),thenpass-by-nameisequivalenttopass-by-reference.Iftheactualparameterisaconstantexpression,thenpass-by-nameisequivalenttopass-by-valueIftheactualparameterisanarrayelement,pass-by-namemaybedifferentfromanyothermethodIftheactualparameterisanexpressionthatcontainsavariable,pass-by-nameisagaindifferentfromanyothermethod9.5Parameter-PassingMethods程序設(shè)計語言原理-復(fù)習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è)計語言原理-復(fù)習Def:An

overloaded

subprogramisasubprogramthathasthesamenameasanothersubprograminthesamereferencingenvironment.Everyversionofanoverloadedsubprogrammusthaveaunique(唯一的)protocol;Itmustbedifferentfromtheothersinthenumber,order,ortypesofitsparameters,orinitsreturntypeifitisafunction.C++,Java,andAdaincludepredefinedoverloadedsubprograms.InAda,thereturntypeofanoverloadedfunctionisusedtodisambiguate(消除…的歧義)calls.

9.7OverloadSubprograms程序設(shè)計語言原理-復(fù)習Thecapabilityofcompilingpartsofaprogramwithoutcompilingthewholeprogramisessentialtotheconstructionoflargesoftwaresystems.Thepartsofprogramthatcanbecompiledaresometimescalledcompilationunits(編譯單元).Thetermseparatecompilation(分別編譯)

meansthatcompilationunitscanbecompiledatdifferenttimes,buttheircompilationsarenotindependentofeachotherifeitheraccessesorusesanyentitiesoftheother.9.9SeparateandIndependentCompilation程序設(shè)計語言原理-復(fù)習Usingwith,theprogrammerspecifiestheexternalunitsthatthecodeinthecompilationmustaccess

withGLOBALS,TEXT_IO;procedureEXAMPLEis

……endEXAMPLE;FORTRAN90alsoallowsseparatecompilationofitssubprogramsandmodules.Withindependent

compilation,programunitscanbecompiledwithoutinformationaboutanyotherprogramunits.9.9SeparateandIndependentCompilation程序設(shè)計語言原理-復(fù)習Def:Thenonlocal

variablesofasubprogramarethosethatarevisiblewithinthesubprogrambutarenotlocallydeclared.Def:

Global

variablesarethosethatarevisibleinallprogramunits.Theprimaryproblemasthemeansofnonlocalvariablesharingstaticscoping

Agooddealofprogramstructuremaybedictated(指定)bytheaccessibilityofsubprogramsandnonlocalvariablestoothersubprograms,ratherthanbywell-engineeredproblemsolutionsmoreaccesstononlocalsisprovidedthanisnecessary(P204)9.11AccessingNonlocalEnvironments程序設(shè)計語言原理-復(fù)習Chapter10:ImplementingSubprogramsTheGeneralSemanticsofCallsandReturns(子程序的聯(lián)接,call,returnP400)ImplementingFORTRAN77Subprograms(activationrecordinstance,靜態(tài)鏈,動態(tài)鏈)ImplementingSubprogramsinALGOL-likeLanguagesBlocksImplementingDynamicScopingReview程序設(shè)計語言原理-復(fù)習10.1TheGeneralSemanticsofCallsandReturns

Asubprogramcallmustincludethemechanism

-Iflocalvariablesarenotstatic,itmustcausestoragetobeallocatedforthelocalsdeclaredinthecalledsubprogramandbindthosevariablestothatstorage-Itmustsavetheexecutionstatusofthecallingprogramunit-Itmusttransfercontroltothecodeofthesubprogramandreturntotheproperplacewhenthesubprogramexecutioniscompleted.-Thecallmustcausesomemechanismtobecreatedtoprovideaccesstononlocalvariablesthatarevisibletothecalledsubprogram.

程序設(shè)計語言原理-復(fù)習10.1TheGeneralSemanticsofCalls

andReturns

AsubprogramReturnmustincludethemechanismIfthesubprogramhasparametersthatareoutmodeandareimplementedbycopyFirst,movelocalvaluesoftheassociatedformalparameterstotheactualparametersNext,ItmustdeallocatethestorageusedforlocalvariablesandrestoretheexecutionstatusofthecallingprogramunitThen,returnthemechanismusedfornonlocalreferencestotheconfigurationithadbeforethecallFinally,

controlmustbereturnedtothecallingprogramunit程序設(shè)計語言原理-復(fù)習10.2ImplementingFORTRAN77

SubprogramsActivationrecord

instance(活動記錄實例)

isaconcrete(具體的)exampleofanActivationRecord

程序設(shè)計語言原理-復(fù)習10.2ImplementingFORTRAN77

SubprogramsCommonstorage程序設(shè)計語言原理-復(fù)習Thereturnaddressoftenconsistsofapointertothecodesegmentofthecallerandanoffsetaddressinthatcodesegmentoftheinstructionfollowingthecall(調(diào)用語句之后那條指令的偏移地址)Thestatic

link(sometimescalledastatic

scopepointer)

pointstothebottomoftheactivationrecordinstanceofanactivationofthestaticparentThedynamic

linkisapointertothetopoftheactivationrecordinstanceofthecaller10.3ImplementingSubprogramsin

ALGOL-likeLanguages

程序設(shè)計語言原理-復(fù)習Considerthefollowingprocedure

proceduresub(vartotal

real;part:integer);varlist:

array[1..5]ofinteger;sum:real;

begin....end;

TheactivationrecordforsubisshowninFigure10.4.10.3ImplementingSubprogramsinALGOL-likeLanguages

程序設(shè)計語言原理-復(fù)習10.3ImplementingSubprogramsin

ALGOL-likeLanguages程序設(shè)計語言原理-復(fù)習10.3ImplementingSubprogramsin

ALGOL-likeLanguagesintfactorial(intn){1if(n<=1)return1;elsereturn(n*factorial(n–1));2}voidmain(){intvalue;

value=factorial(3);3}Recursion程序設(shè)計語言原理-復(fù)習10.3Implementing

Subprograms

in

ALGOL-like

Languages程序設(shè)計語言原理-復(fù)習程序設(shè)計語言原理-復(fù)習程序設(shè)計語言原理-復(fù)習10.3ImplementingSubprogramsin

ALGOL-likeLanguages(staticchains)Def:A

static

chainisachainofstaticlinksthatconnectcertainactivationrecordinstancesinthestack.Def:staticdepthbeanintegerassociatedwithastaticscopethatindicates(指出)howdeeplyitisnestedintheoutermost(最外層)scope.Becausethenestingofscopesisknownatcompiletime,thecompilercandeterminenotonlythatareferenceisnonlocalbutalsothelengthofthestaticchainneededtoreachtheactivationrecordinstancethatcontainsthenonlocalobject.程序設(shè)計語言原理-復(fù)習10.3ImplementingSubprogramsinALGOL-likeLanguages(staticchains)ThelengthofthestaticchainneededtoreachthecorrectactivationrecordinstanceforanonlocalreferencetoavariableXisexactlythedifference(差值)betweenthestatic_depthoftheprocedurecontainingthereferencetoxandthestatic_depthoftheprocedurecontainingthedeclarationforx.Thisdifferenceiscalledthenesting_depth(嵌套深度),

or

chain_offset(鏈偏移),

ofthereference.Itisrepresentedbyanorderedpairofintegers(chain_offset,local_offset)程序設(shè)計語言原理-復(fù)習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è)計語言原理-復(fù)習ComparethestaticchaininganddisplaymethodsThecostofaccessinglocalsisthesameforthetwomethodsReferencestononlocalsthatareonlyonestaticlevelawaytakethesametimeforbothmethods,butiftheyaremorethanonestaticlevelaway,theywillbefasterwithadisplaybecausenochainmustbefollowed.

10.3

ImplementingSubprogramsinALGOL-likeLanguages(display)程序設(shè)計語言原理-復(fù)習Thereareatleasttwodistinct(截然不同的)waysinwhichnonlocalreferencesinadynamic-scopedlanguagecanbeimplemented:deepaccess(深訪問)andshallowaccess(淺訪問).Whenaprograminalanguagethatusesdynamicscopingreferstoanonlocalvariable,thereferencecanberesolvedbysearchingthroughthedeclarationsintheothersubprogramsthatarecurrentlyactive,beginningwiththeonemostrecentlyactivated.10.5ImplementingDynamicScoping程序設(shè)計語言原理-復(fù)習Chapter11:AbstractDataTypeTheConceptofAbstraction(Abstractkinds)2.Encapsulation(encapsulation,)3.IntroductiontoDataAbstraction(abstractdatatype)4.DesignIssues6.ParameterizedAbstractDataTypesReview程序設(shè)計語言原理-復(fù)習11.1TheConceptofAbstractionAnabstractionisavieworrepresentationofanentitythatincludesonlytheattributesofsignificanceinaparticularcontext.Abstractionisaweapon(武器)againstthecomplexity(復(fù)雜性)ofprogramming;itspurposeistosimplifytheprogrammingprocess.Thetwofundamentalkindsofabstractionincontemporary(當代的)programminglanguagesareprocessabstractionanddataabstraction.程序設(shè)計語言原理-復(fù)習11.2EncapsulationDef:AnencapsulationisagroupingofsubprogramsandthedatatheymanipulateWhenthesizeofaprogramreachesbeyondafewthousandlines,twopracticalproblemsappear:modularizationproblemrecompilationproblemAnencapsulationsolvesbothofthepracticalproblemsdescribedabove.程序設(shè)計語言原理-復(fù)習11.3IntroductiontoDataAbstractionDef:Anabstractdatatype(anencapsulation),includesonlythedatarepresentationofonespecificdatatypeandthesubprogramsthatprovidetheoperationsforthattype.Object:AninstanceofanabstractdatatypemotivationfordataabstractionAweaponagainstcomplexityAmeansofmakinglargeand/orcomplicatedprogramsmoremanageable程序設(shè)計語言原理-復(fù)習Chapter12:SupportforObject-orientedPrograms1.Introduction2.Object-OrientedProgramming3.DesignIssuesforObject-OrientedLanguages9.SupportforObject-OrientedProgramminginC++10.SupportforObject-OrientedProgram

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論