BC−AnArbitraryPrecisionDesk-CalculatorLanguage LorindaCherry RobertMorris ABSTRACT BCisalanguageandacompilerfordoingarbitraryprecisionarithmeticon thePDP-11undertheUNIX◯rtime-sharingsystem.Theoutputofthecompileris interpretedandexecutedbyacollectionofroutineswhichcaninput,output,and doarithmeticonindefinitelylargeintegersandonscaledfixed-pointnumbers. Theseroutinesarethemselvesbasedonadynamicstorageallocator.Overflowdoesnotoccuruntilallavailablecorestorageisexhausted. Thelanguagehasacompletecontrolstructureaswellasimmediate-mode operation.Functionscanbedefinedandsavedforlaterexecution. Twofivehundred-digitnumberscanbemultipliedtogiveathousanddigit resultinabouttenseconds. Asmallcollectionoflibraryfunctionsisalsoavailable,includingsin,cos, arctan,log,exponential,andBesselfunctionsofintegerorder. Someoftheusesofthiscompilerare −todocomputationwithlargeintegers, −todocomputationaccuratetomanydecimalplaces, −conversionofnumbersfromonebasetoanotherbase. 6April1993 BC−AnArbitraryPrecisionDesk-CalculatorLanguage LorindaCherry RobertMorris Introduction BCisalanguageandacompilerfordoingarbitraryprecisionarithmeticontheUNIXtimesharingsystem[1].Thecompilerwaswrittentomakeconvenientlyavailableacollectionofroutines(calledDC[5])whicharecapableofdoingarithmeticonintegersofarbitrarysize.Thecompilerisbynomeansintendedtoprovideacompleteprogramminglanguage.Itisaminimallanguagefacility. Thereisascalingprovisionthatpermitstheuseofdecimalpointnotation.Provisionis madeforinputandoutputinbasesotherthandecimal.Numberscanbeconvertedfromdecimal tooctalbysimplysettingtheoutputbasetoequal8. Theactuallimitonthenumberofdigitsthatcanbehandleddependsontheamountof storageavailableonthemachine.ManipulationofnumberswithmanyhundredsofdigitsispossibleevenonthesmallestversionsofUNIX. ThesyntaxofBChasbeendeliberatelyselectedtoagreesubstantiallywiththeClanguage [2].ThosewhoarefamiliarwithCwillfindfewsurprisesinthislanguage. SimpleComputationswithIntegers Thesimplestkindofstatementisanarithmeticexpressiononalinebyitself.Forinstance, ifyoutypeintheline: 142857+285714 theprogramrespondsimmediatelywiththeline 428571 Theoperators−,*,/,%,andˆ canalsobeused;theyindicatesubtraction,multiplication,division,remaindering,andexponentiation,respectively.Divisionofintegersproducesaninteger resulttruncatedtowardzero.Divisionbyzeroproducesanerrorcomment. Anyterminanexpressionmaybeprefixedbyaminussigntoindicatethatitistobe negated(the‘unary’minussign).Theexpression 7+−3 isinterpretedtomeanthat−3istobeaddedto7. Morecomplexexpressionswithseveraloperatorsandwithparenthesesareinterpretedjust asinFortran,withˆ havingthegreatestbindingpower,then*and%and/,andfinally+and−. Contentsofparenthesesareevaluatedbeforematerialoutsidetheparentheses.Exponentiations areperformedfromrighttoleftandtheotheroperatorsfromlefttoright.Thetwoexpressions aˆ bˆ candaˆ (bˆ c) areequivalent,asarethetwoexpressions a*b*cand(a*b)*c BCshareswithFortranandCtheundesirableconventionthat -2-a/b*cisequivalentto(a/b)*c Internalstorageregisterstoholdnumbershavesinglelower-caseletternames.Thevalueof anexpressioncanbeassignedtoaregisterintheusualway.Thestatement x=x+3 hastheeffectofincreasingbythreethevalueofthecontentsoftheregisternamedx.When,as inthiscase,theoutermostoperatorisan=,theassignmentisperformedbuttheresultisnot printed.Only26ofthesenamedstorageregistersareavailable. Thereisabuilt-insquarerootfunctionwhoseresultistruncatedtoaninteger(butseescal-ingbelow).Thelines x=sqrt(191) x producetheprintedresult 13 Bases Therearespecialinternalquantities,called‘ibase’and‘obase’.Thecontentsof‘ibase’,initiallysetto10,determinesthebaseusedforinterpretingnumbersreadin.Forexample,thelines ibase=8 11 willproducetheoutputline 9 andyouareallsetuptodooctaltodecimalconversions.Beware,howeveroftryingtochange theinputbasebacktodecimalbytyping ibase=10 Becausethenumber10isinterpretedasoctal,thisstatementwillhavenoeffect.Forthosewho dealinhexadecimalnotation,thecharactersA−Farepermittedinnumbers(nomatterwhatbase isineffect)andareinterpretedasdigitshavingvalues10−15respectively.Thestatement ibase=A willchangeyoubacktodecimalinputbasenomatterwhatthecurrentinputbaseis.Negative andlargepositiveinputbasesarepermittedbutuseless.Nomechanismhasbeenprovidedforthe inputofarbitrarynumbersinbaseslessthan1andgreaterthan16. Thecontentsof‘obase’,initiallysetto10,areusedasthebaseforoutputnumbers.The lines obase=16 1000 willproducetheoutputline 3E8 whichistobeinterpretedasa3-digithexadecimalnumber.Verylargeoutputbasesarepermit-ted,andtheyaresometimesuseful.Forexample,largenumberscanbeoutputingroupsoffive digitsbysetting‘obase’to100000.Strange(i.e.1,0,ornegative)outputbasesarehandled appropriately. Verylargenumbersaresplitacrosslineswith70charactersperline.Lineswhicharecontinuedendwith\.Decimaloutputconversionispracticallyinstantaneous,butoutputofverylarge numbers(i.e.,morethan100digits)withotherbasesisratherslow.Non-decimaloutput -3-conversionofaonehundreddigitnumbertakesaboutthreeseconds. Itisbesttorememberthat‘ibase’and‘obase’havenoeffectwhateveronthecourseof internalcomputationorontheevaluationofexpressions,butonlyaffectinputandoutputconversion,respectively. Scaling Athirdspecialinternalquantitycalled‘scale’isusedtodeterminethescaleofcalculated quantities.Numbersmayhaveupto99decimaldigitsafterthedecimalpoint.Thisfractional partisretainedinfurthercomputations.Werefertothenumberofdigitsafterthedecimalpoint ofanumberasitsscale. Whentwoscalednumbersarecombinedbymeansofoneofthearithmeticoperations,the resulthasascaledeterminedbythefollowingrules.Foradditionandsubtraction,thescaleofthe resultisthelargerofthescalesofthetwooperands.Inthiscase,thereisneveranytruncationof theresult.Formultiplications,thescaleoftheresultisneverlessthanthemaximumofthetwo scalesoftheoperands,nevermorethanthesumofthescalesoftheoperandsand,subjectto thosetworestrictions,thescaleoftheresultissetequaltothecontentsoftheinternalquantity ‘scale’.Thescaleofaquotientisthecontentsoftheinternalquantity‘scale’.Thescaleofa remainderisthesumofthescalesofthequotientandthedivisor.Theresultofanexponentiationisscaledasiftheimpliedmultiplicationswereperformed.Anexponentmustbeaninteger. Thescaleofasquarerootissettothemaximumofthescaleoftheargumentandthecontentsof ‘scale’. Alloftheinternaloperationsareactuallycarriedoutintermsofintegers,withdigitsbeing discardedwhennecessary.Ineverycasewheredigitsarediscarded,truncationandnotrounding isperformed. Thecontentsof‘scale’mustbenogreaterthan99andnolessthan0.Itisinitiallysetto0. Incaseyouneedmorethan99fractiondigits,youmayarrangeyourownscaling. Theinternalquantities‘scale’,‘ibase’,and‘obase’canbeusedinexpressionsjustlikeother variables.Theline scale=scale+1 increasesthevalueof‘scale’byone,andtheline scale causesthecurrentvalueof‘scale’tobeprinted. Thevalueof‘scale’retainsitsmeaningasanumberofdecimaldigitstoberetainedininternalcomputationevenwhen‘ibase’or‘obase’arenotequalto10.Theinternalcomputations (whicharestillconductedindecimal,regardlessofthebases)areperformedtothespecified numberofdecimaldigits,neverhexadecimaloroctaloranyotherkindofdigits. Functions Thenameofafunctionisasinglelower-caseletter.Functionnamesarepermittedtocollide withsimplevariablenames.Twenty-sixdifferentdefinedfunctionsarepermittedinadditionto thetwenty-sixvariablenames.Theline definea(x){ beginsthedefinitionofafunctionwithoneargument.Thislinemustbefollowedbyoneormore statements,whichmakeupthebodyofthefunction,endingwitharightbrace}.Returnofcontrolfromafunctionoccurswhenareturnstatementisexecutedorwhentheendofthefunctionis reached.Thereturnstatementcantakeeitherofthetwoforms return return(x)

-4-Inthefirstcase,thevalueofthefunctionis0,andinthesecond,thevalueoftheexpressionin parentheses. Variablesusedinthefunctioncanbedeclaredasautomaticbyastatementoftheform autox,y,z Therecanbeonlyone‘auto’statementinafunctionanditmustbethefirststatementinthedefinition.Theseautomaticvariablesareallocatedspaceandinitializedtozeroonentrytothefunctionandthrownawayonreturn.Thevaluesofanyvariableswiththesamenamesoutsidethe functionarenotdisturbed.Functionsmaybecalledrecursivelyandtheautomaticvariablesat eachlevelofcallareprotected.Theparametersnamedinafunctiondefinitionaretreatedinthe samewayastheautomaticvariablesofthatfunctionwiththesingleexceptionthattheyaregiven avalueonentrytothefunction.Anexampleofafunctiondefinitionis definea(x,y){ autoz z=x*y return(z) } Thevalueofthisfunction,whencalled,willbetheproductofitstwoarguments. Afunctioniscalledbytheappearanceofitsnamefollowedbyastringofarguments enclosedinparenthesesandseparatedbycommas.Theresultisunpredictableifthewrong numberofargumentsisused. Functionswithnoargumentsaredefinedandcalledusingparentheseswithnothingbetween them:b(). Ifthefunctionaabovehasbeendefined,thentheline a(7,3.14) wouldcausetheresult21.98tobeprintedandtheline x=a(a(3,4),5) wouldcausethevalueofxtobecome60. SubscriptedVariables Asinglelower-caselettervariablenamefollowedbyanexpressioninbracketsiscalledasub-scriptedvariable(anarrayelement).Thevariablenameiscalledthearraynameandtheexpres-sioninbracketsiscalledthesubscript.Onlyone-dimensionalarraysarepermitted.Thenamesof arraysarepermittedtocollidewiththenamesofsimplevariablesandfunctionnames.Anyfractionalpartofasubscriptisdiscardedbeforeuse.Subscriptsmustbegreaterthanorequaltozero andlessthanorequalto2047. Subscriptedvariablesmaybefreelyusedinexpressions,infunctioncalls,andinreturn statements. Anarraynamemaybeusedasanargumenttoafunction,ormaybedeclaredasautomatic inafunctiondefinitionbytheuseofemptybrackets: f(a[]) definef(a[]) autoa[] Whenanarraynameissoused,thewholecontentsofthearrayarecopiedfortheuseofthefunction,andthrownawayonexitfromthefunction.Arraynameswhichrefertowholearrayscannot beusedinanyothercontexts.

-5-ControlStatements The‘if’,the‘while’,andthe‘for’statementsmaybeusedtoaltertheflowwithinprograms ortocauseiteration.Therangeofeachofthemisastatementoracompoundstatementconsistingofacollectionofstatementsenclosedinbraces.Theyarewritteninthefollowingway if(relation)statement while(relation)statement for(expression1;relation;expression2)statement or if(relation){statements} while(relation){statements} for(expression1;relation;expression2){statements} Arelationinoneofthecontrolstatementsisanexpressionoftheform x>y wheretwoexpressionsarerelatedbyoneofthesixrelationaloperators<,>,<=,>=,==,or !=.Therelation==standsfor‘equalto’and!=standsfor‘notequalto’.Themeaningofthe remainingrelationaloperatorsisclear. BEWAREofusing=insteadof==inarelational.Unfortunately,bothofthemarelegal, soyouwillnotgetadiagnosticmessage,but=reallywillnotdoacomparison. The‘if’statementcausesexecutionofitsrangeifandonlyiftherelationistrue.Thencontrolpassestothenextstatementinsequence. The‘while’statementcausesexecutionofitsrangerepeatedlyaslongastherelationistrue. Therelationistestedbeforeeachexecutionofitsrangeandiftherelationisfalse,controlpasses tothenextstatementbeyondtherangeofthewhile. The‘for’statementbeginsbyexecuting‘expression1’.Thentherelationistestedand,if true,thestatementsintherangeofthe‘for’areexecuted.Then‘expression2’isexecuted.The relationistested,andsoon.Thetypicaluseofthe‘for’statementisforacontrollediteration,as inthestatement for(i=1;i<=10;i=i+1)i whichwillprinttheintegersfrom1to10.Herearesomeexamplesoftheuseofthecontrolstatements. definef(n){ autoi,x x=1 for(i=1;i<=n;i=i+1)x=x*i return(x) } Theline f(a) willprintafactorialifaisapositiveinteger.Hereisthedefinitionofafunctionwhichwillcomputevaluesofthebinomialcoefficient(mandnareassumedtobepositiveintegers).

-6-defineb(n,m){ autox,j x=1 for(j=1;j<=m;j=j+1)x=x*(n−j+1)/j return(x) } Thefollowingfunctioncomputesvaluesoftheexponentialfunctionbysummingtheappropriate serieswithoutregardforpossibletruncationerrors: scale=20 definee(x){ autoa,b,c,d,n a=1 b=1 c=1 d=0 n=1 while(1==1){ a=a*x b=b*n c=c+a/b n=n+1 if(c==d)return(c) d=c } } SomeDetails Therearesomelanguagefeaturesthateveryusershouldknowaboutevenifhewillnotuse them. Normallystatementsaretypedonetoaline.Itisalsopermissibletotypeseveralstatementsonalineseparatedbysemicolons. Ifanassignmentstatementisparenthesized,itthenhasavalueanditcanbeusedanywhere thatanexpressioncan.Forexample,theline (x=y+17) notonlymakestheindicatedassignment,butalsoprintstheresultingvalue. Hereisanexampleofauseofthevalueofanassignmentstatementevenwhenitisnot parenthesized. x=a[i=i+1] causesavaluetobeassignedtoxandalsoincrementsibeforeitisusedasasubscript. ThefollowingconstructsworkinBCinexactlythesamemannerastheydointheClanguage.ConsulttheappendixortheCmanuals[2]fortheirexactworkings.

-7-x=y=zisthesameasx=(y=z) x=+y x=x+y x=−y x=x−y x=*y x=x*y x=/y x=x/y x=%y x=x%y x=ˆ y x=xˆ y x++ (x=x+1)−1 x−− (x=x−1)+1 ++x x=x+1 −−x x=x−1 Evenifyoudon’tintendtousetheconstructs,ifyoutypeoneinadvertently,somethingcorrect butunexpectedmayhappen. WARNING!Insomeoftheseconstructions,spacesaresignificant.Thereisarealdifference betweenx=−yandx=−y.Thefirstreplacesxbyx−yandthesecondby−y. ThreeImportantThings 1.ToexitaBCprogram,type‘quit’. 2.ThereisacommentconventionidenticaltothatofCandofPL/I.Commentsbeginwith ‘/*’andendwith‘*/’. 3.Thereisalibraryofmathfunctionswhichmaybeobtainedbytypingatcommandlevel bc−l Thiscommandwillloadasetoflibraryfunctionswhich,atthetimeofwriting,consistsofsine (named‘s’),cosine(‘c’),arctangent(‘a’),naturallogarithm(‘l’),exponential(‘e’)andBesselfunctionsofintegerorder(‘j(n,x)’).Doubtlessmorefunctionswillbeaddedintime.Thelibrarysets thescaleto20.Youcanresetittosomethingelseifyoulike.Thedesignofthesemathematical libraryroutinesisdiscussedelsewhere[3]. Ifyoutype bcfile... BCwillreadandexecutethenamedfileorfilesbeforeacceptingcommandsfromthekeyboard. Inthisway,youmayloadyourfavoriteprogramsandfunctiondefinitions. Acknowledgement ThecompileriswritteninYACC[4];itsoriginalversionwaswrittenbyS.C.Johnson. References [1]K.ThompsonandD.M.Ritchie,UNIXProgrammer’sManual,BellLaboratories,1978. [2]B.W.KernighanandD.M.Ritchie,TheCProgrammingLanguage,Prentice-Hall,1978. [3]R.Morris,ALibraryofReferenceStandardMathematicalSubroutines,BellLaboratories internalmemorandum,1975. [4]S.C.Johnson,YACC—YetAnotherCompiler-Compiler.BellLaboratoriesComputing ScienceTechnicalReport#32,1978. [5]R.MorrisandL.L.Cherry,DC−AnInteractiveDeskCalculator.

-8-Appendix 1.Notation Inthefollowingpagessyntacticcategoriesareinitalics;literalsareinbold;materialin brackets[]isoptional. 2.Tokens Tokensconsistofkeywords,identifiers,constants,operators,andseparators.Tokenseparatorsmaybeblanks,tabsorcomments.Newlinecharactersorsemicolonsseparatestatements. 2.1.Comments Commentsareintroducedbythecharacters/*andterminatedby*/. 2.2.Identifiers Therearethreekindsofidentifiers−ordinaryidentifiers,arrayidentifiersandfunctionidentifiers.Allthreetypesconsistofsinglelower-caseletters.Arrayidentifiersarefollowedbysquare brackets,possiblyenclosinganexpressiondescribingasubscript.Arraysaresinglydimensioned andmaycontainupto2048elements.Indexingbeginsatzerosoanarraymaybeindexedfrom0 to2047.Subscriptsaretruncatedtointegers.Functionidentifiersarefollowedbyparentheses, possiblyenclosingarguments.Thethreetypesofidentifiersdonotconflict;aprogramcanhavea variablenamedx,anarraynamedxandafunctionnamedx,allofwhichareseparateanddistinct. 2.3.Keywords Thefollowingarereservedkeywords: ibaseif obasebreak scaledefine sqrtauto lengthreturn whilequit for 2.4.Constants Constantsconsistofarbitrarilylongnumberswithanoptionaldecimalpoint.ThehexadecimaldigitsA−Farealsorecognizedasdigitswithvalues10−15,respectively. 3.Expressions Thevalueofanexpressionisprintedunlessthemainoperatorisanassignment.Precedence isthesameastheorderofpresentationhere,withhighestappearingfirst.Leftorrightassociativity,whereapplicable,isdiscussedwitheachoperator.

-9-3.1.Primitiveexpressions 3.1.1.Namedexpressions Namedexpressionsareplaceswherevaluesarestored.Simplystated,namedexpressions arelegalontheleftsideofanassignment.Thevalueofanamedexpressionisthevaluestoredin theplacenamed. 3.1.1.1.identifiers Simpleidentifiersarenamedexpressions.Theyhaveaninitialvalueofzero. 3.1.1.2.array-name[expression] Arrayelementsarenamedexpressions.Theyhaveaninitialvalueofzero. 3.1.1.3.scale,ibaseandobase Theinternalregistersscale,ibaseandobaseareallnamedexpressions.scaleisthe numberofdigitsafterthedecimalpointtoberetainedinarithmeticoperations.scalehasaninitialvalueofzero.ibaseandobasearetheinputandoutputnumberradixrespectively.Both ibaseandobasehaveinitialvaluesof10. 3.1.2.Functioncalls 3.1.2.1.function-name([expression[,expression...]]) Afunctioncallconsistsofafunctionnamefollowedbyparenthesescontainingacommaseparatedlistofexpressions,whicharethefunctionarguments.Awholearraypassedasanargumentisspecifiedbythearraynamefollowedbyemptysquarebrackets.Allfunctionarguments arepassedbyvalue.Asaresult,changesmadetotheformalparametershavenoeffectonthe actualarguments.Ifthefunctionterminatesbyexecutingareturnstatement,thevalueofthe functionisthevalueoftheexpressionintheparenthesesofthereturnstatementoriszeroifno expressionisprovidedorifthereisnoreturnstatement. 3.1.2.2.sqrt(expression) Theresultisthesquarerootoftheexpression.Theresultistruncatedintheleastsignificantdecimalplace.Thescaleoftheresultisthescaleoftheexpressionorthevalueofscale, whicheverislarger. 3.1.2.3.length(expression) Theresultisthetotalnumberofsignificantdecimaldigitsintheexpression.Thescaleof theresultiszero. 3.1.2.4.scale(expression) Theresultisthescaleoftheexpression.Thescaleoftheresultiszero. 3.1.3.Constants Constantsareprimitiveexpressions. 3.1.4.Parentheses Anexpressionsurroundedbyparenthesesisaprimitiveexpression.Theparenthesesare usedtoalterthenormalprecedence.

-10-3.2.Unaryoperators Theunaryoperatorsbindrighttoleft. 3.2.1.−expression Theresultisthenegativeoftheexpression. 3.2.2.++named-expression Thenamedexpressionisincrementedbyone.Theresultisthevalueofthenamedexpressionafterincrementing. 3.2.3.−−named-expression Thenamedexpressionisdecrementedbyone.Theresultisthevalueofthenamedexpressionafterdecrementing. 3.2.4.named-expression++ Thenamedexpressionisincrementedbyone.Theresultisthevalueofthenamedexpressionbeforeincrementing. 3.2.5.named-expression−− Thenamedexpressionisdecrementedbyone.Theresultisthevalueofthenamedexpressionbeforedecrementing. 3.3.Exponentiationoperator Theexponentiationoperatorbindsrighttoleft. 3.3.1.expressionˆ expression Theresultisthefirstexpressionraisedtothepowerofthesecondexpression.Thesecond expressionmustbeaninteger.Ifaisthescaleoftheleftexpressionandbistheabsolutevalueof therightexpression,thenthescaleoftheresultis: min(a×b,max(scale,a)) 3.4.Multiplicativeoperators Theoperators*,/,%bindlefttoright. 3.4.1.expression*expression Theresultistheproductofthetwoexpressions.Ifaandbarethescalesofthetwoexpressions,thenthescaleoftheresultis: min(a+b,max(scale,a,b)) 3.4.2.expression/expression Theresultisthequotientofthetwoexpressions.Thescaleoftheresultisthevalueof scale. 3.4.3.expression%expression The%operatorproducestheremainderofthedivisionofthetwoexpressions.Moreprecisely,a%bisa−a/b*b. Thescaleoftheresultisthesumofthescaleofthedivisorandthevalueofscale -11-3.5.Additiveoperators Theadditiveoperatorsbindlefttoright. 3.5.1.expression+expression Theresultisthesumofthetwoexpressions.Thescaleoftheresultisthemaximunofthe scalesoftheexpressions. 3.5.2.expression−expression Theresultisthedifferenceofthetwoexpressions.Thescaleoftheresultisthemaximum ofthescalesoftheexpressions. 3.6.assignmentoperators Theassignmentoperatorsbindrighttoleft. 3.6.1.named-expression=expression Thisexpressionresultsinassigningthevalueoftheexpressionontherighttothenamed expressionontheleft. 3.6.2.named-expression=+expression 3.6.3.named-expression=−expression 3.6.4.named-expression=*expression 3.6.5.named-expression=/expression 3.6.6.named-expression=%expression 3.6.7.named-expression=ˆ expression Theresultoftheaboveexpressionsisequivalentto‘‘namedexpression=namedexpression OPexpression’’,whereOPistheoperatorafterthe=sign. 4.Relations Unlikeallotheroperators,therelationaloperatorsareonlyvalidastheobjectofanif, while,orinsideaforstatement. 4.1.expression<expression 4.2.expression>expression 4.3.expression<=expression 4.4.expression>=expression 4.5.expression==expression 4.6.expression!=expression 5.Storageclasses ThereareonlytwostorageclassesinBC,globalandautomatic(local).Onlyidentifiersthat aretobelocaltoafunctionneedbedeclaredwiththeautocommand.Theargumentstoafunctionarelocaltothefunction.Allotheridentifiersareassumedtobeglobalandavailabletoall -12-functions.Allidentifiers,globalandlocal,haveinitialvaluesofzero.Identifiersdeclaredasauto areallocatedonentrytothefunctionandreleasedonreturningfromthefunction.Theytherefore donotretainvaluesbetweenfunctioncalls.autoarraysarespecifiedbythearraynamefollowed byemptysquarebrackets. AutomaticvariablesinBCdonotworkinexactlythesamewayasineitherCorPL/I.On entrytoafunction,theoldvaluesofthenamesthatappearasparametersandasautomaticvariablesarepushedontoastack.Untilreturnismadefromthefunction,referencetothesenames refersonlytothenewvalues. 6.Statements Statementsmustbeseparatedbysemicolonornewline.Exceptwherealteredbycontrol statements,executionissequential. 6.1.Expressionstatements Whenastatementisanexpression,unlessthemainoperatorisanassignment,thevalueof theexpressionisprinted,followedbyanewlinecharacter. 6.2.Compoundstatements Statementsmaybegroupedtogetherandusedwhenonestatementisexpectedbysurroundingthemwith{}. 6.3.Quotedstringstatements "anystring" Thisstatementprintsthestringinsidethequotes. 6.4.Ifstatements if(relation)statement Thesubstatementisexecutediftherelationistrue. 6.5.Whilestatements while(relation)statement Thestatementisexecutedwhiletherelationistrue.Thetestoccursbeforeeachexecution ofthestatement. 6.6.Forstatements for(expression;relation;expression)statement Theforstatementisthesameas first-expression while(relation){ statement last-expression } Allthreeexpressionsmustbepresent. 6.7.Breakstatements break breakcausesterminationofafororwhilestatement.

-13-6.8.Autostatements autoidentifier[,identifier] Theautostatementcausesthevaluesoftheidentifierstobepusheddown.Theidentifiers canbeordinaryidentifiersorarrayidentifiers.Arrayidentifiersarespecifiedbyfollowingthe arraynamebyemptysquarebrackets.Theautostatementmustbethefirststatementinafunctiondefinition. 6.9.Definestatements define([parameter[,parameter...]]){ statements} Thedefinestatementdefinesafunction.Theparametersmaybeordinaryidentifiersor arraynames.Arraynamesmustbefollowedbyemptysquarebrackets. 6.10.Returnstatements return return(expression) Thereturnstatementcausesterminationofafunction,poppingofitsautovariables,and specifiestheresultofthefunction.Thefirstformisequivalenttoreturn(0).Theresultofthe functionistheresultoftheexpressioninparentheses. 6.11.Quit ThequitstatementstopsexecutionofaBCprogramandreturnscontroltoUNIXwhenitis firstencountered.Becauseitisnottreatedasanexecutablestatement,itcannotbeusedina functiondefinitionorinanif,for,orwhilestatement.