TheProgrammingLanguageEFL StuartI.Feldman Fortran Preprocessors Ratfor ABSTRACT EFLisaclean,generalpurposecomputerlanguageintendedtoencourage portableprogramming.Ithasauniformandreadablesyntaxandgooddataand controlflowstructuring.EFLprogramscanbetranslatedintoefficientFortran code,sotheEFLprogrammercantakeadvantageoftheubiquityofFortran,the valuablelibrariesofsoftwarewritteninthatlanguage,andtheportabilitythat comeswiththeuseofastandardizedlanguage,withoutsufferingfromFortran’s manyfailingsasalanguage.Itisespeciallyusefulfornumericprograms.The EFLlanguagepermitstheprogrammertoexpresscomplicatedideasinacomprehensibleway,whilepermittingaccesstothepoweroftheFortranenvironment. EFLcanbeviewedasadescendantofB.W.Kernighan’sRatfor[1];thename originallystoodfor‘ExtendedFortranLanguage’.Thecurrentversionofthe EFLcompileriswritteninportableC. 4June1979 TheProgrammingLanguageEFL StuartI.Feldman Fortran Preprocessors Ratfor 1.INTRODUCTION 1.1.Purpose EFLisaclean,generalpurposecomputerlanguageintendedtoencourageportableprogramming.Ithasauniformandreadablesyntaxandgooddataandcontrolflowstructuring.EFL programscanbetranslatedintoefficientFortrancode,sotheEFLprogrammercantakeadvantageoftheubiquityofFortran,thevaluablelibrariesofsoftwarewritteninthatlanguage,andthe portabilitythatcomeswiththeuseofastandardizedlanguage,withoutsufferingfromFortran’s manyfailingsasalanguage.Itisespeciallyusefulfornumericprograms.Thus,theEFLlanguagepermitstheprogrammertoexpresscomplicatedideasinacomprehensibleway,whilepermittingaccesstothepoweroftheFortranenvironment. 1.2.History EFLcanbeviewedasadescendantofB.W.Kernighan’sRatfor[1];thenameoriginally stoodfor‘ExtendedFortranLanguage’.A.D.Halldesignedtheinitialversionofthelanguage andwroteapreliminaryversionofacompiler.Iextendedandmodifiedthelanguageandwrotea fullcompiler(inC)forit.Thecurrentcompilerismuchmorethanasimplepreprocessor:it attemptstodiagnoseallsyntaxerrors,toprovidereadableFortranoutput,andtoavoidanumber ofnigglingrestrictions.Toachievethisgoal,asizabletwo-passtranslatorisneeded. 1.3.Notation Inexamplesandsyntaxspecifications,boldfacetypeisusedtoindicateliteralwordsand punctuation,suchaswhile.Wordsinitalictypeindicateaniteminacategory,suchasan expression.Aconstructsurroundedbydoublebracketsrepresentsalistofoneormoreofthose items,separatedbycommas.Thus,thenotation [[item]] couldrefertoanyofthefollowing: item item,item item,item,item Thereadershouldhaveafairdegreeoffamiliaritywithsomeprocedurallanguage.There willbeoccasionalreferencestoRatforandtoFortranwhichmaybeignoredifthereaderisunfamiliarwiththoselanguages.

-2-2.LEXICALFORM 2.1.CharacterSet ThefollowingcharactersarelegalinanEFLprogram: lettersabcdefghijklm nopqrstuvwxyz digits0123456789 whitespaceblanktab quotes´ " sharp# continuation braces{} parentheses() other,;:.+−∗/ =<>&˜ |$ Lettercase(upperorlower)isignoredexceptwithinstrings,so‘a’and‘A’aretreatedasthe samecharacter.Alloftheexamplesbelowareprintedinlowercase.Anexclamationmark(‘!’) maybeusedinplaceofatilde(‘˜ ’).Squarebrackets(‘[’and‘]’)maybeusedinplaceofbraces (‘{’and‘}’). 2.2.Lines EFLisaline-orientedlanguage.Exceptinspecialcases(discussedbelow),theendofaline markstheendofatokenandtheendofastatement.Thetrailingportionofalinemaybeused foracomment.Thereisamechanismfordivertinginputfromonesourcefiletoanother,soasinglelineintheprogrammaybereplacedbyanumberoflinesfromtheotherfile.Diagnosticmessagesarelabeledwiththelinenumberofthefileonwhichtheyaredetected. 2.2.1.WhiteSpace Outsideofacharacterstringorcomment,anysequenceofoneormorespacesortabcharactersactsasasinglespace.Suchaspaceterminatesatoken. 2.2.2.Comments Acommentmayappearattheendofanyline.Itisintroducedbyasharp(#)character, andcontinuestotheendoftheline.(Asharpinsideofaquotedstringdoesnotmarkacomment.)Thesharpandsucceedingcharactersonthelinearediscarded.Ablanklineisalsoa comment.Commentshavenoeffectonexecution. 2.2.3.IncludeFiles Itispossibletoinsertthecontentsofafileatapointinthesourcetext,byreferencingitin alinelike includejoe Nostatementorcommentmayfollowanincludeonaline.Ineffect,theincludelineisreplaced bythelinesinthenamedfile,butdiagnosticsrefertothelinenumberintheincludedfile. Includesmaybenestedatleasttendeep. 2.2.4.Continuation Linesmaybecontinuedexplicitlybyusingtheunderscore()character.Ifthelastcharacterofaline(aftercommentsandtrailingwhitespacehavebeenstripped)isanunderscore,the endoflineandtheinitialblanksonthenextlineareignored.Underscoresareignoredinother contexts(exceptinsideofquotedstrings).Thus -3-1000000 000 equals109. Therearealsorulesforcontinuinglinesautomatically:theendoflineisignoredwheneverit isobviousthatthestatementisnotcomplete.Tobespecific,astatementiscontinuedifthelast tokenonalineisanoperator,comma,leftbrace,orleftparenthesis.(Astatementisnotcontinuedjustbecauseofunbalancedbracesorparentheses.)Somecompoundstatementsarealsocontinuedautomatically;thesepointsarenotedinthesectionsonexecutablestatements. 2.2.5.MultipleStatementsonaLine Asemicolonterminatesthecurrentstatement.Thus,itispossibletowritemorethanone statementonaline.Alineconsistingonlyofasemicolon,orasemicolonfollowingasemicolon, formsanullstatement. 2.3.Tokens Aprogramismadeupofasequenceoftokens.Eachtokenisasequenceofcharacters.A blankterminatesanytokenotherthanaquotedstring.Endoflinealsoterminatesatokenunless explicitcontinuation(seeabove)issignaledbyanunderscore. 2.3.1.Identifiers Anidentifierisaletteroraletterfollowedbylettersordigits.Thefollowingisalistofthe reservedwordsthathavespecialmeaninginEFL.Theywillbediscussedlater. arrayexitprecision automaticexternalprocedure breakfalseread callfieldreadbin caseforreal characterfunctionrepeat commongoreturn complexgotoselect continueifshort debugimplicitsizeof defaultincludestatic defineinitialstruct dimensionintegersubroutine dointernaltrue doublelengthofuntil doubleprecisionlogicalvalue elselongwhile endnextwrite equivalenceoptionwritebin Theuseofthesewordsisdiscussedbelow.Thesewordsmaynotbeusedforanyotherpurpose. 2.3.2.Strings Acharacterstringisasequenceofcharacterssurroundedbyquotationmarks.Ifthestring isboundedbysingle-quotemarks(´ ),itmaycontaindoublequotemarks("),andviceversa. Aquotedstringmaynotbebrokenacrossalineboundary. ´ hellothere´ "ain´ tmisbehavin´ " -4-2.3.3.IntegerConstants Anintegerconstantisasequenceofoneormoredigits. 0 57 123456 2.3.4.FloatingPointConstants Afloatingpointconstantcontainsadotand/oranexponentfield.Anexponentfieldisa letterdorefollowedbyanoptionallysignedintegerconstant.IfIandJareintegerconstants andEisanexponentfield,thenafloatingconstanthasoneofthefollowingforms: .I I. I.J IE I.E .IE I.JE 2.3.5.Punctuation Certaincharactersareusedtogrouporseparateobjectsinthelanguage.Theseare parentheses() braces{} comma, semicolon; colon: end-of-line Theend-of-lineisatoken(statementseparator)whenthelineisneitherblanknorcontinued. 2.3.6.Operators TheEFLoperatorsarewrittenassequencesofoneormorenon-alphanumericcharacters. +−∗/∗∗ <<=>>===˜ = &&||&| +=−=/=∗∗= &&=||=&=|= −>.$ Adot(‘.’)isanoperatorwhenitqualifiesastructureelementname,butnotwhenitactsasa decimalpointinanumericconstant.Thereisaspecialmode(seetheAtavismssection)inwhich someoftheoperatorsmayberepresentedbyastringconsistingofadot,anidentifier,andadot (e.g.,.lt.). 2.4.Macros EFLhasasimplemacrosubstitutionfacility.Anidentifiermaybedefinedtobeequaltoa stringoftokens;wheneverthatnameappearsasatokenintheprogram,thestringreplacesit.A macronameisgivenavalueinadefinestatementlike definecountn+=1 Anytimethenamecountappearsintheprogram,itisreplacedbythestatement -5-n+=1 Adefinestatementmustappearaloneonaline;theformis definenamerest-of-line Trailingcommentsarepartofthestring. 3.PROGRAMFORM 3.1.Files Afileisasequenceoflines.Afileiscompiledasasingleunit.Itmaycontainoneormore procedures.Declarationsandoptionsthatappearoutsideofaprocedureaffectthesucceeding proceduresonthatfile. 3.2.Procedures ProceduresarethelargestgroupingofstatementsinEFL.Eachprocedurehasanameby whichitisinvoked.(Thefirstprocedureinvokedduringexecution,knownasthemainprocedure, hasthenullname.)ProcedurecallsandargumentpassingarediscussedinSection8. 3.3.Blocks Statementsmaybeformedintogroupsinsideofaprocedure.Todescribethescopeof names,itisconvenienttointroducetheideasofblockandofnestinglevel.Thebeginningofa programfileisatnestinglevelzero.Anyoptions,macrodefinitions,orvariabledeclarationsthere arealsoatlevelzero.Thetextimmediatelyfollowingaprocedurestatementisatlevel1.After thedeclarations,aleftbracemarksthebeginningofanewblockandincreasesthenestinglevel by1;arightbracedropsthelevelby1.(Bracesinsidedeclarationsdonotmarkblocks.)(See Section7.2).Anendstatementmarkstheendoftheprocedure,level1,andthereturntolevel0. Aname(variableormacro)thatisdefinedatlevelkisdefinedthroughoutthatblockandinall deepernestedlevelsinwhichthatnameisnotredefinedorredeclared.Thus,aproceduremight looklikethefollowing: #block0 proceduregeorge realx x=2 ... if(x>2) {#newblock integerx#adifferentvariable dox=1,7 write(,x) ... }#endofblock end#endofprocedure,returntoblock0 3.4.Statements Astatementisterminatedbyendoflineorbyasemicolon.Statementsareofthefollowing types:

-6-Option Include Define Procedure End Declarative Executable TheoptionstatementisdescribedinSection10.Theinclude,define,andendstatementshave beendescribedabove;theymaynotbefollowedbyanotherstatementonaline.Eachprocedure beginswithaprocedurestatementsandfinisheswithanendstatement;thesearediscussedin Section8.Declarationsdescribetypesandvaluesofvariablesandprocedures.Executablestatementscausespecificactionstobetaken.Ablockisanexampleofanexecutablestatement;itis madeupofdeclarativeandexecutablestatements. 3.5.Labels Anexecutablestatementmayhavealabelwhichmaybeusedinabranchstatement.A labelisanidentifierfollowedbyacolon,asin read(,x) if(x<3)gotoerror ... error:fatal("badinput") 4.DATATYPESANDVARIABLES EFLsupportsasmallnumberofbasic(scalar)types.Theprogrammermaydefineobjects madeupofvariablesofbasictype;otheraggregatesmaythenbedefinedintermsofpreviously definedaggregates. 4.1.BasicTypes Thebasictypesare logical integer field(m:n) real complex longreal longcomplex character(n) Alogicalquantitymaytakeonthetwovaluestrueandfalse.Anintegermaytakeonanywhole numbervalueinsomemachine-dependentrange.Afieldquantityisanintegerrestrictedtoapar-ticularclosedinterval([m:n]).A‘real’quantityisafloatingpointapproximationtoarealor rationalnumber.Alongrealisamorepreciseapproximationtoarational.(Realquantitiesare representedassingleprecisionfloatingpointnumbers;longrealsaredoubleprecisionfloating pointnumbers.)Acomplexquantityisanapproximationtoacomplexnumber,andisrepresentedasapairofreals.Acharacterquantityisafixed-lengthstringofncharacters. 4.2.Constants Thereisanotationforaconstantofeachbasictype. Alogicalmaytakeonthetwovalues -7-true false Anintegerorfieldconstantisafixedpointconstant,optionallyprecededbyaplusorminussign, asin 17 −94 +6 0 Alongreal(‘doubleprecision’)constantisafloatingpointconstantcontaininganexponentfield thatbeginswiththeletterd.Areal(‘singleprecision’)constantisanyotherfloatingpointconstant.Arealorlongrealconstantmaybeprecededbyaplusorminussign.Thefollowingare validrealconstants: 17.3 −.4 7.9e−6(=7.9×10−6) 14e9(=1.4×1010) Thefollowingarevalidlongrealconstants 7.9d−6(=7.9×10−6) 5d3 Acharacterconstantisaquotedstring. 4.3.Variables Avariableisaquantitywithanameandalocation.Atanyparticulartimethevariable mayalsohaveavalue.(Avariableissaidtobeundefinedbeforeitisinitializedorassignedits firstvalue,andaftercertainindefiniteoperationsareperformed.)Eachvariablehascertain attributes: 4.3.1.StorageClass Theassociationofanameandalocationiseithertransitoryorpermanent.Transitoryassociationisachievedwhenargumentsarepassedtoprocedures.Otherassociationsarepermanent (static).(AfutureextensionofEFLmayincludedynamicallyallocatedvariables.) 4.3.2.ScopeofNames Thenamesofcommonareasareglobal,asareprocedurenames:thesenamesmaybeused anywhereintheprogram.Allothernamesarelocaltotheblockinwhichtheyaredeclared. 4.3.3.Precision Floatingpointvariablesareeitherofnormalorlongprecision.Thisattributemaybe statedindependentlyofthebasictype. 4.4.Arrays Itispossibletodeclarerectangulararrays(ofanydimension)ofvaluesofthesametype. Theindexsetisalwaysacross-productofintervalsofintegers.Thelowerandupperboundsof theintervalsmustbeconstantsforarraysthatarelocalorcommon.Aformalargumentarray mayhaveintervalsthatareoflengthequaltooneoftheotherformalarguments.Anelementof anarrayisdenotedbythearraynamefollowedbyaparenthesizedcomma-separatedlistofinteger values,eachofwhichmustliewithinthecorrespondinginterval.(Theintervalsmayincludenegativenumbers.)Entirearraysmaybepassedasprocedureargumentsorininput/outputlists,or theymaybeinitialized;allotherarrayreferencesmustbetoindividualelements.

-8-4.5.Structures Itispossibletodefinenewtypeswhicharemadeupofelementsofothertypes.Thecompoundobjectisknownasastructure;itsconstituentsarecalledmembersofthestructure.The structuremaybegivenaname,whichactsasatypenameintheremainingstatementswithinthe scopeofitsdeclaration.Theelementsofastructuremaybeofanytype(includingpreviously definedstructures),ortheymaybearraysofsuchobjects.Entirestructuresmaybepassedto proceduresorbeusedininput/outputlists;individualelementsofstructuresmaybereferenced. Theusesofstructureswillbedetailedbelow.Thefollowingstructuremightrepresentasymbol table: structtableentry { character(8)name integerhashvalue integernumberofelements field(0:1)initialized,used,set field(0:10)type } 5.EXPRESSIONS Expressionsaresyntacticformsthatyieldavalue.Anexpressionmayhaveanyofthefollowingforms,recursivelyapplied: primary (expression) unary-operatorexpression expressionbinary-operatorexpression Inthefollowingtableofoperators,alloperatorsonalinehaveequalprecedenceandhavehigher precedencethanoperatorsonlaterlines.Themeaningsoftheseoperatorsaredescribedinsections5.3and5.4. −>. ∗∗ ∗/unary+−++−− +− <<=>>===˜ = &&& ||| $ =+=−=∗=/=∗∗=&=|=&&=||= Examplesofexpressionsare a<b&&b<c −(a+sin(x))/(5+cos(x))∗∗2 5.1.Primaries Primariesarethebasicelementsofexpressions,asfollows: 5.1.1.Constants ConstantsaredescribedinSection4.2.

-9-5.1.2.Variables Scalarvariablenamesareprimaries.Theymayappearontheleftortherightsideofan assignment.Unqualifiednamesofaggregates(structuresorarrays)mayonlyappearasprocedure argumentsandininput/outputlists. 5.1.3.ArrayElements Anelementofanarrayisdenotedbythearraynamefollowedbyaparenthesizedlistofsubscripts,oneintegervalueforeachdeclareddimension: a(5) b(6,−3,4) 5.1.4.StructureMembers Astructurenamefollowedbyadotfollowedbythenameofamemberofthatstructureconstitutesareferencetothatelement.Ifthatelementisitselfastructure,thereferencemaybefurtherqualified. a.b x(3).y(4).z(5) 5.1.5.ProcedureInvocations Aprocedureisinvokedbyanexpressionofoneoftheforms procedurename() procedurename(expression) procedurename(expression-1,...,expression-n) TheprocedurenameiseitherthenameofavariabledeclaredexternaloritisthenameofafunctionknowntotheEFLcompiler(seeSection8.5),oritistheactualnameofaprocedure,asit appearsinaprocedurestatement.Ifaprocedurenameisdeclaredexternalandisanargument ofthecurrentprocedure,itisassociatedwiththeprocedurenamepassedasactualargument;otherwiseitistheactualnameofaprocedure.Eachexpressionintheaboveiscalledanactualargument.Examplesofprocedureinvocationsare f(x) work() g(x,y+3,’xx’) Whenoneoftheseprocedureinvocationsistobeperformed,eachoftheactualargumentexpressionsisfirstevaluated.Thetypes,precisions,andboundsofactualandformalargumentsshould agree.Ifanactualargumentisavariablename,arrayelement,orstructuremember,thecalled procedureispermittedtousethecorrespondingformalargumentastheleftsideofanassignment orinaninputlist;otherwiseitmayonlyusethevalue.Aftertheformalandactualarguments areassociated,controlispassedtothefirstexecutablestatementoftheprocedure.Whena returnstatementisexecutedinthatprocedure,orwhencontrolreachestheendstatementof thatprocedure,thefunctionvalueismadeavailableasthevalueoftheprocedureinvocation. Thetypeofthevalueisdeterminedbytheattributesoftheprocedurenamethataredeclaredor impliedinthecallingprocedure,whichmustagreewiththeattributesdeclaredforthefunctionin itsprocedure.Inthespecialcaseofagenericfunction,thetypeoftheresultisalsoaffectedby thetypeoftheargument.SeeChapter8fordetails. 5.1.6.Input/OutputExpressions TheEFLinput/outputsyntacticformsmaybeusedasintegerprimariesthathaveanonzerovalueifanerroroccursduringtheinputoroutput.SeeSection7.7.

-10-5.1.7.Coercions Anexpressionofoneprecisionortypemaybeconvertedtoanotherbyanexpressionofthe form attributes(expression) Atpresent,theonlyattributespermittedareprecisionandbasictypes.Attributesareseparated bywhitespace.Anarithmeticvalueofonetypemaybecoercedtoanyotherarithmetictype;a characterexpressionofonelengthmaybecoercedtoacharacterexpressionofanotherlength;logicalexpressionsmaynotbecoercedtoanonlogicaltype.Asaspecialcase,aquantityofcomplexorlongcomplextypemaybeconstructedfromtwointegerorrealquantitiesbypassing twoexpressions(separatedbyacomma)inthecoercion.Examplesandequivalentvaluesare integer(5.3)=5 longreal(5)=5.0d0 complex(5,3)=5+3i Mostconversionsaredoneimplicitly,sincemostbinaryoperatorspermitoperandsofdifferent arithmetictypes.Explicitcoercionsareofmostusewhenitisnecessarytoconvertthetypeofan actualargumenttomatchthatofthecorrespondingformalparameterinaprocedurecall. 5.1.8.Sizes Thereisanotationwhichyieldstheamountofmemoryrequiredtostoreadatumoran itemofspecifiedtype: sizeof(leftside) sizeof(attributes) Inthefirstcase,leftsidecandenoteavariable,array,arrayelement,orstructuremember.The valueofsizeofisaninteger,whichgivesthesizeinarbitraryunits.Ifthesizeisneededinterms ofthesizeofsomespecificunit,thiscanbecomputedbydivision: sizeof(x)/sizeof(integer) yieldsthesizeofthevariablexinintegerwords. Thedistancebetweenconsecutiveelementsofanarraymaynotequalsizeofbecausecertain datatypesrequirefinalpaddingonsomemachines.Thelengthofoperatorgivesthislarger value,againinarbitraryunits.Thesyntaxis lengthof(leftside) lengthof(attributes) 5.2.Parentheses Anexpressionsurroundedbyparenthesesisitselfanexpression.Aparenthesizedexpression mustbeevaluatedbeforeanexpressionofwhichitisapartisevaluated. 5.3.UnaryOperators AlloftheunaryoperatorsinEFLareprefixoperators.Theresultofaunaryoperatorhas thesametypeasitsoperand. 5.3.1.Arithmetic Unary+hasnoeffect.Aunary−yieldsthenegativeofitsoperand. Theprefixoperator++addsonetoitsoperand.Theprefixoperator−−subtractsone fromitsoperand.Thevalueofeitherexpressionistheresultoftheadditionorsubtraction.For thesetwooperators,theoperandmustbeascalar,arrayelement,orstructurememberofarithmetictype.(Asasideeffect,theoperandvalueischanged.)

-11-5.3.2.Logical Theonlylogicalunaryoperatoriscomplement(˜ ).Thisoperatorisdefinedbytheequations ˜ true=false ˜ false=true 5.4.BinaryOperators MostEFLoperatorshavetwooperands,separatedbytheoperator.Becausethecharacter setmustbelimited,someoftheoperatorsaredenotedbystringsoftwoorthreespecialcharacters.Allbinaryoperatorsexceptexponentiationareleftassociative. 5.4.1.Arithmetic Thebinaryarithmeticoperatorsare +addition −subtraction ∗multiplication /division ∗∗exponentiation Exponentiationisrightassociative:a∗∗b∗∗c=a∗∗(b∗∗c)=a(bc)Theoperationshavetheconventionalmeanings:8+2=10,8−2=6,8∗2=16,8/2=4,8∗∗2=82=64. ThetypeoftheresultofabinaryoperationAopBisdeterminedbythetypesofits operands: TypeofB TypeofAintegerreallongrealcomplexlongcomplex integerintegerreallongrealcomplexlongcomplex realrealreallongrealcomplexlongcomplex longreallongreallongreallongreallongcomplexlongcomplex complexcomplexcomplexlongcomplexcomplexlongcomplex longcomplexlongcomplexlongcomplexlongcomplexlongcomplexlongcomplex Ifthetypeofanoperanddiffersfromthetypeoftheresult,thecalculationisdoneasifthe operandwerefirstcoercedtothetypeoftheresult.Ifbothoperandsareintegers,theresultisof typeinteger,andiscomputedexactly.(Quotientsaretruncatedtowardzero,so8/3=2.) 5.4.2.Logical ThetwobinarylogicaloperationsinEFL,andandor,aredefinedbythetruthtables: ABAandBAorB falsefalsefalsefalse falsetruefalsetrue truefalsefalsetrue truetruetruetrue Eachoftheseoperatorscomesintwoforms.Inoneform,theorderofevaluationisspecified. Theexpression a&&b isevaluatedbyfirstevaluatinga;ifitisfalsethentheexpressionisfalseandbisnotevaluated; otherwisetheexpressionhasthevalueofb.Theexpression -12-a||b isevaluatedbyfirstevaluatinga;ifitistruethentheexpressionistrueandbisnotevaluated; otherwisetheexpressionhasthevalueofb.Theotherformsoftheoperators(&forandand| foror)donotimplyanorderofevaluation.Withthelatteroperators,thecompilermayspeed upthecodebyevaluatingtheoperandsinanyorder. 5.4.3.RelationalOperators Therearesixrelationsbetweenarithmeticquantities.Theseoperatorsarenotassociative. EFLOperatorMeaning <<lessthan <=≤lessthanorequalto ===equalto ˜ =≠notequalto >>greaterthan >=≥greaterthanorequal Sincethecomplexnumbersarenotordered,theonlyrelationaloperatorsthatmaytakecomplex operandsare==and˜ =.Thecharactercollatingsequenceisnotdefined. 5.4.4.AssignmentOperators Alloftheassignmentoperatorsarerightassociative.Thesimpleformofassignmentis basic-left-side=expression Abasic-left-sideisascalarvariablename,arrayelement,orstructurememberofbasictype.This statementcomputestheexpressionontherightside,andstoresthatvalue(possiblyaftercoercing thevaluetothetypeoftheleftside)inthelocationnamedbytheleftside.Thevalueofthe assignmentexpressionisthevalueassignedtotheleftsideaftercoercion. Thereisalsoanassignmentoperatorcorrespondingtoeachbinaryarithmeticandlogical operator.Ineachcase,aop=bisequivalenttoa=aopb.(Theoperatorandequalsignmust notbeseparatedbyblanks.)Thus,n+=2adds2ton.Thelocationoftheleftsideisevaluated onlyonce. 5.5.DynamicStructures EFLdoesnothaveanaddress(pointer,reference)type.However,thereisanotationfor dynamicstructures, leftside−>structurename Thisexpressionisastructurewiththeshapeimpliedbystructurenamebutstartingatthelocationofleftside.Ineffect,thisoverlaysthestructuretemplateatthespecifiedlocation.Theleftsidemustbeavariable,array,arrayelement,orstructuremember.Thetypeoftheleftsidemust beoneofthetypesinthestructuredeclaration.Anelementofsuchastructureisdenotedinthe usualwayusingthedotoperator.Thus, place(i)−>st.elt referstotheeltmemberoftheststructurestartingattheithelementofthearrayplace. 5.6.RepetitionOperator Insideofalist,anelementoftheform integer-constant-expression$constant-expression isequivalenttotheappearanceoftheexpressionanumberoftimesequaltothefirstexpression. Thus, -13- (3,3$4,5) isequivalentto (3,4,4,4,5) 5.7.ConstantExpressions Ifanexpressionisbuiltupoutofoperators(otherthanfunctions)andconstants,thevalue oftheexpressionisaconstant,andmaybeusedanywhereaconstantisrequired. 6.DECLARATIONS Declarationsstatementdescribethemeaning,shape,andsizeofnamedobjectsintheEFL language. 6.1.Syntax Adeclarationstatementismadeupofattributesandvariables.Declarationstatementsare oftwoform: attributesvariable-list attributes{declarations} Inthefirstcase,eachnameinthevariable-listhasthespecifiedattributes.Inthesecond,each nameinthedeclarationsalsohasthespecifiedattributes.Avariablenamemayappearinmore thanonevariablelist,solongastheattributesarenotcontradictory.Eachnameofanonargumentvariablemaybeaccompaniedbyaninitialvaluespecification.Thedeclarationsinsidethe bracesareoneormoredeclarationstatements.Examplesofdeclarationsare integerk=2 longrealb(7,3) common(cname) { integeri longrealarray(5,0:3)x,y character(7)ch } 6.2.Attributes 6.2.1.BasicTypes Thefollowingarebasictypesindeclarations logical integer field(m:n) character(k) real complex Intheabove,thequantitiesk,m,andndenoteintegerconstantexpressionswiththeproperties k>0andn>m. 6.2.2.Arrays Thedimensionalitymaybedeclaredbyanarrayattribute array(b1,...,bn)

-14-Eachofthebimayeitherbeasingleintegerexpressionorapairofintegerexpressionsseparated byacolon.Thepairofexpressionsformalowerandanupperbound;thesingleexpressionisan upperboundwithanimpliedlowerboundof1.Thenumberofdimensionsisequalton,the numberofbounds.Alloftheintegerexpressionsmustbeconstants.Anexceptionispermitted onlyifallofthevariablesassociatedwithanarraydeclaratorareformalargumentsoftheprocedure;inthiscase,eachboundmusthavethepropertythatupper−lower+1isequaltoaformal argumentoftheprocedure.(Thecompilerhaslimitedabilitytosimplifyexpressions,butitwill recognizeimportantcasessuchas(0:n−1).Theupperboundforthelastdimension(bn)maybe markedbyanasterisk(∗)ifthesizeofthearrayisnotknown.Thefollowingarelegalarray attributes: array(5) array(5,1:5,−3:0) array(5,∗) array(0:m−1,m) 6.2.3.Structures Astructuredeclarationisoftheform structstructname{declarationstatements} Thestructnameisoptional;ifitispresent,itactsasifitwerethenameofatypeintherestofits scope.Eachnamethatappearsinsidethedeclarationsisamemberofthestructure,andhasa specialmeaningwhenusedtoqualifyanyvariabledeclaredwiththestructuretype.Anamemay appearasamemberofanynumberofstructures,andmayalsobethenameofanordinaryvariable,sinceastructuremembernameisusedonlyincontextswheretheparenttypeisknown. Thefollowingarevalidstructureattributes structxx { integera,b realx(5) } struct{xxz(3);character(5)y} Thelastlinedefinesastructurecontaininganarrayofthreexx′sandacharacterstring. 6.2.4.Precision Variablesoffloatingpoint(realorcomplex)typemaybedeclaredtobelongtoensure theyhavehigherprecisionthanordinaryfloatingpointvariables.Thedefaultprecisionisshort. 6.2.5.Common Certainobjectscalledcommonareashaveexternalscope,andmaybereferencedbyanyprocedurethathasadeclarationforthenameusinga common(commonareaname) attribute.Allofthevariablesdeclaredwithaparticularcommonattributeareinthesame block;theorderinwhichtheyaredeclaredissignificant.Declarationsforthesameblockindifferingproceduresmusthavethevariablesinthesameorderandwiththesametypes,precision, andshapes,thoughnotnecessarilywiththesamenames. 6.2.6.External Ifanameisusedastheprocedurenameinaprocedureinvocation,itisimplicitlydeclared tohavetheexternalattribute.Ifaprocedurenameistobepassedasanargument,itis -15-necessarytodeclareitinastatementoftheform external[[name]] Ifanamehastheexternalattributeanditisaformalargumentoftheprocedure,thenitisassociatedwithaprocedureidentifierpassedasanactualargumentateachcall.Ifthenameisnota formalargument,thenthatnameistheactualnameofaprocedure,asitappearsinthecorrespondingprocedurestatement. 6.3.VariableList Theelementsofavariablelistinadeclarationconsistofaname,anoptionaldimension specification,andanoptionalinitialvaluespecification.Thenamefollowstheusualrules.The dimensionspecificationisthesameformandmeaningastheparenthesizedlistinanarray attribute.Theinitialvaluespecificationisanequalsign(=)followedbyaconstantexpression. Ifthenameisanarray,therightsideoftheequalsignmaybeaparenthesizedlistofconstant expressions,orrepeatedelementsorlists;thetotalnumberofelementsinthelistmustnotexceed thenumberofelementsofthearray,whicharefilledincolumn-majororder. 6.4.TheInitialStatement Aninitialvaluemayalsobespecifiedforasimplevariable,array,arrayelement,ormember ofastructureusingastatementoftheform initial[[var=val]] Thevarmaybeavariablename,arrayelementspecification,ormemberofstructure.Theright sidefollowsthesamerulesasforaninitialvaluespecificationinotherdeclarationstatements. 7.EXECUTABLESTATEMENTS EveryusefulEFLprogramcontainsexecutablestatements—otherwiseitwouldnotdoanythingandwouldnotneedtoberun.Statementsarefrequentlymadeupofotherstatements. Blocksarethemostobviouscase,butmanyotherformscontainstatementsasconstituents. ToincreasethelegibilityofEFLprograms,someofthestatementformscanbebrokenwithoutanexplicitcontinuation.Asquare()inthesyntaxrepresentsapointwheretheendofaline willbeignored. 7.1.ExpressionStatements 7.1.1.SubroutineCall Aprocedureinvocationthatreturnsnovalueisknownasasubroutinecall.Suchaninvocationisastatement.Examplesare work(in,out) run() Input/outputstatements(seeSection7.7)resembleprocedureinvocationsbutdonotyielda value.Ifanerroroccurstheprogramstops. 7.1.2.AssignmentStatements Anexpressionthatisasimpleassignment(=)oracompoundassignment(+=etc.)isa statement: a=b a=sin(x)/6 x∗=y -16-7.2.Blocks Ablockisacompoundstatementthatactsasastatement.Ablockbeginswithaleft brace,optionallyfollowedbydeclarations,optionallyfollowedbyexecutablestatements,followed byarightbrace.Ablockmaybeusedanywhereastatementispermitted.Ablockisnotan expressionanddoesnothaveavalue.Anexampleofablockis { integeri#thisvariableisunknownoutsidethebraces big=0 doi=1,n if(big<a(i)) big=a(i) } 7.3.TestStatements Teststatementspermitexecutionofcertainstatementsconditionalonthetruthofapredicate. 7.3.1.IfStatement Thesimplestoftheteststatementsistheifstatement,ofform if(logical-expression)statement Thelogicalexpressionisevaluated;ifitistrue,thenthestatementisexecuted. 7.3.2.If-Else Amoregeneralstatementisoftheform if(logical-expression)statement-1elsestatement-2 Iftheexpressionistruethenstatement-1isexecuted,otherwisestatement-2isexecuted.Either oftheconsequentstatementsmayitselfbeanif-elsesoacompletelynestedtestsequenceispossi-ble: if(x<y) if(a<b) k=1 else k=2 else if(a<b) m=1 else m=2 Anelseappliestothenearestprecedingun-elsedif.Amorecommonuseisasasequentialtest: if(x==1) k=1 elseif(x==3|x==5) k=2 else k=3 -17-7.3.3.SelectStatement Amultiwaytestonthevalueofaquantityissuccinctlystatedasaselectstatement,which hasthegeneralform select(expression)block Insidetheblocktwospecialtypesoflabelsarerecognized.Aprefixoftheform case[[constant]]: marksthestatementtowhichcontrolispassediftheexpressionintheselecthasavalueequalto oneofthecaseconstants.Iftheexpressionequalsnoneoftheseconstants,butthereisalabel defaultinsidetheselect,abranchistakentothatpoint;otherwisethestatementfollowingthe rightbraceisexecuted.Onceexecutionbeginsatacaseordefaultlabel,itcontinuesuntilthe nextcaseordefaultisencountered.Theelse-ifexampleaboveisbetterwrittenas select(x) { case1: k=1 case3,5: k=2 default: k=3 } Notethatcontroldoesnot‘fallthrough’tothenextcase. 7.4.Loops Theloopformsprovidethebestwayofrepeatingastatementorsequenceofoperations. Thesimplest(while)formistheoreticallysufficient,butitisveryconvenienttohavethemore generalloopsavailable,sinceeachexpressesamodeofcontrolthatarisesfrequentlyinpractice. 7.4.1.WhileStatement Thisconstructhastheform while(logical-expression)statement Theexpressionisevaluated;ifitistrue,thestatementisexecuted,andthenthetestisperformed again.Iftheexpressionisfalse,executionproceedstothenextstatement. 7.5.ForStatement Theforstatementisamoreelaborateloopingconstruct.Ithastheform for(initial-statement,logical-expression,iteration-statement)body-statement Exceptforthebehaviorofthenextstatement(seeSection7.6.3),thisconstructisequivalentto initial-statement while(logical-expression) { body-statement iteration-statement } Thisformisusefulforgeneralarithmeticiterations,andforvariouspointer-typeoperations.The sumoftheintegersfrom1to100canbecomputedbythefragment -18-n=0 for(i=1,i<=100,i+=1) n+=i Alternatively,thecomputationcouldbedonebythesinglestatement for({n=0;i=1},i<=100,{n+=i;++i}) ; Notethatthebodyoftheforloopisanullstatementinthiscase.Anexampleoffollowinga linkedlistwillbegivenlater. 7.5.1.RepeatStatement Thestatement repeatstatement executesthestatement,thendoesitagain,withoutanyterminationtest.Obviously,atestinside thestatementisneededtostoptheloop. 7.5.2.Repeat...UntilStatement Thewhileloopperformsatestbeforeeachiteration.Thestatement repeatstatementuntil(logical-expression) executesthestatement,thenevaluatesthelogical;ifthelogicalistruetheloopiscomplete;otherwisecontrolreturnstothestatement.Thus,thebodyisalwaysexecutedatleastonce.The untilreferstothenearestprecedingrepeatthathasnotbeenpairedwithanuntil.Inpractice, thisappearstobetheleastfrequentlyusedloopingconstruct. 7.5.3.DoLoops Thesimplearithmeticprogressionisaverycommononeinnumericalapplications.EFLhas aspecialloopformforrangingoveranascendingarithmeticsequence dovariable=expression-1,expression-2,expression-3 statement Thevariableisfirstgiventhevalueexpression-1.Thestatementisexecuted,thenexpression-3is addedtothevariable.Theloopisrepeateduntilthevariableexceedsexpression-2.Ifexpres-sion-3andtheprecedingcommaareomitted,theincrementistakentobe1.Theloopaboveis equivalentto t2=expression-2 t3=expression-3 for(variable=expression-1,variable<=t2,variable+=t3) statement (ThecompilertranslatesEFLdostatementsintoFortranDOstatements,whichareinturnusuallycompiledintoexcellentcode.)Thedovariablemaynotbechangedinsideoftheloop,and expression-1mustnotexceedexpression-2.Thesumofthefirsthundredpositiveintegerscould becomputedby n=0 doi=1,100 n+=i 7.6.BranchStatements Mostoftheneedforbranchstatementsinprogramscanbeavertedbyusingtheloopand testconstructs,butthereareprogramswheretheyareveryuseful.

-19-7.6.1.GotoStatement Themostgeneral,andmostdangerous,branchingstatementisthesimpleunconditional gotolabel Afterexecutingthisstatement,thenextstatementperformedistheonefollowingthegivenlabel. Insideofaselectthecaselabelsofthatblockmaybeusedaslabels,asinthefollowingexample: select(k) { case1: error(7) case2: k=2 gotocase4 case3: k=5 gotocase4 case4: fixup(k) gotodefault default: prmsg("ouch") } (Iftwoselectstatementsarenested,thecaselabelsoftheouterselectarenotaccessiblefrom theinnerone.) 7.6.2.BreakStatement Asaferstatementisonewhichtransferscontroltothestatementfollowingthecurrent selectorloopform.Astatementofthissortisalmostalwaysneededinarepeatloop: repeat { doacomputation if(finished) break } Moregeneralformspermitcontrollingabranchoutofmorethanoneconstruct. break3 transferscontroltothestatementfollowingthethirdloopand/orselectsurroundingthestatement.Itispossibletospecifywhichtypeofconstruct(for,while,repeat,do,orselect)isto becounted.Thestatement breakwhile breaksoutofthefirstsurroundingwhilestatement.Eitherofthestatements break3for breakfor3 willtransfertothestatementafterthethirdenclosingforloop.

-20-7.6.3.NextStatement Thenextstatementcausesthefirstsurroundingloopstatementtogoontothenextiteration:thenextoperationperformedisthetestofawhile,theiteration-statementofafor,the bodyofarepeat,thetestofarepeat...until,ortheincrementofado.Elaborationssimilarto thoseforbreakareavailable: next next3 next3for nextfor3 Anextstatementignoresselectstatements. 7.6.4.Return Thelaststatementofaprocedureisfollowedbyareturnofcontroltothecaller.Ifitis desiredtoeffectsuchareturnfromanyotherpointintheprocedure,a return statementmaybeexecuted.Insideafunctionprocedure,thefunctionvalueisspecifiedasan argumentofthestatement: return(expression) 7.7.Input/OutputStatements EFLhastwoinputstatements(readandreadbin),twooutputstatements(writeand writebin),andthreecontrolstatements(endfile,rewind,andbackspace).Theseformsmay beusedeitherasaprimarywithaintegervalueorasastatement.Ifanexceptionoccurswhen oneoftheseformsisusedasastatement,theresultisundefinedbutwillprobablybetreatedasa fatalerror.Iftheyareusedinacontextwheretheyreturnavalue,theyreturnzeroifnoexceptionoccurs.Fortheinputforms,anegativevalueindicatesend-of-fileandapositivevaluean error.Theinput/outputpartofEFLverystronglyreflectsthefacilitiesofFortran. 7.7.1.Input/OutputUnits EachI/Ostatementreferstoa‘unit’,identifiedbyasmallpositiveinteger.Twospecial unitsaredefinedbyEFL,thestandardinputunitandthestandardoutputunit.Theseparticular unitsareassumedifnounitisspecifiedinanI/Otransmissionstatement. Thedataontheunitareorganizedintorecords.Theserecordsmaybereadorwrittenina fixedsequence,andeachtransmissionmovesanintegralnumberofrecords.Transmissionproceedsfromthefirstrecorduntiltheendoffile. 7.7.2.BinaryInput/Output Thereadbinandwritebinstatementstransmitdatainamachine-dependentbutswift manner.Thestatementsareoftheform writebin(unit,binary-output-list) readbin(unit,binary-input-list) Eachstatementmovesoneunformattedrecordbetweenstorageandthedevice.Theunitisan integerexpression.Abinary-output-listisaniolist(seebelow)withoutanyformatspecifiers.A binary-input-listisaniolistwithoutformatspecifiersinwhicheachoftheexpressionsisavariable name,arrayelement,orstructuremember.

-21-7.7.3.FormattedInput/Output Thereadandwritestatementstransmitdataintheformoflinesofcharacters.Each statementmovesoneormorerecords(lines).Numbersaretranslatedintodecimalnotation.The exactformofthelinesisdeterminedbyformatspecifications,whetherprovidedexplicitlyinthe statementorimplicitly.Thesyntaxofthestatementsis write(unit,formatted-output-list) read(unit,formatted-input-list) ThelistsareofthesameformasforbinaryI/O,exceptthatthelistsmayincludeformatspecifications.Iftheunitisomitted,thestandardinputoroutputunitisused. 7.7.4.Iolists Aniolistspecifiesasetofvaluestobewrittenorasetofvariablesintowhichvaluesareto beread.Aniolistisalistofoneormoreioexpressionsoftheform expression {iolist} do-specification{iolist} ForformattedI/O,anioexpressionmayalsohavetheforms ioexpression:format-specifier :format-specifier Ado-specificationlooksjustlikeadostatement,andhasasimilareffect:thevaluesinthebraces aretransmittedrepeatedlyuntilthedoexecutioniscomplete. 7.7.5.Formats Thefollowingarepermissibleformat-specifiers.Thequantitiesw,d,andkmustbeinteger constantexpressions. i(w)integerwithwdigits f(w,d)floatingpointnumberofwcharacters, dofthemtotherightofthedecimalpoint. e(w,d)floatingpointnumberofwcharacters, dofthemtotherightofthedecimalpoint, withtheexponentfieldmarkedwiththelettere l(w)logicalfieldofwidthwcharacters, thefirstofwhichistorf (therestareblankonoutput,ignoredoninput) standingfortrueandfalserespectively ccharacterstringofwidthequaltothelengthofthedatum c(w)characterstringofwidthw s(k)skipklines x(k)skipkspaces "..."usethecharactersinsidethestringasaFortranformat Ifnoformatisspecifiedforaniteminaformattedinput/outputstatement,adefaultformischosen. Ifaniteminalistisanarrayname,thentheentirearrayistransmittedasasequenceof elements,eachwithitsownformat.Theelementsaretransmittedincolumn-majororder,the sameorderusedforarrayinitializations. 7.7.6.Manipulationstatements Thethreeinput/outputstatements -22-backspace(unit) rewind(unit) endfile(unit) looklikeordinaryprocedurecalls,butmaybeusedeitherasstatementsorasintegerexpressions whichyieldnon-zeroifanerrorisdetected.backspacecausesthespecifiedunittobackup,so thatthenextreadwillre-readthepreviousrecord,andthenextwritewillover-writeit.rewind movesthedevicetoitsbeginning,sothatthenextinputstatementwillreadthefirstrecord. endfilecausesthefiletobemarkedsothattherecordmostrecentlywrittenwillbethelast recordonthefile,andanyattempttoreadpastisanerror. 8.PROCEDURES ProceduresarethebasicunitofanEFLprogram,andprovidethemeansofsegmentinga programintoseparatelycompilableandnamedparts. 8.1.ProcedureStatement Eachprocedurebeginswithastatementofoneoftheforms procedure attributesprocedureprocedurename attributesprocedureprocedurename() attributesprocedureprocedurename([[name]]) Thefirstcasespecifiesthemainprocedure,whereexecutionbegins.Inthetwoothercases,the attributesmayspecifyprecisionandtype,ortheymaybeomittedentirely.Theprecisionand typeoftheproceduremaybedeclaredinanordinarydeclarationstatement.Ifnotypeis declared,thentheprocedureiscalledasubroutineandnovaluemaybereturnedforit.Otherwise,theprocedureisafunctionandavalueofthedeclaredtypeisreturnedforeachcall.Each nameinsidetheparenthesesinthelastformaboveiscalledaformalargumentoftheprocedure. 8.2.EndStatement Eachprocedureterminateswithastatement end 8.3.ArgumentAssociation Whenaprocedureisinvoked,theactualargumentsareevaluated.Ifanactualargumentis thenameofavariable,anarrayelement,orastructuremember,thatentitybecomesassociated withtheformalargument,andtheproceduremayreferencethevaluesintheobject,andassignto it.Otherwise,thevalueoftheactualisassociatedwiththeformalargument,buttheprocedure maynotattempttochangethevalueofthatformalargument. Ifthevalueofoneoftheargumentsischangedintheprocedure,itisnotpermittedthatthe correspondingactualargumentbeassociatedwithanotherformalargumentorwithacommon elementthatisreferencedintheprocedure. 8.4.ExecutionandReturnValues Afteractualandformalargumentshavebeenassociated,controlpassestothefirstexecutablestatementoftheprocedure.Controlreturnstotheinvokereitherwhentheendstatementoftheprocedureisreachedorwhenareturnstatementisexecuted.Iftheprocedureisa function(hasadeclaredtype),andareturn(value)isexecuted,thevalueiscoercedtothecorrecttypeandprecisionandreturned.

-23-8.5.KnownFunctions AnumberoffunctionsareknowntoEFL,andneednotbedeclared.Thecompilerknows thetypesofthesefunctions.Someofthemaregeneric;i.e.,theynameafamilyoffunctionsthat differinthetypesoftheirargumentsandreturnvalues.Thecompilerchooseswhichelementof thesettoinvokebasedupontheattributesoftheactualarguments. 8.5.1.MinimumandMaximumFunctions Thegenericfunctionsareminandmax.Themincallsreturnthevalueoftheirsmallest argument;themaxcallsreturnthevalueoftheirlargestargument.Thesearetheonlyfunctions thatmaytakedifferentnumbersofargumentsindifferentcalls.Ifanyoftheargumentsarelong realthentheresultislongreal.Otherwise,ifanyoftheargumentsarerealthentheresultis real;otherwisealltheargumentsandtheresultmustbeinteger.Examplesare min(5,x,−3.20) max(i,z) 8.5.2.AbsoluteValue Theabsfunctionisagenericfunctionthatreturnsthemagnitudeofitsargument.Forintegerandrealargumentsthetypeoftheresultisidenticaltothetypeoftheargument;forcomplex argumentsthetypeoftheresultistherealofthesameprecision. 8.5.3.ElementaryFunctions Thefollowinggenericfunctionstakeargumentsofreal,longreal,orcomplextypeand returnaresultofthesametype: sinsinefunction coscosinefunction expexponentialfunction(ex). lognatural(basee)logarithm log10common(base10)logarithm sqrtsquarerootfunction(√x). Inaddition,thefollowingfunctionsacceptonlyrealorlongrealarguments: atanatan(x)=tan−1x atan2atan2(x,y)=tan−1xy 8.5.4.OtherGenericFunctions Thesignfunctionstakestwoargumentsofidenticaltype;sign(x,y)=sgn(y)|x|.Themod functionyieldstheremainderofitsfirstargumentwhendividedbyitssecond.Thesefunctions acceptintegerandrealarguments. 9.ATAVISMS CertainfacilitiesareincludedintheEFLlanguagetoeasetheconversionofoldFortranor RatforprogramstoEFL. 9.1.EscapeLines InordertomakeuseofnonstandardfeaturesofthelocalFortrancompiler,itisoccasionally necessarytopassaparticularlinethroughtotheEFLcompileroutput.Alinethatbeginswitha percentsign(‘%’)iscopiedthroughtotheoutput,withthepercentsignremovedbutnoother -24-change.Insideofaprocedure,eachescapelineistreatedasanexecutablestatement.Ifa sequenceoflinesconstituteacontinuedFortranstatement,theyshouldbeenclosedinbraces. 9.2.CallStatement Asubroutinecallmaybeprecededbythekeywordcall. calljoe callwork(17) 9.3.ObsoleteKeywords ThefollowingkeywordsarerecognizedassynonymsofEFLkeywords: FortranEFL doubleprecisionlongreal functionprocedure subroutineprocedure(untyped) 9.4.NumericLabels Standardstatementlabelsareidentifiers.Anumeric(positiveintegerconstant)labelisalso permitted;thecolonisoptionalfollowinganumericlabel. 9.5.ImplicitDeclarations Ifanameisusedbutdoesnotappearinadeclaration,theEFLcompilergivesawarning andassumesadeclarationforit.Ifitisusedinthecontextofaprocedureinvocation,itis assumedtobeaprocedurename;otherwiseitisassumedtobealocalvariabledefinedatnesting level1inthecurrentprocedure.Theassumedtypeisdeterminedbythefirstletterofthename. Theassociationoflettersandtypesmaybegiveninanimplicitstatement,withsyntax implicit(letter-list)type wherealetter-listisalistofindividuallettersorranges(pairoflettersseparatedbyaminus sign).Ifnoimplicitstatementappears,thefollowingrulesareassumed: implicit(a−h,o−z)real implicit(i−n)integer 9.6.Computedgoto Fortrancontainsanindexedmulti-waybranch;thisfacilitymaybeusedinEFLbythecom-putedGOTO: goto([[label]]),expression Theexpressionmustbeoftypeintegerandbepositivebutbenolargerthanthenumberoflabels inthelist.Controlispassedtothestatementmarkedbythelabelwhosepositioninthelistis equaltotheexpression. 9.7.GoToStatement Inunconditionalandcomputedgotostatements,itispermissibletoseparatethegoandto words,asin gotoxyz -25-9.8.DotNames Fortranusesarestrictedcharacterset,andrepresentscertainoperatorsbymulti-character sequences.Thereisanoption(dots=on;seeSection10.2)whichforcesthecompilertorecognize theformsinthesecondcolumnbelow: <.lt. <=.le. >.gt. >=.ge. ==.eq. ˜ =.ne. &.and. |.or. &&.andand. ||.oror. ˜ .not. true.true. false.false. Inthismode,nostructureelementmaybenamedlt,le,etc.Thereadableformsintheleftcolumnarealwaysrecognized. 9.9.ComplexConstants Acomplexconstantmaybewrittenasaparenthesizedlistofrealquantities,suchas (1.5,3.0) Thepreferrednotationisbyatypecoercion, complex(1.5,3.0) 9.10.FunctionValues ThepreferredwaytoreturnavaluefromafunctioninEFListhereturn(value)construct. However,thenameofthefunctionactsasavariabletowhichvaluesmaybeassigned;anordinary returnstatementreturnsthelastvalueassignedtothatnameasthefunctionvalue. 9.11.Equivalence Astatementoftheform equivalencev1,v2,...,vn declaresthateachofthevistartsatthesamememorylocation.Eachofthevimaybeavariable name,arrayelementname,orstructuremember. 9.12.MinimumandMaximumFunctions Thereareanumberofnon-genericfunctionsinthiscategory,whichdifferintherequired typesoftheargumentsandthetypeofthereturnvalue.Theymayalsohavevariablenumbersof arguments,butalltheargumentsmusthavethesametype.

-26-FunctionArgumentTypeResultType amin0integerreal amin1realreal min0integerinteger min1realinteger dmin1longreallongreal amax0integerreal amax1realreal max0integerinteger max1realinteger dmax1longreallongreal 10.COMPILEROPTIONS Anumberofoptionscanbeusedtocontroltheoutputandtotailoritforvariouscompilers andsystems.Thedefaultschosenareconservative,butitissometimesnecessarytochangethe outputtomatchpeculiaritiesofthetargetenvironment. Optionsaresetwithstatementsoftheform option[[opt]] whereeachoptisofoneoftheforms optionname optionname=optionvalue Theoptionvalueiseitheraconstant(numericorstring)oranameassociatedwiththatoption. Thetwonamesyesandnoapplytoanumberofoptions. 10.1.DefaultOptions Eachoptionhasadefaultsetting.Itispossibletochangethewholesetofdefaultstothose appropriateforaparticularenvironmentbyusingthesystemoption.Atpresent,theonlyvalid valuesaresystem=unixandsystem=gcos. 10.2.InputLanguageOptions Thedotsoptiondetermineswhetherthecompilerrecognizes.lt.andsimilarforms.The defaultsettingisno. 10.3.Input/OutputErrorHandling Theioerroroptioncanbegiventhreevalues:nonemeansthatnoneoftheI/Ostatements maybeusedinexpressions,sincethereisnowaytodetecterrors.Theimplementationofthe ibmformusesERR=andEND=clauses.Theimplementationofthefortran77formuses IOSTAT=clauses. 10.4.ContinuationConventions Bydefault,continuedFortranstatementsareindicatedbyacharacterincolumn6(StandardFortran).Theoptioncontinue=column1putsanampersand(&)inthefirstcolumnof thecontinuedlinesinstead. 10.5.DefaultFormats Ifnoformatisspecifiedforadatuminaniolistforareadorwritestatement,adefaultis provided.Thedefaultformatscanbechangedbysettingcertainoptions -27-OptionType iformatinteger rformatreal dformatlongreal zformatcomplex zdformatlongcomplex lformatlogical TheassociatedvaluemustbeaFortranformat,suchas optionrformat=f22.6 10.6.AlignmentsandSizes Inordertoimplementcharactervariables,structures,andthesizeofandlengthofoperators,itisnecessarytoknowhowmuchspacevariousFortrandatatypesrequire,andwhatboundaryalignmentpropertiestheydemand.Therelevantoptionsare FortranTypeSizeOptionAlignmentOption integerisizeialign realrsizeralign longrealdsizedalign complexzsizezalign logicallsizelalign Thesizesaregivenintermsofanarbitraryunit;thealignmentisgiveninthesameunits.The optioncharperintgivesthenumberofcharactersperintegervariable. 10.7.DefaultInput/OutputUnits Theoptionsftninandftnoutarethenumbersofthestandardinputandoutputunits. Thedefaultvaluesareftnin=5andftnout=6. 10.8.MiscellaneousOutputControlOptions EachFortranproceduregeneratedbythecompilerwillbeprecededbythevalueofthe procheaderoption. NoHollerithstringswillbepassedassubroutineargumentsifhollincall=noisspecified. TheFortranstatementnumbersnormallystartat1andincreaseby1.Itispossibleto changetheincrementvaluebyusingthedeltastnooption. 11.EXAMPLES InordertoshowtheflavororprogramminginEFL,wepresentafewexamples.Theyare short,butshowsomeoftheconvenienceofthelanguage. 11.1.FileCopying Thefollowingshortprogramcopiesthestandardinputtothestandardoutput,provided thattheinputisaformattedfilecontaininglinesnolongerthanahundredcharacters. procedure#mainprogram character(100)line while(read(,line)==0) write(,line) end -28-Sincereadreturnszerountiltheendoffile(orareaderror),thisprogramkeepsreadingand writinguntiltheinputisexhausted. 11.2.MatrixMultiplication Thefollowingproceduremultipliesthem×nmatrixabythen×pmatrixbtogivethe m×pmatrixc.Thecalculationobeystheformulacij=Σaikbkj. procedurematmul(a,b,c,m,n,p) integeri,j,k,m,n,p longreala(m,n),b(n,p),c(m,p) doi=1,m doj=1,p { c(i,j)=0 dok=1,n c(i,j)+=a(i,k)∗b(k,j) } end 11.3.SearchingaLinkedList Assumewehavealistofpairsofnumbers(x,y).Thelistisstoredasalinkedlistsortedin ascendingorderofxvalues.Thefollowingproceduresearchesthislistforaparticularvalueofx andreturnsthecorrespondingyvalue. defineLAST0 defineNOTFOUND−1 integerprocedureval(list,first,x) #listisanarrayofstructures. #Eachstructurecontainsathreadindexvalue,anx,andayvalue. struct { integernextindex integerx,y }list(∗) integerfirst,p,arg for(p=first,p˜ =LAST&&list(p).x<=x,p=list(p).nextindex) if(list(p).x==x) return(list(p).y) return(NOTFOUND) end Thesearchisasingleforloopthatbeginswiththeheadofthelistandexaminesitemsuntil eitherthelistisexhausted(p==LAST)oruntilitisknownthatthespecifiedvalueisnotonthe list(list(p).x>x).Thetwotestsintheconjunctionmustbeperformedinthespecifiedorderto avoidusinganinvalidsubscriptinthelist(p)reference.Therefore,the&&operatorisused. Thenextelementinthechainisfoundbytheiterationstatementp=list(p).nextindex. 11.4.WalkingaTree Asanexampleofamorecomplicatedproblem,letusimaginewehaveanexpressiontree storedinacommonarea,andthatwewanttoprintoutaninfixformofthetree.Eachnodeis -29-eitheraleaf(containinganumericvalue)oritisabinaryoperator,pointingtoaleftandaright descendant.Inarecursivelanguage,suchatreewalkwouldbeimplementbythefollowingsimple pseudocode: ifthisnodeisaleaf printitsvalue otherwise printaleftparenthesis printtheleftnode printtheoperator printtherightnode printarightparenthesis InanonrecursivelanguagelikeEFL,itisnecessarytomaintainanexplicitstacktokeeptrackof thecurrentstateofthecomputation.Thefollowingprocedurecallsaprocedureoutchtoprinta singlecharacterandaprocedureoutvaltoprintavalue. procedurewalk(first)#printoutanexpressiontree integerfirst#indexofrootnode integercurrentnode integerstackdepth common(nodes)struct { character(1)op integerleftp,rightp realval }tree(100)#arrayofstructures struct { integernextstate integernodep }stackframe(100) defineNODEtree(currentnode) defineSTACKstackframe(stackdepth) #nextstatevalues defineDOWN1 defineLEFT2 defineRIGHT3 #initializestackwithrootnode stackdepth=1 STACK.nextstate=DOWN STACK.nodep=first -30-while(stackdepth>0) { currentnode=STACK.nodep select(STACK.nextstate) { caseDOWN: if(NODE.op=="")#aleaf { outval(NODE.val) stackdepth−=1 } else{#abinaryoperatornode outch("(") STACK.nextstate=LEFT stackdepth+=1 STACK.nextstate=DOWN STACK.nodep=NODE.leftp } caseLEFT: outch(NODE.op) STACK.nextstate=RIGHT stackdepth+=1 STACK.nextstate=DOWN STACK.nodep=NODE.rightp caseRIGHT: outch(")") stackdepth−=1 } } end 12.PORTABILITY OneofthemajorgoalsoftheEFLlanguageistomakeiteasytowriteportableprograms. TheoutputoftheEFLcompilerisintendedtobeacceptabletoanyStandardFortrancompiler (unlessthefortran77optionisspecified). 12.1.Primitives CertainEFLoperationscannotbeimplementedinportableFortran,soafewmachinedependentproceduresmustbeprovidedineachenvironment. 12.1.1.CharacterStringCopying Thesubroutineef1asciscalledtocopyonecharacterstringtoanother.Ifthetargetstring isshorterthanthesource,thefinalcharactersarenotcopied.Ifthetargetstringislonger,its endispaddedwithblanks.Thecallingsequenceis subroutineef1asc(a,la,b,lb) integera(∗),la,b(∗),lb anditmustcopythefirstlbcharactersfrombtothefirstlacharactersofa. 12.1.2.CharacterStringComparisons Thefunctionef1cmcisinvokedtodeterminetheorderoftwocharacterstrings.Thedeclarationis -31-integerfunctionef1cmc(a,la,b,lb) integera(∗),la,b(∗),lb Thefunctionreturnsanegativevalueifthestringaoflengthlaprecedesthestringboflength lb.Itreturnszeroifthestringsareequal,andapositivevalueotherwise.Ifthestringsareof differinglength,thecomparisoniscarriedoutasiftheendoftheshorterstringwerepaddedwith blanks. 13.ACKNOWLEDGMENTS A.D.HalloriginatedtheEFLlanguageandwrotethefirstcompilerforit;healsogaveinestimableaidwhenItookuptheproject.B.W.KernighanandW.S.Brownmadeanumberof usefulsuggestionsaboutthelanguageandaboutthisreport.N.L.Schryerhasactedaswilling, cheerful,andseverefirstuserandhelpfulcriticofeachnewversionandfacility.J.L.Blue,L.C. Kaufman,andD.D.Warnermadeveryusefulcontributionsbymakingserioususeofthecompiler,andnotingandtoleratingitsmisbehaviors. 14.REFERENCE 1.B.W.Kernighan,‘‘Ratfor—APreprocessorforaRationalFortran’’,BellLaboratories ComputingScienceTechnicalReport#55 -32-APPENDIXA.RelationBetweenEFLandRatfor ThereareanumberofdifferencesbetweenRatforandEFL,sinceEFLisadefinedlanguage whileRatforistheunionofthespecialcontrolstructuresandthelanguageacceptedbytheunderlyingFortrancompiler.RatforrunningoverStandardFortranisalmostasubsetofEFL.Mostof thefeaturesdescribedintheAtavismssectionarepresenttoeasetheconversionofRatforprogramstoEFL. Thereareafewincompatibilities:Thesyntaxoftheforstatementisslightlydifferentinthe twolanguages:thethreeclausesareseparatedbysemicolonsinRatfor,butbycommasinEFL. (TheinitialanditerationstatementsmaybecompoundstatementsinEFLbecauseofthis change).Theinput/outputsyntaxisquitedifferentinthetwolanguages,andthereisnoFOR-MATstatementinEFL.TherearenoASSIGNorassignedGOTOstatementsinEFL. Themajorlinguisticadditionsarecharacterdata,factoreddeclarationsyntax,blockstructure,assignmentandsequentialtestoperators,genericfunctions,anddatastructures.EFLpermitsmoregeneralformsforexpressions,andprovidesamoreuniformsyntax.(Oneneednot worryabouttheFortran/RatforrestrictionsonsubscriptorDOexpressionforms,forexample.) APPENDIXB.COMPILER B.1.CurrentVersion ThecurrentversionoftheEFLcompilerisatwo-passtranslatorwritteninportableC.It implementsallofthefeaturesofthelanguagedescribedaboveexceptforlongcomplexnumbers. VersionsofthiscompilerrunundertheandUNIX◯roperatingsystems. B.2.Diagnostics TheEFLcompilerdiagnosesallsyntaxerrors.Itgivesthelineandfilename(ifknown)on whichtheerrorwasdetected.Warningsaregivenforvariablesthatareusedbutnotexplicitly declared. B.3.QualityofFortranProduced TheFortranproducedbyEFLisquitecleanandreadable.Totheextentpossible,thevariablenamesthatappearintheEFLprogramareusedintheFortrancode.Thebodiesofloops andtestconstructsareindented.Statementnumbersareconsecutive.FewunneededGOTOand CONTINUEstatementsareused.ItisconsideredacompilerbugifincorrectFortranisproduced (exceptforescapedlines).ThefollowingistheFortranprocedureproducedbytheEFLcompiler forthematrixmultiplicationexample(Section11.2): subroutinematmul(a,b,c,m,n,p) integerm,n,p doubleprecisiona(m,n),b(n,p),c(m,p) integeri,j,k do3i=1,m do2j=1,p c(i,j)=0 do1k=1,n c(i,j)=c(i,j)+a(i,k)*b(k,j) 1continue 2continue 3continue end Thefollowingistheprocedureforthetreewalk(Section11.4):

-33-subroutinewalk(first) integerfirst common/nodes/tree integertree(4,100) realtree1(4,100) integerstaame(2,100),stapth,curode integerconst1(1) equivalence(tree(1,1),tree1(1,1)) dataconst1(1)/4h/ cprintoutanexpressiontree cindexofrootnode carrayofstructures cnextstatevalues cinitializestackwithrootnode stapth=1 staame(1,stapth)=1 staame(2,stapth)=first 1if(stapth.le.0)goto9 curode=staame(2,stapth) goto7 2if(tree(1,curode).ne.const1(1))goto3 calloutval(tree1(4,curode)) caleaf stapth=stapth-1 goto4 3calloutch(1h() cabinaryoperatornode staame(1,stapth)=2 stapth=stapth+1 staame(1,stapth)=1 staame(2,stapth)=tree(2,curode) 4goto8 5calloutch(tree(1,curode)) staame(1,stapth)=3 stapth=stapth+1 staame(1,stapth)=1 staame(2,stapth)=tree(3,curode) goto8 6calloutch(1h)) stapth=stapth-1 goto8 7if(staame(1,stapth).eq.3)goto6 if(staame(1,stapth).eq.2)goto5 if(staame(1,stapth).eq.1)goto2 8continue goto1 9continue end APPENDIXC.CONSTRAINTSONTHEDESIGNOFTHEEFLLANGUAGE AlthoughFortrancanbeusedtosimulateanyfinitecomputation,therearerealisticlimits onthegeneralityofalanguagethatcanbetranslatedintoFortran.ThedesignofEFLwasconstrainedbytheimplementationstrategy.Certainoftherestrictionsarepetty(sixcharacterexternalnames),butothersaresweeping(lackofpointervariables).Thefollowingparagraphsdescribe -34-themajorlimitationsimposedbyFortran. C.1.ExternalNames Externalnames(procedureandCOMMONblocknames)mustbenolongerthansixcharactersinFortran.Further,anexternalnameisglobaltotheentireprogram.Therefore,EFLcan supportblockstructurewithinaprocedure,butitcanhaveonlyonelevelofexternalnameifthe EFLproceduresaretobecompilableseparately,asareFortranprocedures. C.2.ProcedureInterface TheFortranstandards,ineffect,permitargumentstobepassedbetweenFortranprocedures eitherbyreferenceorbycopy-in/copy-out.Thisindeterminacyofspecificationshowsthrough intoEFL.Aprogramthatdependsonthemethodofargumenttransmissionisillegalineither language. Therearenoprocedure-valuedvariablesinFortran:aprocedurenamemayonlybepassed asanargumentorbeinvoked;itcannotbestored.Fortran(andEFL)wouldbenoticeablysimplerifaprocedurevariablemechanismwereavailable. C.3.Pointers ThemostgrievousproblemwithFortranisitslackofapointer-likedatatype.Theimple-mentationofthecompilerwouldhavebeenfareasierifcertainhardcasescouldhavebeenhan-dledbypointers.Further,thelanguagecouldhavebeensimplifiedconsiderablyifpointerswere accessibleinFortran.(Thereareseveralwaysofsimulatingpointersbyusingsubscripts,butthey founderontheproblemsofexternalvariablesandinitialization.) C.4.Recursion Fortranproceduresarenotrecursive,soitwasnotpracticaltopermitEFLprocedurestobe recursive.(Recursiveprocedureswithargumentscanbesimulatedonlywithgreatpain.) C.5.StorageAllocation ThedefinitionofFortrandoesnotspecifythelifetimeofvariables.Itwouldbepossiblebut cumbersometoimplementstackorheapstoragedisciplinesbyusingCOMMONblocks.