ECMA-116

Embed Size (px)

Citation preview

  • 8/2/2019 ECMA-116

    1/203

    EUROPE CO P ER ANU CTU ERS ASSOCI O

    l

    June 986

  • 8/2/2019 ECMA-116

    2/203

    Free copies of thi document are available fro ECA,

    European Coputer :\Iannfanrers ociation

    Rue dn Hh'e 0 Geneva (Switzrand)

  • 8/2/2019 ECMA-116

    3/203

    BRI HISTORY

    first rsion of t lana BASIC, acronm for Binnr s Allprpos SbolicInstrction Cod, was prodcd in Jn 196 at t Darot Coll in t USA.

    In Janar 1978, ECMA pblisd a Standard for Minial BASIC, ECMA, prpard in coopration wit SI XJ and fll copatibl wit t corrspondin ASI standard . is Standard ECMA srd as a basis for t ISO Standard on Minal BASIC.

    Wit t cont ination o f t work, a draft Standard for fl l BASIC was ard b ASI J,

    EWICS TC and ECMA/TC 1 in Janar 198 . Tis draft is coposd of a dator Cor odland f i optional odls .

    Startin fro tis draft, ECMA /TC1 prpard a Standard for fll dfind sbsts of tlana . s sbsts , ca l ld ECMA BASIC and ECMA BASIC , ar dsind for bsinssappl ications rqir in xtndd fil faci l itis . ECMA BASIC 1 as no xcption andl in

    faci litis and a rdcd st of f il oprations . In addit ion , al l t kords inECMA BASIC1 ar rsrd words, rdcin t coplxit of t intrprtr or copilrndd . ECMA BASIC proids fll xcption andlin capabi litis , fll fi l oprations

    and fixd dcial capabil iti s . T st of rsrd words is inial . Bot sbsts proid

    t fl l f low contr ol capabilitis proidd in t ASI standard . additional odl

    ECMA RAPHICS proids a inim of rapic capabilitis and can b sd wit itrsbst.

    Copatibi lit wit t ASI standard as bn a priar dsin objcti, and t ECMAStandard is fll pward copatibl wit corrspondin iplntations of t ASIStandard .

    Approd as an ECMA Standard b t nral Assbl of Jn 6 , 1986 .

  • 8/2/2019 ECMA-116

    4/203

    - i -

    TABE O COTTS

    1 . ITRODUCTIO

    1.1 Scop1 . 2 Rlatd Standards

    2 . COORMACE

    2 . 1 Prorm Conformanc2 . 2 Implmntation Conformanc2.3 Errors

    2.4 Excptions2 . Rlationsip to t ASI Standard

    3 . SYTAX SPECIICATIO AD DEIITIOS

    3 . 1 Mtod of Sntax Spcification

    3 . 2 Dfinitions of Trms

    3 . 2 . 13 . 2 . 23 . 2 . 3

    3 . 2 . 43 . 2 3 . 2 . 6

    3 . 2 . 7

    BASICBatc-mod

    CanEnd-of-lin

    ErrorExcptionExtrnal

    3.2 .8 Idntifir3 . 2 . 9 Intracti mod

    3.210 Intrnal3.2.11 Kword

    3.2 .12 in3 . 2 . 13 Macin Infinitsimal

    3.2 .14 Ma3.2.1 ati

    3.2.16 Orflow

    3.2.17 Print Zon3 . 2 . 18 Prorm Unit

    3 . 2 . 19 Rsrd Word3.2.20 Rondin

    3.2 .21 Sall3.2.22 Sinificant Diits3 . 2 . 23 Trncation

    3.2.24 Undrflow

    4 . PRORAM ES

    4 . 1 Caractrs

    4 . 2 Prorams ins and Blocks4 . 3 Prorm Annotation4.4 Idntifirs

    . UERS

    . 1 mric Constants . 2 mric Variabls

    . 3 mric Exprssions . 4 Imp lmntation-Spplid mric nctions

    . mric Assi nmnt Statmnt

    2

    22

    4

    4

    4

    8

    9

    99

    101010

    1010

    1010

    1111

    1111

    1111

    111212

    1212

    131313

    13

    1

    1

    161919

    23

    2324226

    31

    8

  • 8/2/2019 ECMA-116

    5/203

    5 . 6 Nric Arittic and Anl

    6. STRINS

    6 . 1 Strin Constants

    6 . Strin Variabls6 . 3 Strin Exprssion

    ii

    6 . 4 IplntationSppl id Strin nctions

    6 . 5 Strin Ass int Statnts6 . 6 Strin Dclarations

    7 ARAYS

    7 . 1 Arra Dclarations

    7 . Nric Arras7 . 3 Strin Arras

    8 . CONTRO STRUCTUES

    8 . 1 Rlation Exprssion

    8 . Control Statnts8 . 3 oop Strctrs8 . 4 Dcis ion Strctrs

    9 . PRORAM SENTATION

    9 . 1 UsrDfind nctions

    9 . Sbproras

    9 . 3 Cainin

    10 . INPUT AN OUTPUT

    10 . 1 Intrnal Data

    10. Inpt

    10. 3 Otpt10 . 4 orattd Otpt10 . 5 Arra I npt and Otpt

    11. IES

    11 . 1 il Oprations11 . i l Pointr Maniplation11 . 3 il Data Cration11.4 il Data Rtrial

    11 . 5 il Data Modification (BASIC onl)

    1. CEPTION HAIN AND DEBUIN

    1 . 1 Excption Handlin ( BASIC onl)1 . Dbin (BASIC1 and BASIC )

    13 . RAPHICS

    13 . 1 Coordinat Ssts13 . Attribts and Scrn Control13 . 3 rapic Otpt

    14 . REA TI ( not in ECMA BASIC )

    15 . I DECIMA S (BASIC onl)

    15 . 1 ixd Dcial Prcision15 . ixd Dcial Prora Sntation

    TABE 1 Standard BASIC Caractr St

    31

    3 5

    3535

    37

    38

    41

    4

    45

    45

    4750

    53

    53

    54

    56

    58

    63

    63

    687 3

    76

    76

    7 7

    8084

    88

    93

    98108

    111118

    15

    130

    130135

    138

    138141

    14 3

    14 6

    147

    149

    15

  • 8/2/2019 ECMA-116

    6/203

  • 8/2/2019 ECMA-116

    7/203

    - 1 -

    1 . I N T RO D UT I O N

  • 8/2/2019 ECMA-116

    8/203

    2

    1. INTRODUCTION

    This Stndard is designed to promote the intercgeaiity of BASIC programs among a vari

    ety of autotic data proces sing systems . Programs conforming to this Standard wi e saidto e written in E BASIC.

    Two eves of the angge are specified in this Standard ECMA BASIC 1 and ECMA BASIC 2

    In addition this Stdard defines an optiona Graphic s modue .

    1 . 1

    This Standard estaishes

    The syntax of progrms written in ECMA BASIC

    Te f ots of data and the min precision and range of numeric representations

    and the mini ength and set of characters in strings which are acceptae as input

    to an automatic data processing system eing contro ed y a program written in

    ECMA BASIC.

    The f ots of data and the min precson and range of numeric representations

    and the min ength and set of characters in strings which cn e generated as

    output y an automatic data processing system eing controed y a program written

    in E BASIC.

    The stic rues for interpreting the ming of a program written in EA BASIC .

    The errors and exceptiona circumsces which sha e detected .

    Athough the BASIC angge was originay designed prriy for interactive use this

    Standard descries a angge t is not so restricted. This Standard is not meant to

    precude the use of any particuar impementation technique, for exe interpreters ,

    incrementa or onepass coi er s .1 . 2 Reated Sdards

    ECMA6

    ECMA5

    E5

    E55

    ISO 21

    ISO 2711

    ISO 7

    ISO 792

    7Bit Coded Character Set

    Code Extension Techniques

    Representation of Source Program for Program Intercge AP

    COBO FOR Minima BASIC and P/ 1

    Mini BASIC

    Writing of Caendar Dates in anumeric form

    Representation of Ordina Dates

    Representation of Time of the Day

    GICA K System GKS IEC 559 Binary Foating Poi nt Arietic f or Microprocessor Systems .

    ANSI X . 11 198X American Nationa Standard for BASIC

  • 8/2/2019 ECMA-116

    9/203

    - 3 -

    2. ONFORNE

  • 8/2/2019 ECMA-116

    10/203

    -

    2 . COOCE

    This Standard speci fie s two eve s of the anguage EA BASIC- nd EA BASIC-2 . In addi

    tion this Standard defines a Graphics modue.

    EA BASIC - incudes a the parts defined in Section to 2 with the exception of thoseportions of Section that descr ies enhanced fi e s and Section 2 . Exception anding .

    A the keywords isted i n 2 . 9 under the heading BASIC- are reserved words .

    ECMA BASIC- 2 in cudes a the parts defined in Section to 2 and in Section 5 . The key

    words i sted in . 2 . 9 under the heading BASI-2 are resered words .

    The graphics mod ue is s pecifi ed in section It is optiona and it can e used together

    either with ECMA BASIC - or EA BASIC-2 .

    There are two aspects of the conforce to the anguage defined in this Standard confo rmance y a program ritten in the ECMA BASIC anguage and confornce y an impementation

    which processes such progrs .

    Broady speaking the conforce requirements are structured so that any program conforming to this standard wi produce the same resuts when executed y any impementation con

    forming to the standard though some iementation-defined features are noted in Appendix

    ) .

    2 . Conforc e

    A program confos to this Standard ony when

    - the program and each statement or other syntactic e ement contained therein is syntac

    ticay vaid according to the syntactic rues specified y this Standard as eonging

    to that eve d

    - the program as a who e vio ates none of the g oa constraints imposed y this eve

    of the Standard on the app ication of the syntactic r ues .

    2 . 2 Conforce

    impementation conforms to a eve of this Standard ony when

    - it accepts and processes a programs conforming to that eve of this Standard

    - it reports reasons for reject ing any program which does not conform to this Standd

    it interprets errors and exceptiona circumstances according to the speci fications of

    this Standard

    - it interprets the sentics of each statement of a confoing program according to the

    specif ications in this Standard

    - it interprets the semantics of a conforming progr as a whoe according to the speci

    fications in this Standard

    - it accepts as input manipuates and can generate as output numers of at east the

    precision and range specified in this Standard

    - it accepts as input manipuates and can generate as output strings of at east the

    ength and composed of at east those characters specified in this Standard

    - it i s accompanied y docuentation avaia e t o the user that descries the actions

    taken in regard to features referred to as "undefined" or "ipementation-defined" in

    this Standard and

    - it i s accompanied y docuentation avaiae to the user that descries and identifies

    a enhancements to the anguage defined in this Standard.

    This Standard makes no requirement conceing the interpretation of the stics of anystatement or progra as a whoe that does not conform to this Standard .

  • 8/2/2019 ECMA-116

    11/203

    - 5 -

    2 Errors

    This Standard does not incude specif ic requirements for reporting syntactic errors in

    the text of a program.

    Impeentations conforming to this Standard ay accept programs written in an enhancedanguage wi thout haing to report a cons tructs not conforming to this S tandard .

    Wheneer a statement or other program eement does not conform to the syntactic rues

    gien herein, and that statement or other program eement, does not hae a cear, we

    documented impementationdefined meaning, an error sha e reported . Errors sha e

    reported in a cear and we documented way and wheneer feasie the ipementation

    shoud indicate the erroneous statement and the position of the error within the

    statement .

    2 .

    exception is a circumstance arsng in the course of execution of a program when an

    impementation recognizes that the semantic rues of this Standard cannot e foowed or

    that some resource constraint is aout to e exceeded . A exceptions descr ied in thisStandard sha e detected, reported and processed when they occur, uness some mecha

    nism proided in 2 . BASIC 2 ony) or an enhancement to this Stndard s een inoked

    y the user to hande exceptions .

    In the asence of progrer spec if ied recoery procedures , excepti ons sha e handed

    y the recoery procedures sp ecified in this Standard . If no recoery procedure is spec

    ified in this Standard, or if restrictions imposed y the hardware or the operating en

    ironment ake it imposs ie to foow the procedure spe cifie d in this Standard, then

    the way in which the exception is handed depends on the context . If the excepti on oc

    curred in the inocation of a function or suprogram, then the exception is "propagated

    ack" to he inoking statement in the inoking progra unit see 2 . ) . If this propa

    gation procedure reaches the mainprogram, or if the exception occurred in the main

    program, then the exception sha e handed y terminating the program.

    The way in which

    impementationdefined,

    the exception code and

    curred.

    the exception handing mechanism reports an exception is

    except that the contents of the report sha identify at east

    the ine ner of the ine in which the origina exception oc

    Except in the cas e of f ies , when seera exception are caused y the execution of a

    singe statement of a progr, his Standard does not specify an order in which these

    exceptions sha e detected or reported . If an impementation determines that a partic

    uar statement in a conforming program wi aways cause an exception when executed , the

    impementation may issue a warning to he user . Nonetheess , the impementation must ac

    cept and execute the program, according to the norma semantic rues specified herein.

    2 . 5 to he ANSI Standard

    This Standard ECMA BASIC defines a suset of the ANSI BASIC Standard , ANSI X . 98 X.

    The ANSI standard defines a set of modues , ony one of which the Cor e modue) is

    andatory . On the other hand , ony the graphics modue is optiona in the ECMA standard .

    Progras written in ECMA BASIC wi on impementations conforming to the ANSIstandard if the impementation impements at east the Core modue. Proi ded that the

    impementationdefined eements are defined in a compatie way in the two impementa

    tions , the programs wi act in the same way and gie the same resuts .

    Programs written in BASIC2 wi on impementations conforming to he ANSI Standardif the impementation impeents at east the Core modue and the Enhanced Fies modue.

    Proided hat he ipementationdefined eements are defined in a compatie way in thetwo impementations , the program wi act in the same way and gie the same resuts .

  • 8/2/2019 ECMA-116

    12/203

  • 8/2/2019 ECMA-116

    13/203

    3 S YN TAX S P E C I F I CAT I O N AN D D E F I N I T I O N S

  • 8/2/2019 ECMA-116

    14/203

    3. SYNTAX SPECIFICATION DEFINITIONS

    3.1 Method of

    8

    The sntax , through a serie s of rewrit ing ues known as "productions " , de fines sntac

    tic ojects of arious tpes, such as a program or expression, and descries which

    str ings of smos are ojects of these tpes

    In the snta, upper-case-etters , digits , and pos si hphenated ) ower-case words

    are used as "metanames" , i e as names of sntactic ojects Most of these metes aredef ined productions in terms of other metanames In order that this proces s termi

    nates , certain metnames are designated as " termina" metanames , and productions for

    em are not incuded in the snta With the exception of the const ruct[impementation-def ined]" , a termina metes occur for the first time and are defined in 4.1. It shoud e noted in particuar that a upper-case-etters are termina

    metanes which denote oth themsees and their ower-case equiaents except in the

    productions defi ning upper-c ase-etters and ower-case etters , in which the etters d e

    note on themsees ) The d igits are termina metanmes which denote themsees In ad

    di tion , the cons truct "[ impementation-d efined]" is not a unique sntactic oject , uteach occurrence of it is defined each impementation in an appropriate fashion for

    the oject in question In some cases a recoendation as t o the representation of the

    oject is gien in the corresponding rearks section

    \e iustrate further detais of the sntax considering some exampes from 5 .1 . The

    production

    fraction period integer

    indicates that a fraction is a period foowed an integer Since "per iod" is a termi

    na mete i e , it does not occur on the eft-hand side of n production) , the semantics in 4.1 identif the particuar character denoted a period

    What is integer The production

    integer = digit digit

    indicates that an integer i s a di git foowed an aritrar numer of other d igits

    asterisk is a sntactic operator indicating hat the oject it foows ma e repeated

    an numer of time, incuding zero times

    \at is a digit In 4.1 the production

    digit = o I 1 I I 3 I 4 I 5 I 6 I 7 I 8 I 9

    indicates at a digit is either a o a 1, , or a 9 The sant is a sntactic operator meaning "or" and is used to indicate that a metane can e rewritten in one of se

    era was

    Since the digits are teina metanames , our dec ipherment of the sntax for a fractioncomes to an end The seantics in 4.1 identif the dig its in terms of the characters

    the represent

    A question-mark is a sntactic operator ike the asterisk, indicating that the oject it

    foows ma e omitte d For exampe , the production

    exrad E sign integer

    indicates tat an exrad consists of the etter E or e foowed an optiona sign fo

    owed an integer

    arentheses e used to group sequences of metes together For expe,

    ariae-ist = ariae coa ariae)

  • 8/2/2019 ECMA-116

    15/203

    9

    defines a variaeist to consist of a variae foowed y an aritrary numer of

    other variaes separated y coas . If we wish parenthese s actuay to appear in syn

    tactic ojects rather than just wish to use them to descrie syntactic ojects then we

    indicate their prese nce y the metanmes eftparenthes is and "rightparenthesi s" .

    When severa syntactic operators occur in the same production the foowing order ofprecedence is empoyed . The operators ? and '

  • 8/2/2019 ECMA-116

    16/203

    - 10 -

    3. 2. 1 BASIC

    A te applied as a name to members of a special class of languages which possess

    similar syntaxes and stic meanings, acrony for Beginner's All-purpose SybolicInstruction Code.

    3. 2. 2 Batch-mode

    The processing of programs in an environment where no provision is ade for user in

    teraction.

    3.2.3

    The word "can" is used in a descriptive sense to indicate that standard-conforming

    programs are allO\ed to contain certain constuctions and that standard-conforming

    implementations are required to process such programs correctly.

    3. 2. 4 Endof-line

    The character(s) or indicator which identifies the termination of a line. Lines of

    three kinds may be identified in BASIC program lines, print lines, and input-replylines. End-of-lines may vary between the hree cases d may also vary depending upon

    context. Thus, for exple, the end-of-line in an input-reply may vary on a given

    system depending on te source for input being used in interactive or batch mode.

    Typical examples of end-of-line are carriage-retu, carriage-retu line-feed, and

    end of record (such as end of card).

    3. 2. 5 Error

    A flaw in the syntax of a progra which causes the progra to be incorrect.

    3.2.6

    A circumstance arising in the course of executing a program when an implementation

    recognizes that the semantic rules of this Standard cnnot be followed or that some

    resource constraint is about to be exceeded. Certain exceptions (nonfatal exceptions)

    may be handled by autoatic recovery procedures specified in his Sandard. These and

    other exceptions may also be handled by recovery procedures specified in the program

    (see 12. 1, BASIC2 only). If no recovery procedure is given in this Standard (fatal

    eceptions) or if restrictions iposed by the hardware or operating environment make

    it impossible to follow the given procedure, and if no recovery procedure is speci

    fied in the progrm, hen te way in which the exception is handled depends on the

    context. If the eception occurred in an invocation of a function, picture, or sub

    progra, then te exception is 'propagated back to the invoking statement of the in

    voking program unit (see 12. 1, BASIC-2 only). If this propagation procedure reaches

    te main progra, or if he exception occurred in the main progrm, then the ecep

    tion shall be handled by terminating the progrm.

    3. 2.7 Extel

    With respect to procedures, refers to a procedure lexically not contained within a

    larger programunit

    3. 2. 8 Identifier

    A character string used to name a variable, an array, an array-value, an exception

    handler, a function, subprogram, or a program.

    3. 2. 9 Interactive mode

    The processing of programs in an environent which permits the user to respond di

    rectly to the actions of individual progrs and to control he initiation and termi

    nation of tese programs.

  • 8/2/2019 ECMA-116

    17/203

    -

    2 Itl

    Wth rspct to rcord-typ rfrs to data rprstatos such that both th typ

    d xact valu of th wrtt data ar prsrvd ad rtrvabl by subsqut read

    opratos

    Wth rspct to procdurs rfrs to a procdur lxally

    largr progra ut ad sharg data wth that ut

    2 ll

    cotad wth a

    A charactr strg usually wth th spllg of a cooly usd or oc ord

    whch provds a dstctv dtfcato of a statt or a copot of a

    statt of a prograg laguag

    Th kywords ECMA BAIC ar

    ACCE AND ANGLE ARITIC ARRAY AK A BAE BEGIN BREAK CALL CAE

    CAUE CHAIN CLAR CLIP CLE CLE CLR DAA DAUM DEBUG DECIL

    DECLE DEF DEGREE DELEE DEVICE DIM DIPLAY ELP ELE ELEIF END

    ERAE ERAABLE I INE NAL YPE FILEYPE FIX FR FUCIN G

    G UB G HANDLER IF IMAGE IN INPU INERNAL I EY KEYED LENGTH LE

    LINE LINE LP MRGIN M MIING NA NAIV N NURIC F FF

    N PEN PIN R RGANIZAIN UIN UPUT PI PINER PIN PRIN

    PRGRAM PRMP RADIAN RNMIZE R RCRD RECIZE RECYPE RELAIVE

    RE RRE RERY REUN RWRITE ELEC EQUNIAL E ER IZE

    KIP ANDARD ATU EP P RING YLE UB AB PLAE N

    I IUT ACE UTIL UE UING VARIABLE VIEWPR WN WHILE

    WINDW WIH WRIE ZNWIDH

    Kywords ay also b splld usg lowr-cas lttrs or xd upprcas ad lowr

    cas lttrs

    22 L

    Two tps of ls ar dscrbd th tadard a physcal l ad a logcal l

    A physcal l s a ordrd squc of charactrs whch trats wth a d-of

    l A physcal l starts wth a lubr or wth a aprsad A logcal l

    cossts of a lubr followd by a ordrd squc of txt whr ach l

    cotuato has logcally b rplacd by a spac

    2 Mach Iftsl

    Th sallst postv valu (othr tha ro) whch ca b rprstd ad apu

    latd by a BAIC pltato

    24 !:

    Th word ay s usd a prssv ss to dcat that a stadardcoforg

    pltato ay or ay ot provd a partcular fatur

    25 Natv

    W rspct to rcordtyp rfrs to a rcord wth a spcfd stctur for th

    flds wth th rcord so as to b copatbl wth rcords gratd by othr la

    guags o th sa syst Wth rspct to urc or strg data rfrs to data for

    whch crta satc ruls ar lft pltatodfd (g collatg s

    quc prcso) so as to b drctly pltabl o th host hardwa

    26 rflow

    Wth rspct to urc opratos th tr appld to th codto whch xsts

    wh a pror oprato has attptd to grat a rsult whch xcds (s544) or whch xcds th axu valu that ca b rprstd by th dclard

  • 8/2/2019 ECMA-116

    18/203

    1 2

    for of a fixed poin variabe or array. Wi respec o sring operaions, e

    erm appied o he condiion which exiss when a prior operaion as aemped o

    generae a resu which as more caracers an can be conained in a sring of max

    ima engh, as deermined by e anguage processor Wih respec o sring assign

    men, he erm appied o he condiion wic exiss when a prior operaion as a

    emped o assign a vaue a is onger han he decared or defau maximum of a

    sringvariabe or sringdefinedfucion.

    32.17 Prin one

    A coniguous se of characer posiions in a prined oupu ine which may conain

    evauaed prinsaemen eemen.

    3.2.18 Uni

    A sefconained par of a BASC progrm consising eier of e mainprogram, whic

    is he sequence of ines up o and incuding e ine conaining a saemen, or

    of an exernasubde or exernafuncionde.

    32.19 Reserved ordBASC1

    A characer sring whose usage as a rouineidenifier, sringidenifier or

    numericidenifier is forbidden in an EQA BASC1 program.ese words are:

    he noargumen suppied funcion nes: DATE NE TYPE P

    T TRANSFORM DATE$ and TME$

    he idenifier used in arrayvaues: CON N ZER and $,

    he foowing keywords: ACCESS AND ANGLE REA ARC ASK AT BASE

    BEGN BRAK CALL CASE CHAN CLEAR CLP CLOSE COLLTE COLOR DATA

    DATM DEBUG DECMAL DECLARE DEF DEGREES DEVCE DEVCE DM DSPLAY

    DO ELAPSED ELSE ESEF EN ERSE ASBLE T AL FLETYPEFOR FUNCTON GO GOSB TO GRAPH F MAGE NPUT N S

    LENGTH LET LNE LES LOOP ARGN MT MSSNG N NATVE

    NOT NlERC OFF ON OPEN OPTON OR ORGANZATON OTN OUTPUT PONT

    POTER PONTS PRNT PROGRAM PROMPT RDNS RDOMZE R, RECSZE

    RECTYPE ST RESTOR RTRN SAt SELECT SEUTAL SET SE

    SZE SKP STARD STATUS STEP STOP SREM STRNG STYLE SB TAB

    TT TR TOUT TO TRACE NTL USNG VARABE VEWPORT

    WHLE NDO WTH WRTE ZONEWDTH.

    The fucion names N and TYPE are no used in ECM BASC1 bu are

    reserved for compaibiiy \i EC BASC2.

    BASC2

    A caracer sring hose usage as a rouineidenifier, sringidenifier or

    numericidenifier is forbidden in an ECA BASC2 progrm.These words are:

    e noargumen suppied fncion nmes: DATE N TYPE P

    T TRNSFORM DATE$ and TMES$

    he idenifiers used in arrayvaues: CON DN Z d $

    he keywords NOT SE PRT and

    3.2.20

    Te process by which a represenaion of a vaue wih ower precision is generaed

    from a represenaion of iher precision aking ino accou e vaue of a por

    ion of he origina nmber whic is o be omied. For exmpe, ronding X o heneares ineger may be accompished by NT(X+O.) (see 54)

  • 8/2/2019 ECMA-116

    19/203

  • 8/2/2019 ECMA-116

    20/203

    4

    4 PRG ELEMENTS

  • 8/2/2019 ECMA-116

    21/203

    1

    4 PRRAM S

    A BASI prorm s a seqence of l nes contann statements Eac lne s t sel f a se

    qence of caracters

    4 1 aracters

    4 . General

    Te caracter set f or EMA BASI s contaned n te Standard EA6

    4 2

    caracter2 qotedstrncaracter3 nonqotecaracter

    4 dobleqote

    5 nqotedstrncaracter

    planstrncaracter

    7 . dt

    8 letter ppercaseletter

    0 . lowercase l etter oter caracter

    qotatonmark nonqotecaracter

    dobleqote nonqotecaractermpersand apostrope astersk crcflexaccent

    colon coa dollarsn eqlssn exclmatonmark reatertnsn leftparentess lesstansn nmbersn percentsn qestonmark

    rtparentess semcolon slnt nderlne nqotedstrncaracterqotatonmark qotatonmark

    space planstrncaracter

    dt letter perod plssn mnssn

    01234678

    ppercaseletter lowercaseletter

    ABEGHIKMNOPQRSTVWXYZabcdefjklmnopqrstwxyz[mplementatondefned]

    Te syntx as descrbed enerates prorams wc contan no spaces oter tan toseoccrrn n remarkst rns , n certan qotedstrns , nqotedst rns , and

    lteral s trns , or were te presence of a space s exp l ct ly ndcated by temetanme space

    Speca l conentons sall be obseed reardn spaces . W t te fo ll own exceptons, spaces my occr anyere n a BASI proram wtot affectn te exectonof tat prorm and may be sed to mproe te appearance and readablty of te proram. Spaces sall not appear

    edately precedn te lnenmber of a l ne wtn lnenmbers

    wtn keywords

    wn dentfers wtn nmercconstants

    wtn mltcaracter relaton symbols

    In addton, spaces wc appear n qotedstrns, nqotedstrns, and format

    str ns sal l be sn f cant ( to spaces wc precede or fol low an nqotedstrn are not part of t strn)

    All keywords n a prorm, wen sed as sc, sall be preceded and followed by somecaracter oter tan a letter, dt, nderlne or dollarsn A keyword ay also befollowed by an endoflne

    4 1 3

    None.

  • 8/2/2019 ECMA-116

    22/203

    4 4 Setics

    The etters sha be the set of capita upper-case) and sma ower-case) atin

    etters contained in the character set in positions 4 to and to , re

    spective

    The digits sha be the set of rabic digits contained in the character set in posi

    tion to

    The reining chracters sha correspond to the remanng graphic characters in po

    sition to , to , 4, and of the E character set

    The nmes of the characters are specified in Tabe Tabe sha app when the

    standard coating equence is in effect , e ither b defaut or b exp ic it use of a

    COLLTE option see 4, , and ) The coding for the native coating sequence

    sha be impementation-defined

    charcters other etters denote themseves Letters denote themse ves

    within quoted-s trings, unquoted- strings and ine-input-rep ies Corresponding upper

    case-etters and ower-case-etters sha be equivaent when used in identifiers and

    kewords Quoted- str ing-characters aso denote themseves , except for the doube

    quote, which denotes one occurrence of the quotation-mark in the vaue of the string

    4

    one

    4 Rerks

    Other-chracers ma be defined b an impementation to be part of the character set

    fo r BSIC These characters ma be used in str ings and be accepted as characters

    in data suppied in response to a request for input or generated as the vaue of the

    $ function see 4) The effects of these other-characters are impementation

    defined

    Programs written using other-chracters except for end-of-ine characters) are not

    hemseves s tandard -conforming programs

    4 and Bocks

    4 Genera

    BSIC program is a sequence of ines Each ine contains a unique ine-number which

    faciitates program editing and serves as a abe for the statement contained in that

    ine

    BSIC program is divided ogica into a number of progr-units The fir st of

    hese is h e main-program, which is terminated b an end - ine Fo owing the main

    program ma be zero o r more externa- sub-def or exte-function-def Certain

    ogica groupings of ines within a BSIC program are caed b ocks

    4

    s l avll y E BIC2 pr ld.

    1 program

    program- name- ine

    progr-ne

    4. main-program

    unit-bock

    inte-proc-def

    > program-name-ine? main-program procedure-par

    ine-number PROGRM program-nme function-parm-ist?

    tai

    routine-identifier

    unit-bock< end-ine

    interna-proc-def bock> inte-function-def internasubdef

    dlr

  • 8/2/2019 ECMA-116

    23/203

    7 bock

    statementne9 nenmber

    10 statement

    11 decaratestatement

    12 mperatestatement

    1 stopstatement14 condtonastatement1 ta1 endofne17 endne1 endstatement

    19 procedrepart

    20 procedre2 1 remarkne

    22 ne

    23 prornt

    24 necontnaton

    - 17

    > statementne oop fbock seectbock

    ene protionblnenmber statement tadt dt

    > decaratestatement mperatestatementcondtonastatement

    > datastatement decarestatement dmensonstatement nstatementoptonstatement remarkstatement

    > arrayassnment arraynptstatementarraynenptstatement

    arrayprntstatement I arrayreadstatementarraywrtestatement I askstatement

    breakstatement castatement casestatement canstatement I

    cosestatement debstatement erasestatement I extdostatement

    extforstatement extfnctonstatement

    exi-hdlersatn extsbstatement

    osbstatement tstatement I

    hdlerresat I nptstatementetstatement I nenptstatement Inmercfnctonetstatement

    openstatement I prntstatement

    rdomestatement readstatement I

    resoresatn retrnstatement I

    setstatement I stopstatement Istrnfnctonetstatement I

    tracestatement rtestatementSTOPfstatement onosbstatement ontstatementtacoent? endofnempementatondefned

    nenmber endstatement taEremarkne procedre

    > externafnctondef I externasbdefnenmber nstatement remarkstatement

    endofne> casene I caseesene done esene

    eseftenne endfctonne I

    edhndlerlne endfne endne Iendseectne I endsbne I dwele

    I externafctonne exteasbne Iforne hdlerle I nteradefne I

    nternafnctonne I nternasbne ftenne maene I oopne nextne I proramnamene remarkneseectne statementne I uelne enle euselne

    > manproram I procedre

    ersd space ta 1 ersd

    A pr oram sa be composed of a seqence of nes . Exacty one of tese nes sa

    be a endne; te nes p to and ncdn ts endne constttes te manproram

  • 8/2/2019 ECMA-116

    24/203

    4 2 3

    - 18 -

    Lne-nube zeo not allowed leadng zeoe hal l hae no ee t Lne hall

    ou n aendng lne-nube ode A l l eeene t o lne-nube wthn a

    poga-unt hal l be to lnenube o lne wthn that poga- unt The nube

    o dgt n a lne-nube hall not eeed The alue o a lne-nube hall not

    eeed 0000

    The anne n whh the end o a lne deteted detened by thepleentaton ; e g the end- o - lne ay be a aage-etu haate a aage

    etun haate o ll owed by a lne- eed hate o the end o a phyal eod

    A phyal lne n a poga hal l ontan at ot 132 haate beoe eah endo

    lne ndato

    At any p lae whee a pae y be ued eept n quoted- tng unquoted- tng

    lteal -tng and eak- tng ( ee 4 1 and 4 3 a lneontnuaton ay be

    ubttuted o a pae wth no eet othe that o the pae t eplae

    Paaete n the poga-nae- lne hall not be ep ltl y d enoned o de laed

    n the an-poga

    2 100 PROGRAM Gaph & h poga daw a gaph

    & ( x, & oodnate& y y yoodnate

    18 999 E

    424 Seant

    The poganae- lne the opend o the hantateent ( ee 9 3 The

    elatonhp between te poganae and the poga-degato n a poga

    eeutng a hantateent pleentaton-dened Paaete n te poga

    naelne ae ealuated a debed n 9 . 1 The ope the anpoga Fo a

    pog eeuted n o laton te poga-nae ha no ee t The ee t o apaete -lt n a poganae lne o a poga eeuted n olaton

    pleentaton-de ned

    ne n a poga hal l be eeuted n equental od e tatng wt the t

    lne untl

    oe othe aton dtated by eeuton o a lne o

    an eepton ou (unle n BASIC 2 t a nonatal eepton whh not

    handled by a ue dened eeptonhdle o

    a hantateent eeuted o

    a top-tateent o endtateent eeuted

    he endtateent hall ee bo to ak the phyal end o e npog nd

    to tenate eeuton o e pog when enounteed

    Eeuton o a toptateent hal l al o aue tenaton o eeuton o the

    pog

    2

    one

    42 Rek

    Reeene to non-etent lne-nube n a pogaunt ae t eo

    Ipl eentaton ay theeoe teat the a eep ton they ae douented a

    uh

  • 8/2/2019 ECMA-116

    25/203

    9 -

    4 3 Aotato

    4 3 1 Geeral

    BASIC prorams may be aotated by coets at te ed of proram les or byseparate remark statemets

    4 3 2

    1 rerkstatemet

    2 remarkstr3 llstatemet

    4 talcoet

    rerkstr

    caractertalcoet

    exclamatomark rerkstr

    ecotato sall ot occr remarkstrs

    4 3 3

    1 INA CCK4 ! COMPE AVERAGE

    4 3 4 Sematcs

    If te execto of a proram reaces a le cota a remarkstatemet or ll

    statemet te t sal l proceed to te ext l e wt o oter effect

    A talcoet as o effect po te execto of te le wc t occrs Te

    rerkstr te talcoet serves solely as a coet abot te le

    4 3

    Noe

    4 3 Remarks

    Noe

    4 4 Idetfers

    4 4 Geeral

    Idet fers are sed to ame varables arrays arrayvales fctos proramssbprorams ad exceptoadlers

    detfer

    mercdetfer

    detfercaracter4 strdetfer

    rotedetfer

    mercdetfer strdetferrotedetferletter detfercaracters ABS ACOS ALE ASI AT CEIL COS COSH

    COT esc DATE DE EPS P FP

    IT IP LO LOl LO2

    MI MOD PI R RAID I ROU SEC S SI SIH SQR TA

    TAH TI TRUCATE

    2. ranoiz-statnt RMIZE

    5.4.3

    2. RADOMIZE

    5.4.4 Satics

    Th valus of th nuric-suppli functions, as ll as th nubr of argunts

    rquir for ach function, shall b as scrib blo. In all cass, X an Y stan

    for nuric-prssions, an stans for an in, i.. th roun intgr valu

    of a nuric-prssion. Each function accpts nuric argunts ithin th rang of

    th ngativ nubr with th largst agnitu to th largst positiv nubr, xcpt

    whr not. For functions which rturn a valu in angl masur (ACOS, ALE, ASI

    an AT), th valu shall b in raians unlss OPTIO ALE DERS is in ffct (s

    5 6 whn th valu shall b in grs. In th santics blow, " pi" (lowr-cas)

    stans for th tru valu of that constant.

    Function

    Function valu

    ABS(X)

    Th absolut valu of X.

    ACOS(X)Th arccosin of X in raians or grs (s 56), hr 0 ACOS(X) pi; X

    shall b in th rang 1 X 1

    ALE(X, Y)

    Th angl in raians or grs (s 5 6 btwn th positiv -ais an th

    vctor joining th origin to th point with coorinats (X, Y), whr -pi 0

    RTRIM$(A$)

    The string o f characters r esul ting from te value assoc iated with A$ bydeleting a ll trai ling space characters

    STR$(X)

    TI$

    The string generated by the print-statement as the numeric-representation of

    the value associated with X No leading or triling spaces shall be includedin this numeric-representation or example , STR$( 23 5 ) 1 2 3 5 andSTR$(-3 4) = - 3 4

    The time of day in 24-hour notation according to ISO 3 307 or exampl e, thevalue of TI$ at ll:5 is 1 l : 5 : 0 0 If there is no c lock avail able ,then the value of TIM$ shal l be 1 1 99 : 99 : 9911 The value of TIM$ at midnight

    is 1 100 : 00 : 001 1

    UCASE$(A$)

    The string of characters resulting from the value associated wi A$ by replacing each lower-caseletter in the string by its upper-case version

    USING$(A$ ,X)

    The string consisting of the foatted representation of X, using A$ as aformat-item, accord ing to the semantics of 0 4 The exceptions defined in

    0 4 5 fo r fomatted output als o apply to the USING$ function

    VAL( A$ )

    The value of the numeric- constant assoc iated with A$ , if the string associ ated with A$ is a numeric constant Leading and trail ing spaces in te stringare ignored If the evaluation of te numericcons tant would result in a

    value which causes an underfl ow, then the value returned shal l be zero orexample, VAL( " 123 5 ) 123 5 , VAL( 2 E -9 9 ) could be zero, andVAL("MVII") causes an exception

    6 4 5

    - The value of the argument of VAL is not a val id numeric-constant (400 1, fatal )

    - The value of the argument of VAL is a val id numeric -constant, but evaluating thisconstant results in an overfl ow (1004 , fatal )

  • 8/2/2019 ECMA-116

    47/203

  • 8/2/2019 ECMA-116

    48/203

    - 42 -

    6.5.6 Remrks

    The order of assignment of alues to string-riables in the string-ariable-list is

    importt in statements such as

    LT A $ ( 1 2 ) , A $ ( 2 3 ) = Xwhere di fferent order of ass ignment y produce dif ferent results

    6 . 6 Declarations

    6 6 .1 Generl

    6 . 6 . 2

    option-statement may be used to define n ordering on the set of all string char

    cters

    A declare-statement may be used to set a maximum length for specified string

    ariables in a program-unit.

    l option2 type-declaration

    3 string-type

    length-max string-declaration

    6. simple-string-declaration

    >>

    >

    COLLAT (NATV / TANDRD)string-type

    TRNG length-max? string-declration (coastring-declaration)'

    asterisk integersimple-string-declrationsimple-string-ariable length-max?

    optio n-statement wit a COLLAT option , if present t all , shal l occur in a lowernumbered line any string-expression, or dimension-statement or declarestatement referencing a string-array or string-riable within the same program-unitA program-unit shall contain at most one COLAT option

    No simp le- string-ariable shal l be declared more than once in program-unit . Asimple-string-ariable which is a formal-parameter or a parameter shall not occur ina declare-statement

    6 6 . 3

    1 COLLAT NATV3 TRNG\8 last_name$'20 , f irstname$ , mid d lename$

    6. 6 emantics

    The COLLAT option identifies the collating sequence to be used within a program-unitfor comparing strings ( see 8 1 ) and for computing alues of the C$ ad ORD functions ( see 6 . 4 ) . OPTON COLLAT NATV specifies that the natie co l lating sequence

    of the host system shal l be used OPTON COLLAT TANDA spec ifies that the col lat

    ing sequence shall correspond to the order of the chracters in Table l . f noCOLLAT option appears in a program-unit then the TANDARD collting sequence shall

    be used wihin that program-unit

    imple-string-ariables whose string-identifiers apper in string-types may hae aximum length less than or equal to te implementation-defined default alue. Themaximum is determined, in descending order of precedence , from

    - the length-m in he string- decl aration for that ariabl e;

    the length-max in the string-type of the declare-statement containing thatariable, or

    - the implementation-defined defaul t .

    The length-max guarantees that string alues up to that length my be stored in theariable ad tat an ttet to store a longer alue wil l cause a string oerf low ex-

  • 8/2/2019 ECMA-116

    49/203

    - 43

    ception. he implementation-defined imum string length default shall be at least

    13 characters

    A length-max of 0 in a string-type shall establish the associated string-variable as

    having a maximum length of zero ; i . e , the nul l string .6 6 5

    None

    6.66 Remarks

    he native collating sequence be the standard collating sequence.

    he CO option be extended, on national versions of this Standard , toaccoodate specif ic needs of local alphabets .

  • 8/2/2019 ECMA-116

    50/203

    44

    7 ARRAYS

  • 8/2/2019 ECMA-116

    51/203

    - 45 -

    7 . AYS

    Arys re indexed cl lectins f nmbers r str ings . Arry elements cn be niplted bysclr nmeric nd string pertins ( see 5 nd 6) In dditin entire rrys my be niplted by mtrix s ttements .

    7 . 1 Declrtins

    7 . 1 . 1 Ge n e r l

    An ptin in the ptin-sttement my be sed t define the lwer bnd fr ll rrysbscripts within prgrm-nit which re nt expl icit ly stted . By se f n

    ptin-sttement the sbscripts f ll sch rrys my be decled t he lwer

    bnd f zer r ne; if n sch declrtin ccrs the lwer bnd shl l be ne.

    Arys my he ne tw r three dimensins . The nmber f dimensins nd sbscript

    bnds fr ech dimensin re declred in the declre-sttement r dimensinsttement . A l l rry-nmes except ths e ppering in fnctin-prm-l ist r

    prcedre-prm- l is t mst be declred in ne nd nl y ne sch sttement . If nt ex

    plicitly declred the lwer sbscript bnd fr gien dimensin is ne r zerdepending n e BASE ptin. Upper bds mst lwys be explicitly declred.

    A ne-dimensinl rry with sbscripts 1 t 10 r 1980 t 1989 r -9 t 0 cntins10 elements . A tw- dimensinl rry wi th sbscript bds 1 t 10 fr ech d imensincntins 100 elements . Simil rly three-dimensinl rry with sbscript-bnds 1t 10 fr ech d imensi n cntins 1000 e lements .

    A declre-sttement cn be sed t dimensin nmeric-rrys s well s t declremximm lengths fr string-ribles d string-rrys nd t dimensin string

    rrys . A dimensin-sttement cn be sed t dimensin rrys bt nt t declare themximm length f strings in string-rrys .

    7 . 1 . 2

    1 . dimensi n-sttement2. dimensin-list

    3 rry-decltin4 nmeric-rry-declrtin5 . bnds

    6 bnds- rnge7 . signed-integer

    8 . string-rry-declrtin9 . ptin

    10 . string-declrtin

    11. nmeric-declrtin

    12 . nmeric- fnctin-ref

    13 . mxsi ze-rgment

    14. bnd-rgment

    DIM dimensin-list

    rry-declrtin (c rry-declrtin)nmeric-rry-declrtin string-rry-declrtinnmeric-rry bnds

    left-prenthesis bnds-rnge (c bnds-rnge)*right-prenthesis

    signed-integer TO signed-integer signed-integer

    sign? integerstring-rry bnds

    > BASE ( 0 1 )

    > string-rry-declrtin length-x?> nmeric-rry-declrtin

    > MAXSIZE xsize-rgment SIZE bnd-rgment O bnd-rgment O bd-rgment

    left-prenthesis ctl-rry right-prenthesisleft- prenthesis ctl -rry ( c index) ?right-prenthesis

    The nmber f bnds- rnges in "bnds " s h ll be ne tw r three .

    An rry which is nmed s frml-rry f defined-fnctin sbprgram r prgram shll nt be declred in declre-sttement r dimensin-sttement (sincethe frml-rry in the fnctin-prm-list r prcedre-prm-list seres s its dec

    lrtin) . Any ther rry shl l be dec lred in lwer nmbered l ine thn nyreference t tht rry r ne f its e lements . y reference t n rry nd its el

    ements mst gree in dimensinlity with the declrtin f tht rry in declresttement dimensin-sttement r s fnctin-prameter r prcedr-prameter.

  • 8/2/2019 ECMA-116

    52/203

    - 46 -

    No numeric-array or string-array shall be dimensioned or declared more once in a

    program-unit

    If the optional lower bound (the first signed-integer) is included in the bounds

    range it shall be less o r equl to the upper bound ( the second s igned- integer)

    If the lower bound is not specif ied then the upper bound must not be less thedefault lower bound which may be ero or one depending on the BASE option

    opti on-s tatement with a BASE option if present at al l shal l occur in a lowernumbered line any declare-statement or dimension-statement or any MAT statement

    that uses a numeric -array-value in the se program-unit A program-uit shal l contain at most one BASE option

    If a bound-argument does not specify an index the actual-array must be declared as

    one-dimensional

    1

    1 DIM A(6 ) B( 1010) B$(100) D(1 TO 1980 TO 1989)

    DIM A$( 44 ) C( - TO 10)10 A$( TO 1) * 81 SIZE(Al )

    SIZE(B$)SIZE( X)BOUND(A)UBOUD( C$ )

    1 4 Stics

    Each array-declaration declares he named array to be either one-dimensional twod imensional or three-d imensional according to whether one two o r three bounds ranges are speci fi ed in the bounds fo r he array In addition the bounds specify the

    ximum and optional ly minimum values hat subscripts for the array shal l have If aminimum subscript is not explicitly declared and no BASE option occurs within theprogram-unit then it shall be implicitly declared to be one

    The BASE option in an option-statement is loal to the program-uit in which it oc

    curs and declares the minimum value for all array subscripts in that program-unitwhich are not explicitly declared

    If the execution of a program reaches a line containing a dimension-statement thenit shal l proceed to the next l ine with no further effect

    String-array-declarations appearing in a string-declaration ay include a length-axwhich sets the xim length of each element of he string-array. As wih simple

    string-vaiab les i f there is no length-max in he str ing-dec laratio n then he

    length-max if any of the string-type takes effect If there is no lengh-ax in ei ther then the implementation-def ined lengthx i f any shal l take effect

    The value of SIZE( A N) where A is actual -array N is index shal l be the

    current number or pemissible values for the Nh subscript of he array named by A( the value of N is rounded to he nearest integer and the subscripts of A are indexed from left to right starting at one) The value of SIZE( A) shal l be the current

    number of elements in he entire array A

    The value of MAXSIZE(A) shall be the total number of elements of he entire array

    named by A pemitted by the aray-declaation

    The value of BOUND(A N ) where A is an actual -array and N is an index shal l be he

    current minimum value allowed for the Nh subscript of he array named by A The

    value of UBOUND(AN) shall be he current maximum value allowed for he Nth subscriptof array A As in he SIZE fuction the value of N is rounded to the nearest inte-

  • 8/2/2019 ECMA-116

    53/203

    - 47 -

    ger a he subsripts of array A are iexe from eft to right startig at oe

    he LBOND a BOND futios may be a e with a sige argumets provie that

    argumets is a vetor i whih ase the vaue of LBOND a BOND are the urret

    miimum maximum vaues a owe for the subsript of the vetor (Here a i the

    fo owig setios the wor " vetor" sha mea a " oe-imesioa array" a thewor " matrix" sha mea a "two-imesioa array")

    7 1 5

    - The vaue of the iex i a SZE referee is ess tha oe or greater tha the

    umber of imesios i the array (4004 fata)

    - The vaue of the iex i a LBOD referee is ess tha oe or greater tha the

    umber of imesios i the array (4008 fata)

    - The vaue of the iex i a BOD referee is ess tha oe or greater tha the

    umber of imesios i the array (4009 fata)

    7 1 6 Remarks

    The imesio statemet is retaie for ompatibi ity with Miima BAS A its a

    pabi ities are i ue withi the e are-statemet

    f a impemetatio supports more three imesios SZE LBOND a BOND

    shou work for those extra imesios a exeptio shou be geerate oy

    whe a attempt is e to iquire about a imesio beyo those e are

    7 2 Numeri

    7 2 1 Geera

    Numeri-arrays i BASC y be mipuate e emet by e emet However it is ofte

    more oveiet to regar umeri-arrays as etities rather tha as iexe o e

    tios of etities a to maipuate the etire etity at oe BASC provies a um

    ber of staar operatios to fai itate suh maipu atios

    7 2 2

    1 array-assigmet > umeri-array-assigmet2 meri-array-assigmet MAT umeri-array equas-sig

    meri-array-expressio

    3 . umeri-array-expressio

    4 meri-array-operator

    5 saar-mutipier

    6 umeri-array-vaue7 . reim

    8 reimbous

    (umeri-array umeri-array-operator)? umeri-array

    I saar-mutipier umeri-array I

    umeri-array-vaue I

    umeri-array-futio-ref

    sig I asterisk

    primary asterisk

    > saar-mutipier? (CON DN ZER) reim?eft-parethesis reim-bous (o reim-bous)right-parethesis

    (iex TO)? iex9 umeri-array-futio-ref= T NV) eft-parethesis umeri-array

    10 umeri-futio-ref

    right-paretesis

    > DET (eft-parethesis umeri-array

    right-parethesis) I T eft-parethesis

    umeri-array o umeri-array

    right-parethesis

    The umber of reim-bous i a reim sha be oe two or three

    A umeri array beig assige a vaue by a meri -array-assigmet sha have tese umber of imesios as the vaue of the meri-array-expressio.

  • 8/2/2019 ECMA-116

    54/203

    - 8 -

    e umei -aays i a umei- fuio -ef ivovig T sa be oe-d imesiona .

    ee mus be o moe a wo edim-bounds foowig IDN.

    Te mei-aays i a sum o dif feee sa ave e same umbe of dimesios .

    Te umei -aay sevig as e agume of DET INV o TRN sa be wodimesiona .

    Te mei-aays sevig as opeads fo e umei-aay-opeao aseisk

    maix muipy) sa be eie oe-desioa o wo-dimesioa and a eas

    oe of em sa be wo-d imesio a .

    2 .

    I e foowig exampes A B ad C ae douby-subs iped umei aays Y adZ ae sigy- subs iped umei -aays and W is a umei -expessio .

    2 . MAT A B MAT

    MAT A B + c T -

    MAT A BC AT 'Y AT 'IAMAT A B HAT ONMAT A ZER) MAT ZERMAT A INVB) MAT A TRB )

    10 DETB) DOT Y

    2 . emais

    Exeuio of a umei-aay-assigme sa ause e umei-aay-expessio o

    be evauaed ad is aue assiged o e aay amed o e ef of e equassig . I f eessay is aay sa ave is si ze aged dyamia y; i . e . isumbe of dimesios sa be uanged bu is size i ea dimesio sa be

    aged o ofom o e size of e aay wi is e vaue of e mei-aay

    expessio.

    We e size of a umei-aay is aged dymiay e ue uppe bouds fois subsips sa be ged o ofom o e ew sizes . Ta is

    ew_owe_boud

    ew_uppe_bound

    od_owe_boundod_owe_boud + ew_size - 1

    Te ew sizes eed o idividuay be ess a o equa o e sizes deemied ie aay-deaaio fo a mei-aay as og as e ew oa umbe of eemes fo e umei-aay does o exeed e oa umbe of eemes deemied

    by e aay-deaaio fo a aay.

    Te evauaio of umei-aay-expessios sa foow e oma ues of maix

    ageba. Te smbos aseisk >

  • 8/2/2019 ECMA-116

    55/203

    49

    Wh a salamltipli is pst i a miaayxpssio, th pimay shall

    b valatd , ad th ah l mt of t miaay sha l l b mltip l id by this

    val

    If a dflow os i th valatio of a miaayxpssio, h th

    val gatd by th opatio whih sltd i th dflow shall b plad byzo

    Vals

    miaayvals shall b assigd to th miaay o th lft of th qalssig If o dim is pst, th siz of th miaay gatd shall b th

    sam as th siz of h miaay to whih it is to b assigd If a dim ispst, a mi aay of th dimsios sp if id shal l b gatd, ad th

    mi aay to whih it is ass igd shal l b dimsiod as ds ibd abov I a

    dim bods , th vals of th idis a th low ad pp bods of th o spodig dimsio i th assoiatd aayval If th dimbods osis ts of as igl idx , its val shal l b th pp boud, ad th low bod shal l b th

    t dfalt low boud i fft If a dim is sd wih th I ostat, hit shal l pod a sqa matix ; i , h mb of ows shal l qal th mb of

    ol ms If a dim is ot sd with th I ostat, th miaay big as

    sigd to shall b sqa

    Th ZE ostat sha ll gat a mia ay, a ll of whos l mts a zo ThO ostat shall gat a miaay, all of whos lmts a o Th I

    ostat shal l gat a idtity matix , i , a sqa tix wih os o th

    mai diagoal ad zos lswh If oly o dimbods is sd with I , thh fft is jst as if that dimbods had b spifid twi

    If a salamltipli is sd with a I, ZER o O ostat, th th pimay

    s is valatd ad ah oz o l mt of th I, ZE o O ostat is

    plad by th val of h piyFtios

    Th ftio T shall pod h taspos of its agmt x M matix is td fo a M x agumt

    Th futio IV sha ll pod h ivs of its agumt Th agumt mst b asqua matix

    Th ftio shall t th dtmit of its agumt Th argmt mst b a

    sqa tix

    Th val of TX shall slt i a sala val, whih is th slt of th i

    podt mlt ipl iatio of th odimsioal mivtos X ad

    2

    Th sizs of miaays i a miaayxpssio do ot oform to thls of matix algba 600 , fatal

    Th total mb of lmts qid f o a dimsiod aay xds th mbof l mts svd by th aay s oigial d sios 500 , fatal

    Th fist idx i a dimbods is gat th sod 6005 , fatal

    dimbods osists o f a sigl idx whih is lss th dfalt lowbod i fft 6005 , fata l

    Th dim fol lowig I dos ot spify a sqa tix, o o dim is pstad th ivig matix is ot sqa 6004, fatal

    Th agmt of th ftio is ot a squar mi tix 6002 , fata l

  • 8/2/2019 ECMA-116

    56/203

    so

    The argmen of he IN funcon s no a square numerc rx ( 00 faa ) .

    Evauaon of a numerc arraexpress on resus n an overfow ( 1005 faa ) .

    Evauaon of DET or T resus n an overfow ( 1009 faa) .

    App caon of IN o a snguar rx or os s of a s gnfcan dgs ( 009 faa) .

    7 .2 . Rerks

    I s recoended ha mpemenaons repor uderf ow as an excepon ( 150 5 nonfa

    a : repace b zero and connue) . In BASIC2 emenaon hs perms nercep

    on b excepon handers .

    7 . . 1 Ge n e r a

    As wh numercarras srngarras be regarded as enes raher as n

    dexed co econs of enes . BASIC provdes he ab o concaenae and assgn

    enre arras of srngs

    7 . . 2

    1 . arraass gnmen2 . srngarraass gnmen

    . Srngarraexpresson

    4 srngarraprmar

    5 . srngarravaue

    > srngarraassgnmen

    T srngarra subsrngquafer? equassgnsrngarraexpressonsrngarraprmar (concaenaon

    srngarraprmr) ? I srngprmarconcaenaon srngarraprr I

    srngarraprmar concaenaonsrngprmar I srngarravaue

    srngarra subsrngquafer?

    ( srngprmar concaenaon) ? N do ars gnredm?

    A srngarra beng assgned a vaue b a srngarraassgnmen sha have he

    same number of dmensons as he vaue of he srngarraexpresson.

    Two srngarras beng concaenaed sha have he same number of dmens ons .

    7 . .

    2 . MAT A$ A$ & B$

    MAT A$ N$( 5 )

    MAT A$ ("Number") & B$

    MAT A $ ( 4 : ) = ( " " ) & B$

    7 . . 4 Semancs

    Execuon of a srngarraassgnmen sha cause he srngarraexpresson o beevauaed and s vaue assgned o he arra amed o he ef of he equassgn.If approprae hs arra sha have s sze changed dmca . e . s numberof dmensons sha be nchanged bu s s ze n each dmenson sha be changed o

    conform o he sze of he arra whch s he vaue of he srngarraexpresson.

    When he s ze of a srngarra s chaged damca he curren upper bounds fors subscrps sha be chaged o conform o he new szes . ha s

    new_ower_boundnew_upper_bound

    od_ower_boundod_ower_boud + new_sze 1

    The new szes need no ndvdua be ess han or equa o he szes deemned nhe srngarradecaraon for ha srngarra as ong as he new oa number

  • 8/2/2019 ECMA-116

    57/203

  • 8/2/2019 ECMA-116

    58/203

    8 . ONTROL S TRUTURES

  • 8/2/2019 ECMA-116

    59/203

    - 53 -

    8 . CONTROL STRUCTURES

    Contro l structures gove the order of execution of lines in a program, both by statementshich me explicit reference to line-numbers and also by explicitly-constructed loops and

    decisi on mechanisms hich make no reference to line-numbers

    8.1 Relational

    8 .1 .1 General

    8 . 1 . 2

    8 . 1 . 3

    Relational-expressions enable the values of expressions to be compared in order to

    influence the flo of control in a program.

    1 . relational-expression2 . disjunction

    3 . conjunction

    4 . relational-term5 . relational-primary

    . comparison

    7 relation

    8 . euality-relation9 . not-euals

    10 . not-less

    11. not-greater

    disjunction

    conjunction OR conjunction)relatio nal- term AND relational- term)

    NOT? relational-primary

    comparison left-parenthesis relational-expression

    right-parenthesisnumeric-expression relation numeric-expression

    string-expression relation string-expression

    euality-relation greater-than-sign less-than-sign not-greater notlesseuals-sign not-euals

    less-han-sign greater-than-sign I greater-than-signless-tan-sign

    greater-than-sign euals-sign euals-sign

    greater-than-signless-than-sign euals-sign euals-signless-than-sign

    2 . NOT X < OR A$ = B$ AND B$ C$3 . A

  • 8/2/2019 ECMA-116

    60/203

  • 8/2/2019 ECMA-116

    61/203

    3 . ongotostatement

    4. gosubstatement

    5 . retustatement

    6 . ongosubstatement

    8 2 3

    2 GO TO 99 9

    GOTO 99 9

    3 ON +1 GO TO 400, 400, 500

    55

    ON index (GOTO GO TO) linenumber (co

    l inenumber) ( S iperatiestatement) ?(GOS GO S) linenumber

    ON index ( GOS GO S) linenumber (col inenumber ) ( LS peratiestatement) ?

    ON X GO TO 100, 200, 150, 9999 S L A 1

    4 . GO S 5000

    GOS 51606 ON A+ GOS 1000, 2000, 000, 4000

    ON Fl2 GOS 4360, 4460, 4660 S PRINT F$

    824 SemanticsExecution of a gotostatement shall cause execution of the progrm to be continued at

    the line ith the speci fied l inenumber

    he index in a ongotostatement shall be ealuated and its alue rounded to obtain integer, hose alue shll be used to select a linenumber from the list folloing

    the GOTO ( the l inenumbers in the l ist are indexed from left to right , starting ith

    1 ) . xecution of e program sha l l continue at the l ine ith the selected lin enumber . If e ongotostatement contains an S clause , and te alue of the indexin the ongotostatement is less one or greater the number of linenumbers

    in the li st , then the imperatiestatement fo l loing the LS sha ll be executed; if

    the imperatiestatement in the LS part does not transfer control to another line,then execution shal l be continued in sequence, i e , i the l ine fol loing atcontaining the ongotostatement.

    he execution of the gosubstatement or ongosubstatement and the retustatementcan be described in terms of sacks of l inenumbers , one associated ith each inocation of a programunit or intelprocdef (but may be implemented in some oer

    fashion) . ( The stack is c onceptual ; the Stdard does not require that this method be

    used ) . Prior to execution of the firs t gosub statement or ongosub statement in theinocation of a programunit or intelprocdef, the stack in that entity shall be

    empty ach time a gosubstatement is executed , the line number of the gosubstatement shall be placed on top of this stack and execution of the programunit orintelprocdef shall be continued at the line specified in the gosubstatement.

    The index in a ongosubstatement shall be ealuated by rounding to obtin an inte

    ger, hose alue shall be used to select a linenumber from the list folloing theGOS (the numbers in e lis t are indexed from left to right, starting it 1 ) Thel inenumber of the ongosub statement sha l l be p laced on top of the stack for e appropriate prograunit or intelprocdef, ad execution shall continue at the linei th e l inenumber se lected by the index . If the ongosub statement contains anLS clause, and the alue of the index in the ongosubstatement is less one or

    greater than the number of linenumbers in the list, then the imperatiestatementfolloing the ELS shall be executed and the stack of linenumbers shll not bechanged; if the imperatiestatement in the S part does not transfer control to

    nother line, execution sha ll then continue in sequence , i . e . , ith the l ine fol loing that containing the ongosubstatement

    ach time a retustatement is executed, te linenumber on top of the stack shall

    be remoed from te stack and execution of the programunit or intelprocdefshall continue at the line folloing the one ith that linenumber

  • 8/2/2019 ECMA-116

    62/203

    56

    A et- statement gosb-statement and on-gosb- statement within an intenal-p oc

    def shal l inteact only with the stack fo that intenal- poc-def Al l oe schstatements inteact only with the stack fo the pogam-nit containing he state

    ment

    t is not necessay that eqal nmbes of gosb-statements o on-gosb-statements andet-statements be exected befoe temination of a pogam-nit o intel-poc

    def; the stack of line-nmbes associated with the cent invocation of a pogamnit o ntel-poc-def shall be emptied pon teminaton of that pogam-nit o

    intel-poc-def

    8 2

    - The vale o f the index in an on-goto-statement o an on-gosb- statement wihot anSE clase s less one o geate than he nmbe of l ine-nmbes in he

    list ( 10001 fatal)

    - attempt is de to execte a et-statement wihot having exected a coesponding gosb-statement o on-gosb-statement wihin he same pogam-unit o

    intel-poc-def ( 10002 fatal )

    8 2 6 Reks

    The syntactic element contol-tansfe is defined solely to pemit descibing limitations on tasfes to l ine nmbes t is not geneated by ohe podctions

    Refeences to nonexistent line-nmbes in a pogam-nit inclding those in contol

    tansfes ae synta eos ( see 4 2 ) Thee is theefoe no exception defined in

    this Standad fo sch efeences mpl ementations may howeve cho ose to teat themas exceptions if they ae so docmented since the effect of non-s tandad pogams

    is implementation-defined

    8 . 3 Stctes

    83 1 Geneal

    8 3 2

    Loops povide f o he epeated exection of a seqence of statements Do- loops po

    vid e fo the constction of loo ps wih abitay exit condit ions The fo -statement

    and next-s tatement povide fo the constction of conte-conto l led loop s

    l . loop

    2 do-loop

    3 . do-line4 do -statement

    5 exit-condition

    6 . do-body7 . exit-do-statement

    8 . loop-line9 . loop-statement

    10 fo-loop1 1 fo-line

    12 fo-statement

    13 contol-vaiable

    14 initial-vale15 limit

    16 incement

    17 fo-body

    18 exit-fo-statement19 next-line

    do-loop fo-loopdo-line do-bodyline-nmbe do-statement tail exit-condition ?

    (LE L) elational-expessionblock loop-line

    T DOline-numbe loop-statement tail

    LOOP exit-condition?fo-line fo-body

    line-numbe fo-statement tailFOR contol-vaiable eqals-sign initial-vale TOlimit (STEP incement) ?

    simple-neic-vaiablenumeic-expessionnmeic-expessionnumeic-expessionbl ock next-line

    T FORline-nmbe next-statement tail

  • 8/2/2019 ECMA-116

    63/203

    57 -

    20 next-sttement control-vrible

    The control -vribl e in the next-sttement which termintes for- loop shl l be the

    sme s the cont rol -vrible in the for- sttement which begins the for- loop .

    A for-loop contined in the for-body of nother for-loop shll not employ the secontrol-vrible s tht other for- loop . No line- numbers in control -trnsfer out

    side for-loop or do-loop shll refer to line in the for-body of tht for-loop or

    in the do-body of tht do-loop.

    exit-do- sttement my only occur in do- loop . exit-for-sttement my only occur in for-loop.

    8

    2 0 ILE I N AND A(I) > 020 I I +

    0 LOOP2 00

    O I I 20 PINT MOE ENTIE0 INPUT A$( I )40 P UNTIL A$(I) = NO

    2 0 20 INPUT X

    ( NO I NON)

    0 I 0 X AND X 7 AND X = INT(X) IT

    40 PINT I NP INTEG B AND 7

    50 LP0 00 O I TO 0

    50 LET A( I ) = I200 I

    2 O I = A TO B TEP -20 C7

    8 4 emntics

    exit-condition shll be sid to require exit from loop if the vlue of thereltionl-expression following the eyword ILE is flse or if the vlue of the re

    ltional expression following the eyword UNTIL is true.

    If executio n of program reches do- l ine , en the exit-cond itio n, if ny , in thatdo- l ine shll be evluted . If there is no exit condi tio n, or if it does not require

    exit from the loop , then execution shl l proceed to the next l ine . If the conditionrequires exit from the loop, then execution shll continue t the line following thess ocited loop - l ine . If execution of progrm reches loop line, then the exit

    condition in ht loop - l ine, if ny, shll be evluted . I f there is no exit conditio n, o r i f it does not require exi t from the loop , then execution shl l resume t

    the ssocited do-line if the condition requires exit from the loop, then executionshll continue t the line following the loop-line.

    The ction of the for-sttement nd the next-sttement is defined in terms of othersttements, s follows.

  • 8/2/2019 ECMA-116

    64/203

    - 58 -

    0 FOR v = nta -vau TO mt T ncmnt ns

    50 NT v

    sha b quvant to

    LT own = mt20 LT own2 = ncmnt

    0 L v = nta-vau

    0 D NTL v- own ' GN 2 > 0 ns5 0 L v = v own2

    0 LOO

    v s any smp -numc- vaab and own and own2 a vaabs asso catdwth th patcua fo- oop and not accssb to th poga . Th vaabsown and own2 sha b dstnct fom sma vaabs assocatd w oth fooops . n th abov quvanc a conto - tansf to th fo- n sha b ntptd as a conto-tansf to th fst t-statmnt and a conto-tansf toth nxt- n sha b nttd as a conto- tansf to th ast t- statmnt .

    n th absnc of a T caus n a fo-statmnt th vau of th ncmnt sha

    b .

    xcuton of an xt-do-statmnt sha caus xcuton to contnu th n foowng th oop- n of sma st do- oop n whch th xt-do- statmnt occus . x

    cuton of th xt-fo-statmnt sha caus xcuton to contnu at th n foowng nxt- n of th sma st fo- oop n whch th xt-fo -statmnt occus .

    8 . . 5

    Non.

    8.. Rmks

    On xt fom a fo-oop ough th nxt-statmnt th vau of th conto-vaabs t f st vau not usd on a oth x ts fo m a fo- oop th conto-vaab

    tans ts cunt vau.

    8. Dcson tucturs

    8. . Gna

    8 . 2

    f- statmnt aows fo condtona tansfs fo th condtona xcuton of a

    sng patv-statmnt o fo th xcuton of on of two atnatvmpatv- statmnts .

    f-bock aows fo th condtona xcuton of a squnc of ns o fo thxcuton of on of sva a tnatv squncs of ns .

    A sct-bock aows fo th condtona xcuton of any on of a numb of atnatv squncs of ns basd on th vau of an xpsson.

    2. f-caus

    . f-bock

    . f-thn-n5 . thn-bock6 . sf-bock7 . sf-thn-n8. s-bock

    9 . s-n0 . nd-f-n

    mpatv-statmnt I n-numbf-thn-n thn-bock sf-bock' s-bock?nd-f-n

    n-nub F atona-xpsson tabocksf -thn-n bock'

    n-numb LF atona-xpsson tas-n bock

    n-numb L tan-nub D F ta

  • 8/2/2019 ECMA-116

    65/203

    11 . select-bloc

    12 select-lne

    1 . select-statement

    14 . case-bloc15 . case-lne

    16 case-statement

    17 . case-lst

    18 . case- tem1 . ange

    20 case-else-bloc

    1 . case-else-lne22 end-select-lne

    5 -

    select-lne er-lne case-bloc case-bloc

    case-else-bloc? end-select-lne

    lne-numbe select-statement talSELECT CASE expesson

    case-lne bloclne-numbe case-statement talCASE case-lstcase-tem (coa case-tem)constant I ange(constant TO I IS elaton) constant

    case-else-lne bloc*lne-numbe CASE ESE tallne-numbe SECT tal

    The constants appeang n case-statements n a select-bloc shall be the same type

    ( e ethe numec o stng ) as the expess on n the sel ect- statement Theanges and constants specfed n case-lsts n a select-bloc shall not oelap

    o lne-numbe n a contol-tansfe outsde an f-bloc then-bloc elsef-blocelse-bloc select-bloc case-bloc o case-else-bloc shall efe to a lne nsde

    tat f-bloc then-bloc elsef-bloc else-bloc select-bloc case-bloc o

    case-else-bloc espectely othe than to the f-then-lne of that f-bloc o theselect-lne of that select-bloc

    A lne-numbe n a contol-tansfe nsde an elsef-bloc else-bloc case-bloc

    o case-else-bloc may not efe to te assocated elsef-ten-lne else-lne caselne o case-else-lne

    8 4

    1 . I X => 2 GOSUB 00 SE GOSUB 2000

    I X$ = "O" OR X$ = "STOP" A = 1I A = B 100

    I A$ = B$ 200 SE 00

    10 I X = INT(X) 20 PRI X; "IS A INTEG"

    0 ESE40 PRINT X ; "I S NOT A INEG"

    50 I100 I A = 0

    110 PRINT "ONE ROOT"120 SEI ISC < 0

    1 0 PRINT "COMPL ROOTS"

    140 ESE150 PRINT ROOTS"160 EN I

    11 . 10 SELECT CASE A$( 1 1)

    20 CASE "A" TO "Z " "a" TO " z"

    0 PRINT A$ ; "s tarts wth a lette"40 CASE 0 TO

    50 PRINT A$; "stats wt a dg t"60 CASE ESE70 PRINT A$; "doesn t stat wth a lette o a dgt"

    80 SECT

  • 8/2/2019 ECMA-116

    66/203

    8 4 4

    - 60 -

    10 SECT CASE X

    20 CASE IS 0

    0 PRIT X " s negatve"

    40 CASE IS 0

    0 PRIT X; "s postve"60 CASE SE

    70 PRIT X; " s ero"

    80 SECT

    Sentcs

    If the vaue of the reatona-expresson n an f-statement s true and anmperatve-statement foows the keyword T then ths mperatve-statement shabe executed; f a ne-nber foows the keywork T then executon of the programsha be contnued at the ne wt that ne-number . If the vaue of the reatona

    expresson s fase nd an mperatve-statement foow the keyword SE ten thsmpertve-statement sha be executed; f a ne-number fo ows the keyword ELSE

    ten executon of te progrm sha be contnued at the ne wth at ne-numberf no SE s present then executon sha be contnued n sequence . e . wt he

    ne foowng tat contanng the f-statement.

    If -bocks sha be executed as fo ows . If a then-bock e se f- boc k or ese-boc k

    does not contan a bock te effect s as f t dd contan a bock consstng of a

    rerk- ne . If the vaue of the reatona- express on n the f -then- ne s trueten executon sha contnue at the frst ne of the correspondng hen-bock. If

    fase then the reatona-expressons of each correspondng esef-ten-ne fny sha be evauated n order. As soon as a true reatona-expresson s foundexecuton sha contnue at the f rst ne of the b ocks of hat ese f -b ock . If no

    true reatona -expresson s found n he ese f-then- nes then f an es e-b ock

    s present executon sha contnue at the frst ne of the bock of that ese

    bock. If there s no ese-bock executon sha contnue at the ne foowng theend-f-ne. When executon reaches the end of a then-bock an esef-bock or anese-bock t sha contnue at the ne foowng the correspondng end-f-ne.

    The expresson n a seect-statement n a seect-bock sha be evauated and tsvaue compared wth te case- tems n the case statements unt a mtch s found . A

    match sha occur when

    - the vaue of te express on equas that of a constant appearng as a case-tem or- the vaue s greater han or equa to hat of the frst cons tant appearng n a

    range contanng e word TO but e ss han or equ to te second or- the vaue satsfes e reatonshp ndcated by he reat on appeng before he

    constant n a rnge.If and when a tch s found the rest of he case-bock headed by e case-statement

    n whch the match was found sha be executed . If no case- tem s matched then thecase-ese -b oc k f t s present sha be executed . When executon reaches the endof a case-bock or case-ese-bock t sha contnue at the ne foowng the endseect-ne.

    estng of b ocks s permtted subje ct to the same nestng constrants as for- oops( . e. no overappng bocks ) .

  • 8/2/2019 ECMA-116

    67/203

  • 8/2/2019 ECMA-116

    68/203

    9 . PROGRAM S E GMENTAT I ON

  • 8/2/2019 ECMA-116

    69/203

    - 63 -

    9 PRRAM SEGO

    BASC rov des thee mechansms f or the segmentaton of rograms. h e frst rovdes for

    user-defned functons, hose values may be used n numerc-exress ons and strng

    exressons. he second enables subrogrs to be defned, hch councate va arametersand h ch can be nvoked v a a call-statement. he thrd enables searate rograms to be

    executed sequentally tou t user nteventon.

    Functons and subrograms (hch e refer to collectvely as "routnes") are o to tyesnteal d external Extenal routnes are ndeendent rogram-unts lexcally ollong

    the man-rogram. nteal routnes are contaned th n a rogra-unt (the man-rogr

    or an external rout ne) d are consdered to be art of tat r ogra-unt. ntel

    routne cannot conta n another ntenal routne.

    n general, a external routne does not share anythng (ncludng, but not lmted to,

    varables, DAA statements, nternal routnes, OPOs, and DEBUG status) th other

    rogram-unts. nformaton s exchanged beteen external routnes and other rogram-unts

    by means o arameters and, n the case of external functons, retued values. n general,

    an nternal routne sares everytng th ts surroundng rogram unt, th the exceton

    of ts arameters. here are no local varables for nternal rout nes. See Aendx 2 or

    more deta l on scoe ules.

    \thn a rogram-unt, a routne must alays be defned or declared n a lne lexcally

    recedng ts frst nvocaton n that rogramunt. t s not an error for a routne to be

    dened or declared thout beng nvoked. extel routne may be nvoked throughout

    the rogram an nteal routne may be nvoked only from thn ts contanng rogram

    unt.

    o control transfer thn an nternal or exteal routne may refer to a lne-nuber

    outsde that routne, nor may a control-transer outsde a routne refer to a lne-number

    thn t.

    91 UserDened Functons

    911 General

    912

    n add ton to te mlementaton-suled fnctons rovded for the convenence o

    te rograer (see 5 . 4 6 . 4 ad elsehere), BASC allos the rogrer to de ne

    ne unctons thn a rogram-unt or rogram.

    1 functon-de

    2 nternal-functon de

    3 . nternal-def-lne

    4 def-statement5 . numerc-de statement

    6. numerc-dened-uncton

    7 stng-def-statement

    8 strng-defned-uncton

    9 functon-am-lst

    10 functon-arameter

    11 fomal-array

    12 nternal-unctonlne

    nternal-uncton-de I external-uncton-de

    nternal-de -lne I nternal-uncton-lne block

    end-unct on-lne

    lnenumber def-statement tal

    numerc-def-statement str ng-def-statement> DEF numerc-defned-functon unctonarm-lst?

    equals-sgn numerc-exresson

    numerc-dentfer

    DEF strng-dened-uncton length-max?

    ncton-a-lst? equals-sgn

    strng-exresson

    strng-dentfer

    let-arenthess uncton-arameter (coa

    uncton-arameter) rght-arenthess

    > smle-varable I ormal-array

    array-ne left-arenthess coa rght-arenthess

    > lne-number FNCON (numerc-defned-functon I(strngdef ned-uncton length-max? ))

    fncton-armlst? tal

  • 8/2/2019 ECMA-116

    70/203

    13 ed fuctio lie

    1 etealfnctio de

    15 etealfuctio lie

    - 64 -

    liembe END UNCTION tail

    eteal fuctio lie uit bloc ed functio lie

    > lieumbe TERNAL UNCTION(meic defiedfunctio I

    (stigdefiedfuctio legthmax?))fctiopamlist? tail

    16 meic fuctio letstatemet = LE umeic defiedfctio equalssig

    meicepessio

    1 stigfuctio letstatemet = LET stigdefiedfnctio equalssig

    1. eitfuctiostatemet

    19 type declaatio

    0 def type

    21 itealfunctiotype

    . etealfunctio type

    3. fnctio list24 defied fuctio

    stigepessio

    IT UCTION

    > def type I itealfuctio typeeteal fctio type

    DE fuctio list

    UNCTION fuctiolist

    TERNAL FUNCTION fuctio list

    defied fuctio (coa defied functio)> meicdefiedfuctio I stigdefiedfuctio

    No liembe i a cotoltasfe outside a itealfuctiode shall efe to

    a lie i a iteal fuctio de othe ta to a itealfuctio lie o shall

    a liembe i a cotoltasfe iside a itealfctiode efe eithe to a

    lie otside at itealfunctio de o to the associated itealfuctio lie

    liembe i a cotoltasfe iside a etelfctiode shall ot efe

    to te associated eteal fuctio lie

    If a defiedfunctio i s defied b y a etealfuctio de it shall ot b e defied

    moe te oce i te pogam If a defied fuctio is defied by a itel

    fctio de it shall ot be defied moe tha oce i the cotaiig pogamuit

    thi a poguit o moe oe fuctio (iteal o eteal) of a giveame shall be declaed o defied

    If a defiedfunctio is defied by eteal functio de the a declae

    statemet it eteal fuctiotype cotaiig that defied fuctio shall occu i

    a loe umbeed lie tha the fist efeece to that defied functio i e same

    pogm unit

    If a defied fuctio is defied by a iteal fuctio de othe ta a itel

    de lie the eithe the iteal fuctio de o a declae statemet ith

    itealfuctio type amig tat defiedfuctio shall occu i a loembeed

    lie ta the fist efeece to that defiedfunctio i the same pogamnit

    If a defiedfctio is defied by itealdeflie the eite the itealde lie o a declae statemet ith def type ig that defied fnctio shall

    occu i a loeumbeed lie ta the fist efeece to that defied fuctio i

    te same pogamuit

    Selfecusive functios eed ot declae temselves that is if a functiode co

    tais a efeece to itself that efeece does ot equie a type declaatio co

    taiig te defied f uctio i a loe mbeed lie eit fuctio statemet

    shall occu oly ithi a fctio de

    Withi each fuctio de (ote ta a itealdef lie) shall occu at least oe

    umeicfuctioletstatemet o stigfunctioletstatemet ith defiedfuctio

    the same as te defiedfuctio i te iteal functio lie o etel fuctio

    lie of te functiode

  • 8/2/2019 ECMA-116

    71/203

    1

    65

    he umer ad type of fuctoargumets a umercfuctoref or strg

    fuctoref shall agree wth the umer ad type of fuctoparameters the cor

    respodg fuctode That s ,

    The umer of fuctoargumets shal l e the same as the umer of fucto

    parameters

    The fuctoargumets the fucto arg l st shal l e assocated wth the correspodg fuctoparmeters the fuctopa l st e , the frs t wth the

    fr st e secod wth the secod , etc ) , ad the types shal l correspod as fol

    lows

    arameter

    smpleumercvarale

    smplestrgvaraleformalarray umerc)

    formalarray strg)

    rgumet

    umercexpresso

    strgexpressoactualarray umerc)actualarray strg)

    The umer of dmesos of a actualarray shall e oe more the umer of comas the correspodg formalarray forlarray shall have o more three

    mesos two coas )

    Wheever a umerc argumet s passed to a correspodg umerc parameter a dfferet programut the ITTIC optos effect f or the two programut s must

    agree

    he ITIC opto exteralfuctode of umerc type must agree wth that of

    e vokg programut

    gve fuctoparmeter shal l occur o ly oce fuctopa lst Fucto

    parameters shall ot e explctly eclared or dmesoed wth the teral

    fuctode or exteral fuctode

    defedfucto appearg a deftype or tealfuctotype shall e defed

    elsewhere the se programut y a teraldefle or teralfuctode other tha a teldef l e) , respectvely

    defedfucto appearg a exteralfuctotype shall e defed elsewhere the program y a exteral fucto de

    5 DEF E = 2 7182818DEF VEGEX, Y) = X+Y)/2

    7 . D FN$S$, T$) = S$ T$

    DEF ght$$, ) = $ Le$)+1 Le$) )

    14 100 FUNCTION NSWE$)120 SEECT CSE UCSE$$)

    10 CSE "YES"

    140 LET NSW= 1150 CSE "NO"

    16 0 NSW=2

    170 CSE SE

    180 LET NSW=

    1 0 E SEECT

    200 END FUNCTION

    2 1 FUNCTION VGE, VSE$

  • 8/2/2019 ECMA-116

    72/203

    66 -

    9 1 Setic

    A function-def pecifie the men of evaluating a function baed on the value ofthe parameter appearing in the function-parm-lit and poibly other variable or

    contant .

    Function Parameter

    When a defined-function i referenced i . e . , when expreion involving the func

    tio n i evaluated) , then the argument in the fuction reference, if any, hal l be

    evaluated from left to right and their value hall be aigned to the parameter in

    the fuction-parm- lit for the function-def i . e . , argument hal l be paed by value

    to the parameter of the function . The number of dimenion in a forl -array i one

    more the nmber of coa in the formal-array. Upon invocation of a function

    def, a formal-array ha the ame bound a te correponding actual-array. A imple

    tring-variable or tring-array which i a function-prameter hall have the

    implementation-defined default a it ximum length.

    Fnction EvaluationIf a fnction i defined in a def-tatement , then the expre ion in that tatement

    hal l be evaluated ad it value ai gned a te value of the function. If a fnction

    i defined in an intel-function-def or external-function-def, then the line fol

    lowing te intel-function-line or external-fnction-line hall be executed in e

    quential order until

    ome other action i dictated by execution of a line, or

    - a fatal exception occur , or

    a chain - tatement or top- tatement i executed, or

    - an exit- fnction-tatement i executed, or

    - an end-function-l ine i reached

    The value of the defined-function hall be et by execution of one or more numericfunction- let- tatement or tring-function- let- tatement . Upon exit from the

    function-def , te value ha ll be that mot recently a igned to the define d-fuction

    in tat invocation . If , upon exit , no uch value ha been a igned , then the reult

    hall be conitent with the implementation-defined policie for ninitialized vari

    able. A lengt-max following a tring-defined-function etablihe the maximum

    length of the tr ing value to be returned by that function- def . If no length-max i

    pec if ied , then the maximm lengt hal l be te ame a for a tringvariable wi hout

    a lengt- max .

    exit -function - tatement, when executed , hal l terminate te execution of the

    function-def in which it i iediatel y contained . end-fnction-line mrk the

    textual end of a function-block, d alo hall terminate execution of te function

    block. Execution of a top-tatement in a fuction-block hall teinate execution ofthe entire program.

    A fnction-de f may refer , d irectl y or indirec tl y, to the function being def ined ;

    i . e . , recurive function invocation are permitted .

    Line in a function-def hall not be executed nle e fuction t define i ref

    erenced . If te execution of a program reache intel-d ef- l ine, it ha ll proceed

    to the next line witout furter effect. If execution reache an inteal-function

    l ine , i t hal l procee d to the line fol lowing the ao ciated end-fuction- l ine without

    further effect.

    of nel d Data

    A function-parameter appearing in the fction-parm-lit of a function-def hall belocal to each invocation of tat fnction-def ; i . e . , it ha ll name a variable or ar

    ray dit inct from any variable or array with te ame name outide te fuction- ref .

  • 8/2/2019 ECMA-116

    73/203

    67

    The reaen of variale and array hich are no ned a funcionparaeer in a

    funciondef hal l depend upon heher he funcio nde f i inernal or exeal f

    he funci onde f i exernal en uch variale ad array hal l e local o each

    invocaion of tha prograuni i . e . hey hal l e di inc fro ojec ih he

    ae ne ouide ha funciondef or ihin oher invocaion of ha fuciondef ; in addi ion hey hall e iniiali zed or no iniial ized in a aner coni en

    ih he ipleenaiondefined policie for he ainprogra each ie he funcion

    def i invoked . f e funcio ndef i inernal hen hoe variale and array

    hall e gloal o e conaining prograuni and hall reain heir aigned value

    each ie he fuci onde f i invoked; if hee value are changed during he coure

    of execuing he inernal funciondef the change reain in effec hen execuion

    i reurned o the urroding prograui.

    With one excepi on he cope of chanel nuer ee 2 ) i alay he progr

    i Nonzero chanelnuer ihin a funciondef hall e local o each invocaion

    of ha funciondef if i i exel and hall e gloal o he conaining

    progruni in hich i occur if i i inernal Channel zero hal l e gloal o

    the enire progra i le hal l e aigned o nonzero chanel ihin a progruniy ean of an open aeen efore ue . i le a igned o channel local o a

    funciondef hal l e c loed upon exi fro ha funciondef .

    The cope of ineal daa i alay he prograui Thu daa ih in an exernal

    fciondef hal l e loc al o each invocaion of tha progruni . ence read

    aeen and reoreaeen ihin uch a fnciondef hall refer only o daa

    in daa aeen ihin tha funcionde and no o daa in oher prograi .

    Upon invocaion of uch a funci ondef the po iner for he daa ithin t

    funciondef hal l e ree o the egining of the daa ee ) . Daa ihin an

    inealfuciondef hall e par of he daa equence for the conaining progr

    ui and readaeen and reoreaeen ithin uch a funcionde hall re

    fer o he eni re equence of daa in tha prograuni .

    .

    ring funcion le aeen aep o aign a value hoe lengh exceed he

    axiu for the ringdefinedfuncion 6 faal )

    R e r k

    Incopaile COTE opion are alloed eeen a invoking and invoked progruni

    even if hey coicae via ring pareer ) ecaue COTE doe no dicae the

    inernal repreenaion of ring u only heir order in a ring copari on and

    the value of the C and OR funcion .

    I i no a error for a inernalfuciondef o appear efore a declareaeenith defype or inernalfuncionype conaining he nae of tha inernal func

    io n I i no a error for a fncion o e defined y an ineral fnci ondef oro appear in a decl areaeen u no o e referred o in th prograni

    n ineralfucionype or defype ay e oied if te correponding definiion

    appear efore f ir reference . exernalfuncionype i alay required hen a

    exernalfncion i referenced in a prograuni.

    i no an error for a fucion o e defined y an ineralfunciondef or o ap

    pear in a dec lare aeen u no o e referred o in ha progrni

    I i no error for a inealfunciondef o appear efore a declareaeen

    ith defe or inernalfuncionype conaining the nae of tha ineral func

    ion.

  • 8/2/2019 ECMA-116

    74/203

    68

    ntenaluntontype o detype ay be otted the oepondng denton

    appea beoe the t eeene to tat unton etenaluntontype al

    way equed when an etelunton eeened n a pogaunt othe

    t own

    The equeent that both ntenal and etenal unton be delaed o dened be

    oe tey ae ued al low eveal pogaunt wthn a poga eah to ontan an

    ntenal unton wth the ae nae a an etenal unton Th altate the

    ue o unton lbae whee the pogae ay not know the nae o all the

    etealuntonde n the lbay

    2

    2 Geneal

    2 2

    Subpoga povde a ehan o the logal egentaton o poga al lowng

    paaete to be paed between poga egent Subpoga lke dened

    unton ay be ntenal o etenal to a pogaunt

    ubpogade

    2 ntenalubde

    3. ntena lub lne

    4 . ub tateent

    5