If you can't read please download the document
Upload
dodan
View
221
Download
0
Embed Size (px)
Citation preview
COO3077151
CourantMathematicsand
ComputingLaboratory
U.S.DepartmentofEnergy
ThePL/IProgrammingLanguage
PaulAbrahams
ResearchandDevelopmentReport
PreparedunderContractEY76C023077
withtheOfficeofEnergyResearch
MathematicsandComputing
March1978
NewYorkUniversity
UNCLASSIFIED
CourantMathematicsandComputingLaboratory
NewYorkUniversity
MathematicsandComputingCOO3077151
THEPL/IPROGRAMMINGLANGUAGE
PaulAbrahams
March1978
U.S.DepartmentofEnergy
ContractEY76C023077
UNCLASSIFIED
ThisreportistoappearasanarticleonthePL/I
programminglanguageintheEncyclopediaofComputer
ScienceandTechnologypublishedbyMarcelDekker,Inc,
ii
TableofContents
INTRODUCTION..............................................................1
SyntacticConventions...................................................6
DATATYPES................................................................9
ArithmeticTypes........................................................9StringTypes...........................................................11PicturedTypes.........................................................13Pointers,AreasandOffsets............................................19Files..................................................................20Labels.................................................................22Entries................................................................23Formats................................................................24Arrays.................................................................25Structures.............................................................26
DECLARATIONS.............................................................29
Manifest,Explicit,Contextual,andImplicitDeclarations..............29DeclarationsofStatementNames........................................31AttributeConsistencyandCompleteness.................................32StandardandUserDefinedDefaults.....................................38TheLIKEAttribute.....................................................41
EXPRESSIONS,TYPECONVERSION,ANDASSIGNMENT.............................43
PrefixandInfixExpressions...........................................45BuiltinFunctions......................................................51TypeConversion........................................................64Promotion..............................................................68TheAssignmentStatement...............................................69
STORAGETYPES............................................................72
StaticStorage.........................................................72AutomaticStorage......................................................73ControlledStorage.....................................................73BasedStorage..........................................................74TheReferOption.......................................................77LefttoRightCorrespondence...........................................79AllocationinAreas....................................................80ParameterStorage......................................................81DefinedStorage........................................................82Alignment..............................................................84Initialization.........................................................86
PROCEDURES,SCOPES,ANDENVIRONMENTS.....................................88
iii
TheRETURNStatement...................................................90ArgumentsandParameters...............................................91Options................................................................93Recursion..............................................................94TheGENERICAttribute..................................................95BlocksandScopes......................................................96InternalandExternalScope............................................99EntryValuesandEnvironments.........................................100
ONUNITSANDONSTATEMENTS..............................................102
TheONStatement,REVERTStatement,andSIGNALStatement..............105EnablementandDisablement............................................108BuiltinFunctionsforONConditions...................................109CategorizationoftheONConditions...................................110
OTHERSTATEMENTSAFFECTINGFLOWOFCONTROL..............................115
ConditionalStatements................................................115TheDOStatement......................................................116TheGOTOstatement....................................................119TheSTOPStatementandtheNullStatement.............................121
FILESANDRECORDINPUTOUTPUT...........................................122
FileAttributes.......................................................122FileOpeningandAttributeDetermination..............................123FileClosing..........................................................127OperationsonRecordFiles............................................127
STREAMINPUTOUTPUT.....................................................135
DataLists............................................................137ListDirectedInputOutput............................................138DataDirectedInputOutput............................................140EditDirectedInputOutput............................................142
BIBLIOGRAPHY............................................................150
EDITORIALNOTES.....................................................NOTES1
Acknowledgement...................................................NOTES1Errata............................................................NOTES1AbouttheAuthor..................................................NOTES2
iv
INTRODUCTION
PL/Iisalargeandpowerfulmultipurposeprogramming
language.TheintentofthedesignersofPL/Iwastocreate
alanguagethatcouldbeusedinbusinessandinscientific
applications,aswellasinsystemsprogrammingapplications
suchaswritingoperatingsystems.Theoriginaldesignwas
developedin1963byacommitteeofpeopledrawnfromIBM
andfromSHARE,anIBMusergroup.Foralongtimetheonly
importantimplementationsofPL/IwerethosedevelopedbyIBM
onthe360and370computers,andtheimplementationonthe
GE645attheMULTICSProjectatMIT.However,duringthe
early1970'sanumberofotherimplementationsarose.The
implementationofPL/Ibyotherorganizationswasgivenimpetus
bythedevelopmentofanationalandinternationalstandard
forPL/IbyasubcommitteeoftheAmericanNationalStandards
Institute,inconjunctionwithasimilarsubcommitteeofthe
EuropeanComputerManufacturers'Association.
ThedefinitionofStandardPL/Iwasformallyreleased
latein1976,butthecontentofthestandardwaspubliclyknown
wellbeforethen.Thestandarditselfwaswritteninanovel
mannerasasetofalgorithms,expressedinhighlystylized
English,fortheoperationofahypotheticalPL/Imachine.
TheversionofPL/IdescribedinthisarticleisStandardPL/I.
ThedesignofPL/Idrewheavilyonthemajorlanguages
thatexistedin1963:Fortran,Cobol,andAlgol60.The
syntaxofPL/ImostresemblesthatofFortran,butwithout
1
Fortran'srigidrulesforprogramformatting.Thenotionof
blockstructurewastakenfromAlgol60,whilePL/Istructures
weretakenfromtherecorddescriptionsofCobol.However,a
greatmanyfeatureswereaddedtoPL/Ithathavenocounter
partinitsancestorlanguages.
AnexampleofaPL/Iprogramisgiveninfigure1.A
programiswrittenasasequenceofexternalprocedures,which
aredefinedinsuchawaythattheycanbecompiledseparately
andthenlinkedtogetherwhentheprogramisexecuted.Within
anexternalprocedure,therecanbeinternalprocedures.
Inthisexample,thereisoneinternalprocedure,named
GET_DIGRAM.Eachprocedureintheprogramconstitutesablock,
Inaddition,ablockcanbedelimitedbythePL/Istatements
BEGINandEND(asinAlgol60).
TheinternalprocedureGET_DIGRAMcommunicateswiththe
outerprocedureDIGRAMSviaargumentspassedtoGET_DIGRAM
bytheCALLstatement.FromtheviewpointofGET_DIGRAM,
theseargumentsappearasparametersandarelistedinthe
PROCEDUREstatement.
Thevariablesusedinthisprogramaregiveninthe
DECLAREstatements.Ingeneral,avariable(orotheruseof
anidentifier)isdescribedbyasetofattributes.Notall
oftheseneedbegivenintheDECLAREstatement;thosethat
arenotgivenarededucedthroughtheapplicationofasetof
defaultingrules.Infact,defaultingisappliedinagreat
manycontextswithinPL/I.
2
Onaccountofitscomprehensivenature,PL/Iisadiffi
cultlanguagetolearninitsentirety.Forthatreasonit
wasdesignedsothatausercouldlearnjustthosepartsof
thelanguagethatheneeded,andignoretherestofituntil
theoccasionarosetousesomepreviouslyuntriedfeature.
Theextensivedefaultingconventionswereincluded,fora
largepart,tomakeitpossibletowriteprogramswithout
havingtolearnaboutobscureandirrelevantattributes.For
instance,onecanwritebusinessprogramsinPL/Iwithout
everrealizingthatthelanguageincludescomplexnumbersand
anextensiverepertoireofmathematicalbuiltinfunctions.
SinceStandardPL/Iisintendedtobeimplementedona
varietyofmachines,thestandardprovidesthatanumberof
characteristicsofthelanguageareimplementationdefined.
Forexample,machinesdifferintheirwordlengths;therefore
themaximumnumberofdigitsthatneedbecarriedina
floatingpointcomputationisleftimplementeddefined.Inthe
descriptionofPL/Igiveninthisarticle,implementationdefined
featuresofthelanguagearereferredtofrequently.