77
COMputation Research Group Technical Me.oranduM 209 Hortran3 U •• r's Cuide A. James Cook Co.putation Research Group 88 Stanford lin.ar Accelerator Center Stanford California, 9f30S December 16. 1982 Working Paper Do not quota, c.ite, .b:dr.ct, or reproduce without prior permission of the author{s}. DISCLAIHER NOTICE This document and associated documents and programs, and the IIMIteriel and data therein, were developed under the sponsorship of the U.S. government. Neither the U.S. nor the U.S.D.D.E •• nor the leland Stanford Junior University, nor their employees, nor th.ir respective contractors, subcontractors, or their e.ploy •• s. Makes any warranty, express or implied. or assumes any liability or responsibility for accuracy, completeness or usefulness of any information, apparatus, product or process disclosed, or represents that its use will not infringe privately-owned rights. "ention of any product, itl Manufacturer, or suppliers shall not, nOr is it intended to, iMply approval, disapproval, or fitness for any particular use. A royalty-fr... non-exclusive right to use and disseminate sa.e for any purpose whatsoever is expressly reserved to the U.S. and the University.

Working Paper - SLAC€¦ · "'Twas brillig. and the slithy toves ••• '). On output, Mortran3 will convert ~trings to the 1966 FORTRAN standard nH format if directed to do so

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

  • COMputation Research Group Technical Me.oranduM 209

    Hortran3 U •• r's Cuide

    A. James Cook

    Co.putation Research Group 88 Stanford lin.ar Accelerator Center

    Stanford California, 9f30S December 16. 1982

    Working Paper Do not quota, c.ite, .b:dr.ct, or reproduce without prior permission of the author{s}.

    DISCLAIHER NOTICE

    This document and associated documents and programs, and the IIMIteriel and data containe~ therein, were developed under the sponsorship of the U.S. government. Neither the U.S. nor the U.S.D.D.E •• nor the leland Stanford Junior University, nor their employees, nor th.ir respective contractors, subcontractors, or their e.ploy •• s. Makes any warranty, express or implied. or assumes any liability or responsibility for accuracy, completeness or usefulness of any information, apparatus, product or process disclosed, or represents that its use will not infringe privately-owned rights. "ention of any product, itl Manufacturer, or suppliers shall not, nOr is it intended to, iMply approval, disapproval, or fitness for any particular use. A royalty-fr... non-exclusive right to use and disseminate sa.e for any purpose whatsoever is expressly reserved to the U.S. and the University.

  • f ~,

  • Mortran3 User's Guide i

    t.

    z.

    3.

    CONTENTS

    INTRODUCTION

    PART I. The Prolr"".1 Lanlual.

    Features Directives

    PROGRAHHING CONVENTIONS

    Form, Line Length, Strings, Comments Labels, Blanks, Summary of Conventions

    STRUCTURE

    Statements Blocks Control

    Sequential control IF UNLESS ELSE ELSEIF FORTRAN IF Summary of IF, ELSE, and ElSEIF

    It.,..tive Control WHILE LOOP UNTIL FOR DO The "compact" DO "Forever"'" loops EXIT NEXT

    Multi-level Control Multi-level EXIT Mult;-le"el NEXT EXECUTE local procedure

    A.James Cook

    CGT" 209

    1

    3

    " s

    5 . 6

    • 7

    7 7 8 8 8 9 9

    10 12 12 13 13 13 1'1 15 17 17 18 18

    '9 20 20 21 22

    Decembe,. '6, 1982

  • Mortran3 Uaer's Guide - i, -

    II. co.rlOL SUHKARY . • • •

    Sum.ary of Iter.ttv. Control •• Sum.ery of Sequential Control

    GOTO :label:

    s. "ISCELLAHEOUS FEATURES

    5.

    MUltiple Assign.ent Input-Output Abbreviations ••

    PART II. Th. Deft.ttl •• La ... a •••••••••

    INTRODUCTION TO NOTATIONAL TRAHSFORHATIOHS

    A useful ex.mple •

    7. TRAIISFORHATION RULES

    The Si.plest Example. The T_plat. Part ••••• • • • •

    Parameter Kerkers • • • • • Specifiers •••.• . •••

    Forward references tn Specifications •••••• Specifying "Optional" ••••

    The Value Part • • . . • • • . • • Parameter References • . • •

    Left-to-right Substitution •• NULL 'ar .. eters . • . .

    Primitive Evaluation Functions. Order of evaluation .••• The REDUCE pri.itive ••••

    REDUCED text vs. REPLACED text. The COM.PUlE pri.itive •••••• •

    Constant expressions .•••• Constant Logical Expressions •

    Evaluation-ti.e IF-ELSE ••••• String Expressions ••••• The primitives HULL and EXIST

    Recursive Application of Rules. Unwanted Recursion •.•.

    The Scope of Rules • . . • • • Removing Rules and Specifiers •••• Internal Counters . • . . The LENGTH Pri.itive Appending text. Special Symbols The Reserved Symbol Other "special" symbols

    Terminators end Delimiters The Apostrophe ...

    . . . . . . . .

    .. . .

    ZS

    25 26 26

    27

    21 28

    za

    29

    29

    32

    32 33 33 35 31 31 38 38 39 110 III 41 112 /12 43 /13 114 45 46 47 48 50 51

    52 53 5/1 56 58 58 58 59 59

    A.James Cook - ii - December 16~ 1982

    ~

    - -._------ -----

    ~.

  • Mortran3 User's Guide - iii -

    A. PROCESSOR CONTROL

    Free-for. directives. Colu.n-one-restricted directives.

    B. PRI"ITIVE SPECIFICATIOHS.

    c.

    Qualifiers . . Quantifiers. . Alternative. Literals . .

    PRI"JTIV£ EVALUATORS . . . REDUCE • • • • • • • COMPUTE • • • • • Counter primitives. Parameter Primitives. Miscellaneous primitives.

    A.Jema5 Cook

    · . . . . . · .

    . · . . .

    - iii -

    .

    .

    · · · · · · · · · · · · .

    · · · · .

    . . . -. . . .

    . . . . .

    CGT" 209

    . .

    . .

    page

    &2

    62 64

    &5

    65 66 67 68

    59

    69 69 70 70 11

    Daeembar 16. 1982

  • - I -

    1. INTRODUCTION

    This Guide is divided into two p.~t.:

    • Pa~t I • P.rt II

    The P~og~amming Language. The Definition l.ngu.ge.

    COTM 209

    T~ prograMMing language (.ore accurately, the notation) I. dafined by .et of transFor.ation rules. TransFor_ation of Mo~t~an3 notation into FORTRAN notation results from the .pplication of these rule. bV the "ortran3 proeestfor.

    The definition language i. u.ed to define new progra .. ing notation •• Briefly, the US8~ supplies a prototgp. of a new not.tion. and. prototMP. of the FORTRAN notation into which his notation is to be transfor.ed. The details of how this is done i. the subject of Part II.

    "Lan.ua •• " versus "Notation"

    We are compelled by usage to describe "languages". even though that terM (as it is applied in cOMpute~-rel.ted contexts) has be.n abused to the point of becoming virtually ••• ningl •••• t Current use of the terM "high-level language" usually implies the existance of a p~ogr .. called 8 co.pil.r. The co_pilers ref.red to in this docu .. ent era FORTRAN compilers; they transform FORTRAN notations into "machine-dependent" bina~y not.tions.

    The binary not.tions into which. FORTRAN progr .. is transformed (translated) dapand upon the computer that will "executa" the progr... Consequently. a different FORTRAH compiler is ~equir.d for e.ch different computer on which FORTRAN programs will be "run".

    We regard FORTRAN compilers .5 hGrd.are-extens~ons. From this point of view. the portabilltg of FORTRAN p~ograms derives f~om the fact that virtuallv all "max;" and "mini" COMputers, .nd indeed. Many "micro" computars hava been extended 1n this sensa: they heve FORTRAN compilers.

    The Processo ..

    The Mo~tran3 proe.ssor exists in two forms:

    Form I: A FORTRAN program of lass than 2000 lines. and Form II: A Mortran program of 1855 thin 600 linl5.

    t Examples: Machine-language (meaning either binary notation notation), "achina-oriented-Ianguage (maaning a notation compiler.), Higl-1eval language, Procedural language. language, Structured language • • t eetera, ad absurdu •.

    or assembler for writing

    Hon-Procedural

    A.James Cook - 1 - December 16. 1982

  • "ortran3 U •• r'. Guide - z -

    When for. I f. compiled it produce. _ proc ••• or. Thl. processor can, viven the nec.ssary rule., tr.n.fo~ For. II into For. I. Given other rul... the processor can transforM Form II Into notations other t~n FORTRAN.

    P~".MPllatl ••

    The Mortran3 proc ••• or (.s described here)! i. • preco.pller·. output I •• compiler'. input.

    Portability

    A program P in Mortran3 .otation

    The Mortran3 proo •• sor

    The 'prograM P transfor.ed Into • program in FORTRAN notation

    A FORTRAN compiler

    A

    The portability of a FORTRAN program depends largely3 upon the extent to which the program. conforms to the (1966 ANSI)' FORTRAN .tandard.

    The MortranJ "language" does not produce FORTRAN state.ents that violate the 1966 ANSI FORTRAN standard. Consequently, "ortranJ program. .ay be .ade portable to the sa.e extent thet FORTRAN programs May be .ade portable.

    1 The "ortranJ processor •• y be used for other purposes. See the "ortran3 Refer.nee Manual.

    3 The precision with which arithmetic operations are performed i. not dealt with here.

    , FORTRAN 77, at this time. is not in widespread use. Pascal .... s • More likely candidate for the "portable language" for the near future.

    A.James Cook - z - December 16. 1982

  • Mortren3 User's Guide - 3 -

    FEATURES

    Free-fo,.. • Column and line (~ard) boundaries .ay be ignored. • Continuation .arks are not required.

    Labels • Alphanu .. rlo lebel. of arbitrary length are accepted. • FORTRAN .tate •• nt labels (numbers) are accepted.

    Local Procedures.

    He.ted block structure Controlled execution of blocks:

    • Saquential control IF, ELSE, ELSEIF~ UHLESS, end GOTO.

    • Iterativa control (loops) WHILE, UNTIL, FOR, LOOP, end DO. EXIT (jump out of) any loop NEXT (go to next iteretion of) any loop Tests for loop termination may b •• ade et the

    beginning of • loop and of a loop both begining and end of a loop nona of the above (i.a. "Forever" loops)

    • Multi-level control statem.nts. Multi-Ieval iterative control.

    EXIT (alphanv •• ric lab.,> NEXT (alphanu •• ric lab.I).

    Multi-level .equential control. EXECUTE Local Procedure. Gala alphonv •• ric label.

    Co .. ents may be inserted anywhare in the program taxt.

    Operators

    CGTM 209

    • Relational operators may be denotad by: . The operators •• y also be denoted by =< and >= respectiYely. The symbols $, #, and ~ .ay b. used if the user's display device is capable of representing them.

    • Logical operators .ay be denot.d by: ~(and), ICor), and ~(not).

    Conditional (altarnat.) oompilatlon

    Abbreviations Multiple assign.ant statements Input/output statements may ba abbreviated.

    A.James Cook - 3 - Dece.bar 16, 1982

  • Mortran3 User's Guide - " -

    DIREGTIVES

    Directiv •• do not involve transfor.ation of notations, Instructions to the processor.

    Llstt •• Directiv ••

    • AutoMatic printing of the nasting lavel.

    • Automatic indentation according to ne.ting level (optional).

    CGTM 209

    • Interleaving of t.he Mortran~ Source prograM as CO""ENTS in the generated FORTRAN program (optional).

    • Inclusion of "ortran3 COMMENTS.. COMMENTS in the generated FORTRAN prograM (optional).

    Other Directives

    • FORTRAN sourc. t.xt .ey b. Intersp.rs.d with Mortr.n3 source taxt.

    • Mortran sourc. input-unit swltoh' ••.

    • Mortren source input-unit rewladt ••.

    • Mortren input line~length May be .et by the progr .... r.

    • The number of columns of the input line that are intepreted as program text .. y be set by the programmer.

    • Automatic termination of Mortran co •• ents at the end of an input line.

    • Tracing of the transformation process.

    A.Jalnes Cook - II - December 16. 1982

  • Mortran3 User's Guide - 5 - C8T" 209

    z. PROGRAHnING CONVENTIONS

    St.t •• ents May bagin anywhere on a line. line or on a succeeding line.

    end .. y and anywhere on the s_a

    • Continuation Marks are not required (nor perMitted). • The end of •• tat .. ent i. deter.ined by a se.icolon (;).

    This convention (with the convention for blanks described below) parMits fre.-fo~ programming in which column end line boundaries May be ignored.

    LJ..u Length

    The line length L may be set by the programmer: 20S L SIZO. (Default: 80.)

    The number C of columns to be tntepreted as program text .ay be set by the programmer: 10 S C S L. (Default: 72.)

    Strtn,s

    ~ A string is a sequence of characters enclo.ed in apostrophes (.5 in 'TWINE'). An apostrophe within a string is denot.d by a pair of apostrophes (as in "'Twas brillig. and the slithy toves ••• ').

    On output, Mortran3 will convert ~trings to the 1966 FORTRAN standard nH format if directed to do so by he programmer. (S •• appendix A).

    • Example: 'DON'tT' will be convert.d to SHDOH'T

    Co .. nts

    Comments are .nclosed in quotation marks (as in "BALDERDASH!"). may contain any character except a quotation mark.

    Comments may be inserted anywhere in the program text except: • Within _ string .·coM.ent becomes part of the string . • In transfor.ation rules. (Se. Part II.>

    Example: Is equivalent to:

    CALL SUB (A "INPUT" , B "OUTPUT"); CALL SUB ( A , a );

    A comment

    A.James Cook - 5 - December 16, 1982

  • Mortran3 User's Guide - 6 - CGTM 209

    An .1p~numeric label is • sequence of c~r.cters enclosed in colons C •• in :COMSERVATIVE:).

    • The c~r.cter •• ay be .ny combination of letters and digits. • The length is arbitrary.

    :THIS ABSURDLY LONG ALPHAHU"ERIC LABEL IS A VALID LABEL:

    • Alphanumeric labals ere intandad to supplant FORTRAN stat .. ent labels, but FORTRAN st.te.ent label. (nu.bers) are allowed in MO.t context ••

    Ilanks

    A sequence of two or .ore blanks is equivalent to a single blank except in .irings. where all blanks ara pra.erved.

    Blanks are signiFicant in so.a Mortran3 contaxts.

    • :THIS LABEL: is equivalent to :THIS LABEL: :THIS LABEL: is not equivalent to :THISLABEL:

    • DOII:I," is acceptable in FORTRAN. In contrast. keywords must be followed by at la.st ona blank in "ortran3.

    Su ... ry of oonventtons

    • TerMinate statement. with a semicolon (;).

    • Enclose commants in quotation .arks (").

    • Enclose labels in colons (:).

    • Enclose character string. in apostrophes (I).

    • An arbitrary number of blanks may be substituted for a single blank QXCQpt in .trings.

    A.James Cook - 6 - DQcambar 16, 1982

  • Mortran3 User's Guide - '1 -

    3. STRUCTURE

    3.t IJATEHEITS

    A valid FORTRAN .tatement beco ••• a valtd Mortran3 st.te.ent when:

    • The statement is terminatad by • lamieolon, (3-1) • Continuation .ark. (if any) .re deleted, .nd

    • Hollerith fields ara converted to string •• '

    Subject to (3-1), FORTRAN .ay b. regarded as • sub •• t of Mortr.n3; Conversely, Mortran3 .ay be regarded as an extension of FORTRAN. Most of the "extenlions" are rel.ted to block structure and to the control of the execution of blocks.

    3.2 'LOCKS

    A Mortran3 block is •• equence of Mortran3 statements enclosed in the special characters [ and]. Let Si (i="n) be a sequence of Mortran3 statements:

    (3-Z)I~ _________ S_t_; __ S_Z_; __ S_3_;_._._._;_s_n_; ________ ~ The sequence (3-2) becomes a block when it is enclosed in brackets:

    (3-3)1~ ________ [ __ S_'_; __ S_Z_; __ S_3_;_._._._;_s_n_; __ ] ______ --J Blocks .ay ba nested. That is, a block may contain one or more blocks. For example, one could insert the block [ Ti ] (ia".) in (3-3) producing:

    [St; S2; (Tt; 12: 13 .•. 1.; ) S3 ••• Sn; )

    The block [ Ti ] is completely contained or nested within the block [ Si J.

    Example of • block: [ X=Y; CALL WUHDERCBAR). B=E; 1

    5 For example, tSHTHIS THING is converted to 'THIS THIHG '

    A.James Cook - '7 - December 16, 1982

  • -, - CGTM 209

    3.3 CONTROL

    • An ellipsis enclo.ed in bracket. [ ••• ] will denote an arbitrary block.

    • A control phro •• controls the ex.cution of • block •.

    • A control c/ous. I •• control phr •• e followed by the block it control ••

    • When referring to blocks:

    executed .eans: control i. tran.ferred to the first .tate •• nt within the block.

    skipped ••• ns: control Is transferred to the first st.t •• ent follow'n. the block.

    a.3.1 l.a.en11.1 !,nSr,1

    The .implest .equential control clause is the IF-clause.

    a.3.1.1 I,.

    .IF e [ ••• ]

    where. is an arbitrary logical expression • If e is TRUE, the block is.executed. • If e is FALSE, the block is skipped.

    Example (3-5) IF A=8 /; C>D ( C=D; E=F; ] G=H;

    FORTRAN IF(A.NE.I .OR. C.lE.D)GO TO It generated Cal) by "ortranJ E=F froll (3-5) II CONTINUE

    G=H

    The labal LI is a FORTRAN statement labal (integer constant) ganeratad by Mortran. One or more such labels is generated for each control phrase.

    A.James Cook - 8 - December 16. 1982

  • Mortran3 User's Guide - 9 - CGT... 209

    Notice that DeMorgen's lews heve been applied in (3-5),

    The expression "(A=I ,; C>D)

    beco.e. A.NE.I •• OR.C.LE.D

    De"organ'. I ... will be applied to expressions with FORTRAN operators (.LT., .LE., .EQ., ate.) .s wall. 3.3.'.2 UNLESS

    UNLESS a [ ••• ]

    • If e is FALSE, the block Is executed. • If e is TRUE, the block is skipped.

    3.3.'.3 ELSE

    An IF-clause (or an UNLESS-clausa) may be followed by an ELSE-clause:

    Example (3-7)

    A.JaMes Cook

    IF e [ ••• ] ELSE [ •.. l

    • If e is TRUE. the IF-block is execut.d and the ELSE-block is skipped.

    • If e is FALSE,. the IF-block is skipped and the ELSE-block is executed.

    IF A < I [ C=Di E=F; 1 ELSE [ G=H; I=Ji ]

    IF(A.GE.)GO TO L t C=D E=F GO TO L2

    L1 CONTINUE G=H I=J

    L2 CONTINUE K=l

    - 9 -

    K=L;

    December 16. 1982

  • "ortren3 U •• r'. Guide - 10 -

    3.3.t.. ELSEIF

    IF~ELSE-cl.us •• May b. n •• t.d to a depth of 50. aut ne.ting !F~ElSEs f. not always desirable; In some situations, on. wants to avoi_ n.sting. For e.-.ple. con.id.r the following ·ca.e analv.i.· proble.:

    (3-8) IF p [A] ELSE ( IF q [8] ELSE [ IF r [el ELSE [D) ] ]s:

    where p,q. end r ere logical expressions A,I,e, end D are blocks of .t.t .. ents • denote. the fir.t .t.te.ent following the nest.

    • If p i. TRUE. block A is executed and control i. tran.ferred to ••

    • If P is FALSE end q is TRUE. block I is executed end control i. tren.ferred to s.

    • If p and q ar. FALSE .nd r i. TRUE. block e is executed end control is transferred to s.

    • If p,q. end r ere ell FALSE. block D is executed, and control is transferred to s.

    Using."structured programming" principles to expos. the level of ne.ting, w. could re-writ. (3-8) as:

    IF p [Al ELSE [ IF q til

    (3-9) ELSE [ IF r [el ELSE [D]

    ] ]

    5;

    But (3-9) is awkward because each ELSE-clause incre.s.s the level of nesting. The ELSEIF-cl.us. combines an ELSE-claus. with an IF-claus.:

    IF P [Al ELSEIF q [I] ElSEIF r [e)

    ELSE [D]

    Thus, the tests ere .ade at the same nest level.

    An arbitrary number of ELSEIf-cleuses may follow an If-clau •••

    - 10 - December 16, 1982

  • ,.......

    1""".

    "ortren3 User's Guide - " - CGTM2tJ9

    In additton to the advantages Mentioned above, the ELSEIF generate. "cleaner" FORTRAN:

    IF P [A] ELSEIF q [I] ELSEIF r[C] ELSE ED] 5;

    IF(~(p» GO TO LI A GO TO L.

    Ll IFC .. Cq»GO TO Lz I GO TO til

    L! IFC .. Cr»GO TO L3 C GO TO l.

    L3 D l' CONTINUE

    s

    The nested If/ELSE example generates more "CONTINUE" st.tements:

    IF p [A] ELSE [IF q [8] ELSE [IF r[C] ELSE [DJ 1 1 5;

    IFC .... Cp» GO TO L, A GO TO l'

    l. IFC"(q» GO TO It 8 GO TO Ls

    Lt IFC .. Cr» GO TO L3 C GO TO III

    t3 D L, CONTINUE ls CONTINUE L, CONTINUE

    5

    A.James Cook - II - December 16~ 1982

  • "ortranJ User's Guide

    3.3.t.S FeRTRAH IF

    The FORTRAN logical IF: fs equivalent to:

    - IZ -

    IF(.) .t.t ••• nt. IF • [st.t ... nt.]

    CeT" zo~

    Th. IF-phrase is the preferred forM because an ELSE-clause (or an an ELSEIF-clau.e) .ay not follow. FORTRAN IF.

    Inoorreot: IfCX=Y) CALL SOME(HELP); ELSE [ ••• ] oorreot: IF X.y [CAll SOME(HElP).1 ELSE [ ••• ]

    3.3.1.& Su ... ry of IF, ELSE, .ad ELSEIF

    • An IF-clause .ay app.ar by itself.

    • An IF-clau.e •• y be followed by an ELSE-clause. .

    • An IF-clause .ay be followed by an arbitrary nUMber of ElSEIF-clausas.

    • The la'st in a sequence of ElSElf-clauses May be followed by an ELSE-clause

    A.James Cook - 12 - December 16. 1982

  • Mortran3 U •• r's Guida - 13 - CGT" 209

    a.a.z IS.raSly, Control

    A ~rtran3 loop i •• blD~k Nhi~h t. pr.~.d.d by end. optionally. follow.d by • loop-oontrol phras.. (W. will short.n this to "phras." In .ost cont.xt •• )

    • A loop is t,r_lnat.d •• ans: control Is transf.rr.d to the first st.t ... nt f.lloMt •• the loop.

    3.3.2.t WHILE

    WHILE. [ ••• ] WHILE. [ .•. ] REPEAT

    • REPEAT is optional. • IF • is FALSE. the loop is t.r.inat.d • • If • is TRUE (I the block is .x.cut.d and

    (2 control is r.turn.d to t.st • again.

    Exampl. (3-") WHILE A

  • Mo~t~an3 U.e~'. Guide - '" -

    a.a.2.3 _TIL

    UNTIL • [ ••• 1

    • IF • i. TRUE, the loop i. t.~.in.t.d. • If • is FALSE (I the block is executed and

    (2 control is returned to t.st • 8Sain.

    ExaMpl. (3-111) UNTIL X>Y [ ... ]

    lt IF(X.GT.Y)GO TO II

    GO TO l, Lz CONTINUE

    T.sts for loop ter.inat;on May b ••• da .t if ., and .z ara logical expressions, beginnins .nd the end:

    both ands of • loop. the following test

    Th. FORTRAN

    WHILE et [ ... ] UNTIL e2 ; WHILE at [ ... ] WHILE aZ ; UNTIL et [ ... ] WHILE e2 UNTIL et [ ••• 1 UNTIL al ;

    generated for the first exaMple is:

    WHILE at [ ••• l UNTIL 82.

    It IF(~(et»GO TO lz

    IF(ez)GO TO Lz GO TO L,

    Lz CONTINUE

    For eXaMple, .t both the

    Any Mortran3 loop may be tested at both ends, described yet: three flavors of FOR loops, "Forever" loop.

    including the ones we haven't two flavors of DO loops and the

    A.James Cook - If - December 16, 1982

  • - 15 - CGT" 209

    a.~.z.. FOR

    The loop control phr.... di.cuss.d up to this point do not Involve ~ontrol varlabl... that is. variables that are autoMattcally Incr .. ented (d.cr ... nted) for .ach .xecution of the loop. The FOR loop involve. _ control v_ri.bl ••

    FOR VaAx IY Ai TO Af [ ••• ]

    • V is the control variable. V •• Y be a subscripted variable. V ... t be of type REAL or INTEGER.

    • Ax. Ai, end Af are arbitrary arithmetic expressions.

    Ax is the initial value Ai i. the incr ••• nt A' is the 'inal value

    The values of Ax. Ai, .nd Af •• y be nagative.

    Ax is assigned to Vend the t.st for loop termination i •• ad.:

    A.James Cook

    The test: (3-' 5) 1L. __ A_i _*_( V_-_A_'_)_>_O--,

    • If (3-15) is TRUE. the loop i. tarminated. • If (3-15) i1 FALSE:

    (I the block is executed (2 V is incremented by the value of ~i (3 control is passed to the test •

    • Multiplication by Ai corrects the .ign of (V-A').

    - 15 - December 16, 1982

  • - 16 -

    FOR X=.t TO -.3 IY -.01 [ .~. 1

    Xc.f GO TO L3

    ", X=X+(-.DI) L3 If«-.Ol)*(X-(-3».GT.O)GO TO Ll

    GO TO L, t.l CONTINUE

    This trivial example i. presented to .ake the following points:

    • The increment in (3-16) t. n.vative • The control vartable X is assigned both zero and negettve v.lue •• • The loop Is terMinated only when X S -0.3. In the state.ents

    indicated by the ellipsis in (3-16). the progra_er _y change V or any of the variabl •• of A~, Ai, or AF.

    I) Change. in the variable. of Ax will heve no effect on the loop, .ince the a.sign.ent V=Ax is not re-executed.

    2) Changing the value of the variables of Ai or Ar .ight be useful for aSYMptotic proc •••• s.

    Assuming a "straightforward" application of the FOR-loop: If Ai .n~or Af are expressions whose evaluation i. tim.-consuMing. (and ti.e i. important) assign.ant of Ai and Af to temporary variable. outside the loop •• y be indicat.d. ,

    The FOR-loop has three forms:

    FOR VcAx BY Ai TO At [ ... ] FOR V=Ax TO Ar BY Ai [ ... ] FOR VI:A~ TO At [ ... ]

    where V, A~, Ai, and A(, are as above

    • If no increment (BY Ai) is given the integer I is assu •• d.

    A.Jame. Cook - 16 - Decamber 16, 1982

  • Mortran3 Use,.'s Guide - 17 -

    3.3.2.5 DO

    (3-/7)1~ __________ D_O __ i_=J_'._k_._n __ [_._._.] ________ ~ where i.j,k, end n .ust confor. to FORTRAN requir .. ents for DO loops.

    COTM 209

    A standard FORTRAN DO loop is generat.d froM (3-'7). Therefore, i.j.i. end n Must all b. of type INTEGER en~ .ay •• t be subscripted variables or expressions.

    3.3.2.5 The "collpaat" DO

    There is one except,ion to the rule that loops' Must b. preceded by control phra.es.

    (3-,B)I _____________ [_,_O=_J_O,_k_,_n_; __ ._._. __ 1 ______ __

    (3-18) generates a standard FORTRAN DO loop. This for. par.it. COMpact not.tion for nests like the following example.

    Example (3-19) [1=1 ,N/; [J=I,N2; [K=I,M3; ••• ll]

    DO 10 1=I,MI DO 20 J=I,N2 DO 30 K=I,N3

    30 CONTINUE ZO CONTINUE 10 CONTINUE

    This "oddball" notation has been severely criticized on the ground that it too "terse" and tends to obs~ur. rather than clarify loop control. It is included for "compatability" with Mort .. an2, and ~ec.use the author likes it.

    A.James Cook - 17 - December 16, 1982

  • - 18 -

    3.3.2.7

    lOOP [ ••. ] lOOP [ ••• ] REPEAT

    REPEAT I. option.l

    The "forever" loop generate. the following FORTRAN:

    II CONTINUE

    GO TO LI Lz CONTINUE

    The "exit" froN "forever" loops .ust be •• d. by a st.t •• ant within the loop. The lab.l L2 is gener.tad bV "ortren3 a. the "t.rget" for the EXIT. who •• description follow ••

    a.a.z... EXIT EXIT is "5horthand" for "jump out of this loop", where this loop rafers to the I ••• r ... t loop in which the EXIT appears.

    EXIT; IF (e> EXIT; IF e [ ... EXIT;]

    In the "forever" loop EXIT generate. "GOTO Lz". "terget" mentioned above.

    But EXIT may appear in ang MortranJ loop.

    where Lz· ref.rs to the

    In a Mort .. an3 loop, EXIT caus.s a transf.r of control to tha firlt st.t ••• nt following the loop in which it occu.... For nested loops, . the EXIT t. from the innermost loop to the next level out.

    A.Jame. Cook - 18 - Decembe .. 16, 1982

  • "ortran3 Us.r's Guide - 19 -

    3.3.2.' IlEXT

    NEXT is "shorthand" for "go to t~ next iteration of this leep". where this .oep refer. to the tn.er.ost loop in which the NEXT app.ars.

    NEXT; IF Ce) NEXT. IF • [ ••• NEXT;]

    NEXT transfars control to the beginning of the loop in which it occurs •

    • The control variable (if any) is Incremented

    • The test (if any) for loop ter.ination is .ade.

    • If tests at both ends of. tha loop are involved. only the test at the beginning of the loop i •• ade.

    • In FOR-loops and DO-loops. NEXT where LI refers to the leb.l on increments the control variable.

    generates GOIO the stat .. ent

    L •• that

    • In DO-loops. the statement that increments the control is the CONTINUE that Marks the end of the "range" of the DO.

    Phras •• control the execution of blocks. But notice that EXIT and NEXT refer to iterative control phrases, and not to •• qu.nlial control phrases.

    Exa.pla: UNTIL A=B [ ••• IF C=D [ ••• EXIT;] P=Q •.•• ] R=S; •••

    In this ex~ple EXIT transfers control to the statement R=S. and not to the st.tentent P=Q.

    A.James Cook - 19 - December 16, 1982

  • Mortran3 U •• r'. Guide - 20 -

    3.3.3 HUltt-l.y.1 Contr.1

    Ther • • r. two c.t"orf.s: •• qu.ntial. end it.retiv ••

    3.3.3.1

    -Multi-l.v.l it.r.tiv, control st.t ... nt. er.: EXIT: 10b.1 : "EXT: 'ab.,:

    -Multi-l.v.l •• qu.ntial control .t.t ... nt •• r.: EXECUTE proc.dure no •• LEAVE GOTD : 10b.l:

    HUltt-l.v.1 EXIT

    In nost.d loops, It .ay b. d.slrabl. to EXIT Mor. than on. l.v,l. EXIT of .or. than on. l,v,l of n •• ting •• V b ••• d ••• Iy fro. lab.led loops. A label.d loop is. loop pr.c •• d.d by an alphaau .. rlo l.b.l. A "ultt-l.v.l EXIT Is lIad. by:

    EXIT : 1 a"" , : ;

    EXIT:/ob.l: transf.rs control to the first statam.nt following the lab.l.d loop. The transf.r of control take. pl8ce regardl ••• of n.sting, and thus provides a ".ulti-l.~.l" EXIT capability.

    :bon: UNTIL Mort

    ]

    ho; hum;

    [ ch.rch.z; 18 verite; UNTIL oins=zw.i

    toktob.r;

    ]

    IF ( tod ) EXIT :bon:; IF (angst) EXIT; f.st:

    cast; la vie;

    - 20 -

    10 CONTINUE II IF(Mort)GOTO 12

    ·ch.rchez la v.rite

    ZI IF(.ins.EQ.zw.i)GOTO 22 oktob.r IF(tod)GOTO IZ IF(angst)GOTO 22 fest GOTO 21

    22 CONTINUE c.st la vi. GOTO II

    12 CONTINUE ho hum

    D.cember 16, 1982

  • " - 21 - CGT" 209

    3.3.3.2 ~Itl-Ievel .EXT

    NEXT :Iab.l: transfers Gontrol in the .anner d.scrlbed ebov. for NEXT, but .ay be Multi-Iavel. The following ax .. pla cont.ins both slngle-l.val end .ulti-Ievel EXIT. end NEXT ••

    ,SEARCH: FOR V=Ax IY Ai TO A' [

    :IOW: DO I=I,N [

    :COl: DO J=I,"

    [ ... UNTIL .0

    [ ... IFC.,)

    IFCe2)

    IFC.:.)

    IFCe')

    IFC.s)

    IFC.,)

    IFC.7 )

    ] "end

    ] "end COL"

    ] "end ROW"

    ] "end SEARCH"

    A.James Cook

    EXIT

    NEXT

    NEXT

    EXIT

    NEXT

    NEXT;

    EXIT;

    UNTIL"

    :SEARCH: . , :SEARCH: . , :ROW: . , :ROW:

    :COL:

    - 21 -

    10 CONTINUE V=Ax GOTO 13

    II VI:V+(Ax) 13 IF(CAi)*CV-CAF»

    * .GT.O)GOTO IZ 20 CONTINUE

    DO 21 I=I,N

    3D CONTINUE DO 31 J=I, .. .. ~

    III IFC.o)GOTO liZ

    IF(e3)GOTO IZ

    IF(e,)GOTO II

    IFCe:.)GOTO 21

    IFCe,)GOTO 22

    IFC.s)GOTO 31

    IFC.,)GOTO 41

    IFCe7)GOTO 112

    GOTO III 4Z CONTINUE Cend UNTIL

    31 CONTINUE 32 CONTINUE Cend COL

    21 CONTINUE 22 CONTINUE Cend ROW

    GOTO II 12 CONTINUE Cond SEARCH

    December 16, 1982

  • "ortran3·U.er'. Guida - ZZ -

    3.3.3.3 EXECUTE lo.oal pr.c.da ....

    no •• PROCEDURE [ ••. ]

    where no •• is alphanum.ric.

    A local procedure i. "call.d" by the .t.t •• ent:

    Any number of EXECUTE .t.t .. ents .ay precede a procedure.

    The "calls" EXECUTE PHI ; _st· precede EXECUTE PHI ; the 'roc .... r. PHI PROCEDURE [ ]

    After the procedure is executed control ;s returned to the first .t.tement following the EXECUTE st.tement. An EXECUTE st.tement .ust not follow. procedure:

    This sequence ts oorreot

    Hot this:

    EXECUTE PHI

    PHI PROCEDURE [ 1

    EXECUTE PHI ;

    • The first EXECUTE .t.temont will "call" PHI. and will return correctly.

    • The second EXECUTE statemant will "call" PHI. but wIll n.t return corr.ctly.

    Multiple returns fro. a procedure .re written:

    I LEAVE no.o: I A.James Coole - 22 - December 16, 1982

  • Mortran3 User's Guide - 23 -.

    Ex"ple of FORTRAN generated for procedures:

    EXECUTE RHO;

    EXECUTE PHI.

    EXECUTE PHI:

    EXECUTE RHO:

    PHI PROCEDURE [ LEAVE PHI; ]

    RHO PROCEDURE [ LEAVE RHO: ]

    CAVEAT !

    10

    30

    50

    COT" 209

    ASSIGN " TO K'20 GOIO 21 CONTINUE

    ASSIGN 10 TO KPtO GOTO III CONTINUE

    ASSIGN 5D TO KP.O GOTO "' CONTINUE

    ASSIGN 6D TO IP20 GOTO 21

    60 CONTINUE

    GOTO 113 112 GOTO KPIIO,(30, 50) "' CONTINUE

    GOTO 112

    GOTO 112 113 CONTINUE

    GOTO 23 22 GOTO KP20.(10. 60) 21 CONTINUE

    GOTO 22

    GOTO 22 23 CONTINUE

    Program units containing local procedures .ust avoid identifiers of the form:

    KPn I where n compris.s 2 to II decimal digits.

    (S.e the example above.)

    Moreover, the program unit Must not override the FORTRAN convention that identifiers beginning with "K" default to type INTEGER.

    A.James Cook - 23 - December 16, 1982

  • Mortran3 U.er'. Guide - 24 - C01M 209

    EXaMination of the FORTRAN generated for EXECUTE end rROCfDURE stete.ent. will reveal that:

    I) It t. not possible to -fall-into" _ procedure. because e brGnch Ground the procedure is generated by MortrenJ.

    2) It is not necessary t. Issue LEAVE stet ••• nts explicitly unle ••• ulttple returns are needed.

    3) EXIT :na.~: Is equivalent t. LEAVE no ••• confusion with loops.

    LEAVE should be us.d to avoid

    It should also be pointed out that "G010 proc.dur. no •• " wtll generate a FORTRAN cOMpil.-ti •• error of ""1551"6 LAIEl". (5 •• the following .ection.)

    A.James Cook - 24 - December 16. 1982

  • "ortran3 User's Guide - 25 - CGT" 209

    •• COHTROL IUtltARy

    •• I lllltABy![ ITDATIVE COITROL

    We can now summarize "GRTRAN loops in the following chart:

    optional choos. 0". optional

    WHILE ., UNTIL . , NEXT • LOOP EXIT;

    :/ob.l: fOR V=Ax IY Ai TO Ar [ ... EXIT : lab. I : • FOR V=Ax TO Af IY Ai NEXT :Iab.':~ FOR V=Ax TO AI' DO i=j,lc,n

    where:

    • .t end eZ are logical expressions.

    • V is a (subscripted) yeriebl. of type INTEGER Dr REAL.

    • Ax, Ai, and Ar are arbitrary arithmetic expressions,

    Ax is the initial Yalue. Ai is the incr ••• nt. Af is the fInal yalue .

    • i, j, Ie, end n are stendard FORTRAN DO yeriebles:

    i is • non-subscripted INTEGER variable. j, Ie, and n ere non-subscripted INTEGER variables

    or INTEGER constonts.

    The "compact" DO-loop does not "fit" in the aboye chart, that apply to DO i=j,lc,n [ ••• ] also apply to th. [;=j,k,n; ••• ]

    A.James Cook - 25 -

    optional

    WHILE flZ' ... ] UNTIL ez • REPEAT

    however, "COMpact"

    the rules DO-loop

    December 16, 1982

  • Mo~t~.n3 U •• r'. Guida - 25 -

    •• 2 IUnnABT I[ SEIUEITlftL COnTROL

    S.qu.ntlal control stat ... nts ar. IF, IF-ELSE, ELSEIF, end GOTO.

    •• 2.1 IIII :llb.l:

    This .tat ••• nt g.n.~at •• _ .tandard FORTRAN GOTO statem.nt. "ortran1 do.s not prohibit branching into the ranga' of • loop. cons.quently:

    • If the loop is • DO-loop, no error will be sener.ted by Mortr.n3, but an .~ror will b. g.n.rat.d by .08t FORTRAN cOMpil.rs.

    • S;milerly, GOTO proc.dur. nD •• will not g.n.rat. Mortran3 .rrors, but will generate fORTRAN compil.-ti ••• rrors.

    A.James Cook - 26 - D.cember 16, 1982

  • "ortren3 User's Guide

    S.t MULTIPLE 1$11'"",11

    produces:

    - 27 -

    s. "ISCELLANEOUS FEATURES

    V, •• xpr ••• ion Vz •• xpr ••• ;on V3=expr ••• ion

    NOTICE to MortrenZ users: this hes b.en changed.

    t10rtranZ produced

    This was changed because:

    V'=flxpr •• sion Vz=V, V31:VZ

    Vn=Vn-t

    COTM 2D9

    I) The Mortran2 version .. y cause conversion errors when the Vi are different types.

    2) This new version is "what one would expect".

    A.J ..... s Cook - 27 - D.c.mber 16, '982

  • "ortr.n3 U •• r'. Guida - 28 -

    5.2 INPUT-OUTPUT "I."IATIONS

    Example:

    Produces: 10

    OUtput

    Exemple:

    Produces: 20

    Where i-o li.t end for.at li.t must ••• t standard FORTRAN requtr .. ants.

    INPUT X,Y ; (2Fg.3)i

    READCS. IO)X.Y fORMAT (2F9 • .7)

    OUTPUT ;-0 I is': «(or.at I isl):

    Where i-o li.t and for.at list .ust ••• t standard FORTRAN requirements.

    OUTPUT Z J (t VOILA LE Z ',EI2.6)

    WRITE(6. 20)Z FORMAT (' VOILA LE Z '.E/2.6)

    COT" 209

    INPUT end OUTPUT may be g.neralized to include other logical i-o units. (s •• Part II).

    A.Jam.s Cook - 28 - December 16. 1982

  • "ortren3·U •• r's Guide - 29 -

    PART II. The D.ftaltl.ft Laft8Q_ ••

    •• INTRODUCTIOR T. ..TATIORAL TRAHSFORttATIORS

    The pr.,r ... tn, lanvuage de.cribed 'In Part I is defined by a .. t of tr.n.'or.ation rul... The #ran.'or.ation fro. Mortran notat1oft to FORTRAN notation i. the r •• ult of the opp·licfltion of these rules by the "ortran3 proe.ssor.

    Th. application of a rule involves:

    • "Recognition" of a notational "for." and • Subst itut ion of FORTRAN "for.(·.)" for the "for." that wa. "recognized".

    We will give precise definitions of these "fuzzy" st.te.ents later. aefore going into thet. w. pr ••• nt a s'.pl •• us.ful exampl ••

    5.t I USEEUL EXAHPLE

    Suppose one has a progr .. in which .ubscrip#. are calculated. and that errors will result if the subscripts ar. not within certein ranges. for exempl.:

    3 < J < 7

    One could insert IF, WRITE, and FORMAT stat •• ants thet issue error messages if these variables are not within the given ranges. lut such error-checking statements are obtrusive; they distract our.attention fro. More important aspects of the program. A Much less obtrusive (and e.sier to writ.) notation might be:

    Example (6-1) ASSERT 3 < J < 7

    One wants to transform notations like (6-1) would produce ruft-tt .. error .essages like:

    into FORTRA" st.te.ant. that

    ASSERTION "3

  • "ortranJ U.er's Guide - 3D -.

    A .ore general for. of (6-1) is:

    (6-Z) ASSERT di,it, < I.tt.r < digitz;

    The fORTRAH notation one .. ants to substitute for (6-2) should depend upon the octuol l.tter. and digits corresponding to fll.itt./.tt.r, and "fIi.itz.

    The transfor.atfon described above could be defined by:

    (6-3)

    REPLACE (ASSERT(DIGIT)«LETTER)«DIGIT» WITH ( IF( ~«(rl)«'Z) ~ (PZ)«P3» ) OUTPUT (PZ);

    (' ASSERTION "(PI)«PZ)

  • "ortr.nJ U.er's Guide - 31 -

    lut the progr .... r May d.fine sp*clfl.r. that .uit hi. own n .. d.. For ex.-ple. a spacifar •• y be defined that describe. _ variable..... A FORTRAN veriabl. n ... i.:

    A letter followed by not MOr. then 5 l.tters or digit ••

    A ~rtran3 apeoltter that could be u.ed to "recognize" a FORTRAN varl.bl. n ... i. defin.d by the following SPECIFY .t.t"ent:

    (6-4) SPECIFY FORTNA"E AS L~TTER (O.5)[LETTERIDIGIT] :

    Following the definition (6-4). (FOIT"A"£) could replace (LETTER) In the ASSERT rule definition ebov. so that the ASSERT not.tion could b. used with FORTRAN variable names instead of single letters. lut so.ething MU.t b. done about DIGIT el... The "s ••• thln,· follow.:

    SPECIFY CONSTANT AS (1.7)[DIGIT];

    How, on. c.n re-write the transfor •• tion rule as:

    (6-6)

    REPLACE (ASSERT(COHSTAHT)«FORTHA"E)«COHSTAHT» WITH ( IF( ~«(PI)«P2) , (P2)«P3» ) OUTPUT (P2).

    (t ASSERTION "(PI)«P2)«P3)" VIOLATED: (P2) .'.19). )

    Following the definitfon of (6-6), one .ight write:

    ASSERT 123f < INDEX < 5678;

    Producing. at rUft-tl .. :

    ASSERTION "123f

  • Mortr.n3 U •• r'. Quid. - 32 - CGTM ·209

    7. TRAllSF'ORtlATIOil RULES

    The Mortr.n3 proce •• or •• Y b. r.gerd.d e. a dev;c. that aoo.pt. end .,.11 •• transform.tion rul.s.

    • A rule .ay be defin.d at eny point in _ progra •• • A rule applies to ell progr .. text after It Is deflnad •• • A rule May d.fine one or .or. rul.s. (Definitions "V be ne.t.d.)

    To define e rule. the progr .... r writes:

    • The keyword. REPLACE and WITH are intended •• a con.tant r .. inder that a rule defines a substitutive function.'

    • T •• p/.t. de.cribes a user-defined not.tion. • Value comp ... i •• s text (and'or _ p ..... cription constructing text)

    that will be substituted for the user-d.fined not.tion • • The broc •• era deli.iter ••

    7.1 !HE IlnpLEST IXanpLI.

    In the .impl •• t type of rule. both the te.plete pa ... t end the value part er • •• de up of liter.' _N.bo/_ (sy.bols that denote th .. selv.s). Thi. type of ... ule merely substitutes one symbol-string for another symbol-string.

    Examp 1. (7-1 )1 .... ___ R_E_'_L A_C_E_(_S_I_Z_E_l_W_I_T_H_(_2_2_1 ___ ... Rule (7-') would transform all occu ... rances of (say):

    into DIMENSION ACSIZE) DIMENSION A(22)

    Rules like (7-/) ar •• by themselv.s, of limited usefuln.ss.'

    The user may d.fin .... ul.s of considerable pow .... and flexibility by including broced quantities within the t .. plat •• nd value parts. If braced quantities are included in the template and valu. parts the braces Must be balanc.d. ju.t .s perenth ••• s Must be balanced in FORTRAN .xp .... s.ion ••

    6 The scope ·of ... ule application may be r.stricted by the progr ....... (Se. Section 'The Scop. of Rules' below.)

    7 A function that is ev.luated by substitution as oppos.d to tran.f .... of ~ control. Se. "Mortran3 Raf.renc. Manual". appendix E fo ... a FORTRAN analogy.

    • They may be used like FORTRAN 77's PARAMETER statement.

    A.James Cook - 32 - D.c.mb .... 16. 1982

  • "ortren3 Us.r's Guid. - 33 - CGTM 209

    Irae ........ tltl .. t. Mil .... flaltlo ...... t. f ... tl •• ,..f.,. ......

    .• 1ft the t .... pl.t. pert they denote reo ... ltt •• functions. • 1ft the value part they denote eval.atl.. functions.

    7. Z IB TAtPLUE UBI

    A template comprises literal ,ymbols and, optionally, braced quantities. • TeMplate ... st contain literal .~.Is. • Templates"y cont.in .ra.ed .. a"tltl •••

    The ne.e wlthl. the braces is the n ... of a r.o •• _ltl •• function. Th. na.. and the braces co.prlse a par .. eter .arker.

    7.2.'

    A par ••• tar .. rker .ay b. thought of .s a "place holder":

    template (7-Z)I~ _______ TH_I_S __ {_W_O_R_D_) __ IS __ F_A_L_S_E_. ______ ~ T.mplat. (7-2) i •• ad. up of:

    • Lit.ral symbols: "THIS IS FALSE." • • A parameter .arker: (WORD) • A speolfler: WORD

    A specifier is the .... of • function. Must b •• et by an aotual paraMeter.

    Th. function specifi.s criteria that

    Assume that WORD has b.en sp.cified (described below) .s:

    "a contiguous string of upper-case letters"

    Then, (7-Z) would match ITHIS SENTENCE IS FALSE. I; par ... t.r. "SENTENCE".

    A.J.m •• Cook

    • A template may contain up to 35 paramater Markers.

    • The parameter markers In a template are "positional". That 15, thev are nUMbered (bV Mortran) fro. the left, starting with on8.

    - 33 - December 16, 1982

  • . Mortran3 U •• r'. Guid. - 3. -

    t •• plat. (7-3)1 .. __ (_lW_O_R_D_J_._lW_O_R_D_J_l __

    T •• plat. (1-3) has t.o par ... ter •• rkers. loth par ... ter .. rkers .re deftotad by (WORD).

    (7-3) would •• tch: (THIS. THAT)

    'st actual par .. eter is "THIS" 2nd actual par ... t.r is "THAT"

    T.-plate (7-3) would also .atch: • (A .11> • (AHTIDISESTABLISHMEHTARIAHISM.DIALECTICAlMATERIALISM)

    Template (7-3) would •• t .etch: • (3.14) because 3 is not a word. • (A.EQ.I) becaus. EQ.I is not a word.

    Ona "tells Mo~tran" how to "recognize" a parameter by .e.ns of the SPECIFY .tatement. which i. described in the next s.ction.

    A.James Cook - 311 - December 16, 1982

  • "ortran3 U •• r's Guid. - 35 - COT" 2D9

    ~.2.2 'patfl.t.

    A .~c;';e~ I. the no •• of. reco.nl#ion function. by • SPECIfY .tat ... nt:

    The function t. d.fin.d

    • A sp.cification i •• boel ••• function. (I) A .p.cification I ... t Dr It i ••• t-.. t. (Z) A sp.cificatton cOMpri ••• :

    Ca) Sp.cifi ...... (b) PrJ.ittv •• p.cifi.r •• ee) PrJ.ltt ••• p.cifications.

    I) Sp.cifi.rs are us.r-d.fin.d. 2) PrJ.ltl •• , ar •• yst.m-d.fin.d.

    • A sp.cifl .... I. ,atlafl.d If it. sp.cificatton I ••• t.

    Example:

    ExaMple:

    A t •• pl.t. will •• t .. tch a •• gm.nt of t.xt unl ••• all of its sp.cifi.r. ar. satisfl.d.

    SPECIFY HEXDIGIT AS (D~ .. F);

    • Thi. SPECIFY .tat.m.nt d.fin.s the sp.cifi .... HEXDIGIT. • HEXDIGIT would b. satisfi.d by on. of the symbols 0 through F.

    HEXDIGIT would not b. satisfi.d by anv oth.r symbol. • Th. paraM.t.r •• rk.r (HEXDIGIT) would "m.tch" a sing1. digit.

    The pa ...... t ..... ark.r (HEXDIGIT) would not " ... tch" any other symbol •

    • (D ••• F) 'S en .xempl. of • prieifive sp.cification.

    SPECIFY LCASE AS ( •••. z):

    • This sp.cify statem.nt d.fin.s the sp.cifi.r LeASE. which would b. s.tisfi.d by on. low9r-cas. l.tt.r.

    • The sp.cification part of this sp.cify stat.m.nt is an .xampl. of a primitive sp.cification, nam.ly, a quali'ier.

    Th ..... ara a number of prt_Ittva (system us.ful ones ..... LETTER, DIGIT. and ALPHA; as follows:

    defined) specifiers. Thr •• very Th.y ara pr.d.fin.d by the syst.m

    A.James Cook - 35 - D.c.mber 16, 1982

  • Mortran3'User's Cuid. - 36 - CGTM 209

    • (7-.) b

    e

    ,

    SPECIFY LETTER AS (A ••• Z); 'SPECIFY DIGIT AS (O ••• S)J SPECIFY ALPHA AS [LETTERIDICIT];

    Hotice that (7-f)-c Is specified In ter.s of other specifiers. n .. ely LETTER and DIGIT. LETTER and DIGIT comprise a li.t of two alternativ... ALPHA is s.tisfied if .Ither LETTER or DIGIT I ••• ti.fied. The .YMbol "I" i. the "alternation sYMbol". The square bracket. deli.it the li.t of two altern.tives. (In general. the nUMber of alternatives in a li.t is arbitrary.)

    Square brackets also deliMit entities that are quantiFied.

    Ex.mple:

    Example:

    SPECIFY FNA"E AS LETTER(O.5)[ALPHA];

    • The specific.tion p.rt cont.ins • quantiFi.r. a) The entity being quantified i. enclosed in square brack.t •• b) The qu.ntifier i. enclosed In parenthe •• s.

    • The quantifier May be read .) ".t le •• t zero. but not Mor. than five" or b) "optionally at Most five".

    • fHAME would be s.tisfied by • letter followed. optionally. by at .ost 5 letters or digits.

    • fHAME would b ••• ti.fied by •• tand.rd FORTRAN v.ri.ble n ••••

    SPECIFY THING AS 'T'(Z)[LETTERIDIGIT];

    • THING would be satisfied by the letter T followed by exactly two symbol •.

    • E.ch of the symbols •• y be either a letter or a digit. • The specification p.rt in this example comprises

    a) the lit.r.l 'T'. b) two specifiers LETTER .nd DIGIT. c) one quantifier. (Z) d) a list comprising two alternativ ••• [LETTERIDIGITl.

    A.James Cook - 35 - Decembar 16. 1982

  • "ortran3 User'. Guide - 37 - CGTM 209 .

    7.2.1.1 Forward refer •• o •• t • .,eolfloatlens

    Forward referenc •• are per~itted In sptteiflcatlons. For ex_pl •• I

    SPECIFY _UADRUPED AS '.)[LEG]; (7-5)

    SPECIFY ~EG AS [ 'LIMB 'I 'EXTREMITY']; 1 I

    In (7-5) LEG ,a referred toi before· it is defined. LEG i •• for_ord r.t.r.nc ••

    Forward references May incr~as.the comput.tion done during tr.nsfor .. tlons.

    It should also be pointed I~ut that QUADRUPED wi 11 be •• t isf ted by .ny of 16 (=2') possible .rr.n9 .... nt.1 of LIMB and EXTREMITY.

    If we write "L" for "LIMai .. and "E " for "EXTRE"ITY ". then the following arreng_ents would sattsfy !the specifier 'UADRUPED.

    L L L L , L L L E , L L E L , L LEE , L ELL • L E L E , LEE L , LEE E , ELL l, ELL E , E L E L , E LEE , EEL L , EEL E , E EEL , E E E E

    There are two ways that a ~.cification .ay be .ad. "optional".

    ..

    -b

    -~

    SPECI~ APPEHDAGE AS ['TAIl'I"],

    SPECIFY APPENDAGE AS (O,I)['TAIL'];

    Both (7-6)-. and (7-6)-b :specify that APPENDAGE is "optional". In words, the text "TAIL" iwtl1 •• ti.fy the the specifier APPENDAGE. APPENDAGE will be •• ti.fie~ whether or not the text "TAIL" is present.

    • If "TAIL" is presentl, It becomes the actual arsu •• nt. • If "TAIL" is ab.ent, thD actual argument is NULL.

    "ore about this in the sub~ction 'HULL P.ra •• tars· below.

    other but

    A.J .... s Cook - 37 - Decemb.r 16, 1982

  • Mortran3 Us.r's Guide - 38 -

    The value part cOMpris •• eny or all of the followin.,

    • Literal sYMbols • Strings • Braced quantities • Evaluation-ti.a IF-THEN-ELSEs.

    Braced quantities (not In .trlngs) always denote faRotto. refereao... The simplest of tha function ~af.~enc ••• ~. the poro •• t.r r.f.r.nc •••

    7.3. t par..,t.r '.f.r ..... A parameter reference is • primitive function that ~.f.~s to en actuol e~gu •• nt. The first of the.a i. denoted by:

    (Pn)

    I $ n $ 35

    The pri.itive function Invoked by (Pn) ~eturns actual argu.ent n.

    • n is the parametar reference nUMber • n corresponds to tha ralative position (from the laft)

    of the parameter .ark.r.

    • The number of parameter markers may not exceed 35, but any number of parameter references May appaar in the value part.

    • The parameter, referance number n may not exceed the number of parameter .arkers. (If it doe. the error .as5aga "NO SUCH ARGUMENT IN TEMPLATE" will result.)

    Other primitives that refer to actual parameters are:

    I (7-7) 2

    J

    (LENGTH n) (EXIST n) {NUll nJ

    • (7-7)-1 returns the length of actual argument n. • (7-7)-2 end -3 refar the "exi5tance" or "non-existance" of

    tNt nth actual argument.

    Briefly, the parameter "exists" if its length is greater than zero, and is ~ "null" if its length is aqual to zaro. But sa. tha section "HULL Paramatars" below.

    A.James Cook - 38 - Decembar 16, 1982

  • MortranJ Us.r's Guid. - 31 -

    7.".1.1 Lett-to-rt.ht Subatltutt ••

    Hor.ally. the value part of a rule is substituted for the t •• pl.t. pert on _ strict left-to-right (L-R) basis.

    (7-8) REPLACE «(LETTER).(LETTER») WITH ( (P/)(/). (P2)(I)

    + (P')(Z)* (P2)(2) + (PI)(3). (P2)(3)

    )

    • The template part of rule (7-8) contains two par .. eter .arkers.

    • The value part of rul. (7-8) contains six parameter references. Three of th •• refer to the first .ctuel per ... ter. Thre. of the. refer to the second actual par ... ter.

    Application of (7-8) to the

    program taxt (A.B)

    produce. A(I)*B(/) + A(2)*1(2) + A(3)*B(3)

    Since (7-8) contains only literel symbols, parameter .erkers, end per .. eter referances, application of (7-8) involve. the following .teps:

    I. The template part matches the text (A.B).

    2. The parameters A and I .re sav.d and the text "(A. B)" is deleted.

    3. aeginning at the point where the text "(A.B)" was deleted, the value pert is substituted. The substitution proceeds left-to-right end symbol-by-symbol -unt i 1 • par .. eter reference is encountered.

    4. The actual par .. eter r.fe~r.d to is inserted at the reference point.

    5. Left-to-right substitution re.umes until the next par .. eter reference is encountered.

    Upon completion of the substitution, the newly substituted text is ,..-scanned to deta,..ina whethe,. other rul ••• ey be applied to it.

    Simple l.ft-to-right substitution •• y be altered by the programMer through the use of priMitive evaluation functions and ev.luation-ti •• IF-ELSEs described below.

    A.J .. es Cook - 39 - necember 16, 1982

  • "ortran3 Usar's Guida - liD - CGT" 209

    7.3.1.2

    The pr09,._e,. .. y def ine notat ions who.e per .. eter. are de.or'lbed in con.lderable datail by .ean. of SPECIFY .tat .. ants.

    In pa .. ticula .. , ha •• y specify that. par .. ater is "optional". ways he May do this is illustrated in the following ex_pie:

    a-

    (7-9) b-

    c-

    SPECIFY IIPED' AS

    SPECIFY APPENDAGE AS

    SPECIFY APPENDAGE AS

    (2') [ LEG ];

    (O,I)[TAIL];

    [TAIL I' 'J;

    One of the

    loth (7-9)-b and (7-9)-c .pecifV that APPENDAGE is "optional". (7-9)-a specifies that BIPED requir.~ exactly 2 occurrences of LEG. How conside .. the template fragmant:

    ••• (8IPED)(APPENDAGE) •••

    If the spectfier BIPED Is satisfied, end tha " ••• " parts are satisfied. then the t .. plat. matches regardle •• of whether or not the specifie .. TAIL is sat i sf ied. In oth.r words, tha spaci f ,ar APPEHDAG,E wi 11 always b •• at i.f iad.

    If a specifier has been defined .5 optional, than:

    • The aotaal perameta.. EXISTS if it cont.ins .t le.st one symbol •

    • The aotual parameter i. NULL if it contains no symbol ••

    (NULL. do •• not EXIST. contains no symbols.)

    Now~ in the vo/u. part of. rule. the programme.. May well want to know whether the BIPED has a tailor not. and to take action accordingly. The programmer may test for th •• xistane. af ~ p.~.motlr thlt hli blln d.cllrld optional. More about this following the evaluation-time IF-ELSE.

    A.James Cook - 110 - December 16. 1982

  • - ., -

    5i_pl. left-to-right .ub.tltution .ay be altered by:

    • Evaluation function r.f.r.nc ••• • !valuatfon-tf •• If-THEH-ElSEs.

    7.11 "'"'TIVE ['N.D'!I. FllCTIOII

    A prl.tttv. evaluatton function reference is denoted by:

    • NAnE i. the n .. e of the function and • orgu .. nt ts •• V-bol-string.

    The QrfU-&nt .f en eveluetton function --v contain r functton references. In other words. function r.f.r.nc .... y b. _ .sted. N •• t.d pri_itiy. raf.rences (.xcepttng par .. etar refer.nc.~) ~ev.lu.t.d frOM the inn.n.ost outward. _~ -

    7 .... t l.tsIK 21 ., .... \1.. . ... ,' "

    Let p", end R denote prJ_fti". function neme., end l.t en ellipsis denote en arbitrary symbol-string.

    (7-'O)I~_. ____ (P_._._._{_' __ •• _._{_R __ ._ •• _) __ ._._.) __ ._._._) __ ~ In (7-10), the pri.itive R is evaluated fir.t. The argu.ent· of' then includes the symbol-string resulting from R's evaluation, and so on until P is evaluated. (Each evaluation results in the removal of the n ... and delimiting brace. of the function.)

    let upper-case latters denote the names of primitive functions. lower-case letters denote symbol-strings, and boldface letter. denote evaluated symbol-string ••

    Then, CP abCt cd(R af) gh) I j) {P abe, cdefgh} tj} (P eboclef.hij)

    uodef",tJ

    fs evalueted ., follow,. Cafter R i. applied.) (after Q is appl ied.·) Cafter P is applied.)

    A.James Cook - III - December 16, 1982

  • Mortran3 Us.r's Guid. - liZ -

    7 ••• 2 IbI BIDUCE prtwdsty.

    Fir.t, w. Illu.trat. with. Gentriv.d .xeMpl. involving 3 rul •••

    (7-11)-. -b -c

    REPLACE (xxx) WITH (In3) REPLACE (n) WITH (2) REPLACE (/Z3) WITH (OHE,TWO,THREE!)

    Rul.s (7-11) will transfor. "xxx" transformed into "ONE, TWO, THREE!". following steps:

    into "123", Rul.s (7-11)

    but wi 11

    I) "xxx" I) "n"

    Is r.plac.d by "/n3" by (7-II)-a. t. r.plac.d by "2" by (7-11)-b.

    "123" will .. t b. b. appll.d 1ft the

    As point.d out In s.ction "L-R Substitution" aboye, the substituted t.xt is "r.-scanned" to det.rMin. whether other rul.s .. y be·.ppli.d. But the t.xt is re-.cann.d from the point .t which the last SUbstitution was .ad.. In this .x .... pl., "123" will not be •• tchecl b.eaus. the r.-scen b.glns.t "23" aft.r (7-II)-b is eppli.d. . ~ can Fore. the application of (7-")-c by r.-writing.(7-11)-a to invoke RE~CE:

    (7-")-a-REV REPLACE (xxx) WITH (REDUCE(ln3»

    Then, "xxx" will b. transformed into "ONE.TWD.THREE!" ift the foll.wlng st.ps: I) "xxx" t.s r.no.d to" I n3" by (7-11) -a-REY • 2) "n" is reducld to "2" by (7-11)-b. 3) "123" is r.duold to "ONE,TWO,THREE!" by (7-II)-c. 4) "xxx" is r.plaold by "ONE, TWO, THREE!"

    7.1I.2.t REDUCED t.xt vs. REPLACED t.xt.

    Th. distinction b.tw •• n ~.duo.d and replaced is an important on ••

    REDUCE raseans 011 of it. argument until all rules haYe b.en appli.d to the argument. Wh.n no further reduction is possible, the red.oed string ~.pl.o.s the aatch.d string.

    If the argument of REDUCE inn.rmost is re-scanned ref.rences in FORTRAH.)

    conteins other first. (This

    inyocations of is not unlike

    REDUCE then the nested FUNCTION

    A.James Cook - 112 - December 16, 1982

  • - "3 -

    REDUCE is automatically Invoked by the COMPUTE priMitive.

    7 ••• 3 Iba conpUTE prt.,I'y.

    Again, the contrived introductory example:

    (7-12)-a -b -c

    REPLACE (TWO) WITH (2) REPLACE (SIX) WITH (6) REPLACE (APE) ~ITH «CO",UTE 3*(TWO+SIX) »

    Rules (7-IZ) will trensfon. "APE" into "211" in the following at.ps: I) TWO i. reduoed to 2 by (7-12)-8. 2) SIX i. r.d8 •• d to 6 by (7-12)-b. 3) The .... t_t .x, ........ "3*(2+6)" is •• al •• ted. 4) The value t. converted to the two char.cters ·2" .nd "II". 5) The text "2"" r.~I .... the text "APE".

    • COMPUTE returns the val •• expressed as a dl.lt-.t~t ••. • CO"PUTE's .r ..... t Must b. reducible to • oonst •• t express'o ••

    (IF it is not r.ducibl •• various .rror ••••• g •• will result)

    7 ••• 3.1 Co.sta.t .xpress'ons

    Constant expressions cOMprise I.t •• er ooftstants and ope ... tors.

    An expression like: could reduce to (say): and then to (say):

    DOGS > CATS POODLES+CORGIES > SIAMESE+AllEY

    5+7 > 2+32768 this last ;s a constant expression.

    Constant expressions are either Int ••• r expressions or 10.Ioa. expressions.

    A oonstant expression oo.,rt •• s: Integer constant, (contiguous digit-,trins,) Arithmetic operators (+.-.*.'.**) Relationel oper.tors ( )

    or (LT. LE, EQ. NE. GE. GT Logicill operators ( AND , OR , HOT )

    or ( t; , I • ) Parentheses

    (The FORTRAN operators .AND., .EQ., .HE., ate. ara HOT acceptable in this context.)

    )

    A.James Cook - "3 - December 16, 1982

  • "ortr.n3 U.er's Guide - tt -.

    7 ••• a.z Con.tant LOlloal Expres.'o"

    For constent lo.lcGI expre •• ion. COMPUTE returns: the digit I (TRUE) or the digit 0 (FALSE)

    A.au_ing rules (7-IZ)-. and (7-IZ)-b .boye.

    (COMPUTE TWO LT SIX ) r.turns I (COMPUTE TWO < SIX ) r.turns I (COMPUTE TWO Ect SIX ) returns D

    (COMPUTE TWO*SIX+S > 3D-TWO ) r.turns 0

    (TRUE) (TRUE) (FALSE) (FALSE)

    (COMPUTE TWO*SEX+CS > JD-TWO ) ' •• ues error ...... If "SEX" I. not reducible. Returns o.

    An arithmetic expression that evaluates to zero is .ot distinluishable fro. a 10lical. expression that eyaluet.s to FALSE. Therefore, it Is possible (but not adyisable) to perforM arithmetic operations on logical .xpresslons.

    A.James Cook - qf - December 16, 1982

  • "ortran3 U •• r's Guide - '15 -

    7.... I!.'gatlen-SI., IF-EL'E

    [IF] [ELSE]

    prfHIicat. i • (I (Z (3 (of

    [true-port] ['.'.e-part]

    • con.tant expression.' • .tring .xp ...... lon the pri.itive EXIST the pri.itive HULL

    true-part and rol •• -port ar •• vmbol strings •

    The IF-ELSE In a p ... ograllll.tng language control. the order of executton of the st.tements in a progr ...

    This .voluofion fi •• [IF]-[ElSE] controls the substitution of sv-bol-strings. ~ This [IF1-[ElSEl should b. r.garded as a function that r.turns the

    syMbol-string ro/ •• -parf if pr.dicot. is FALSE. and the sYMbol-string true-port otherwise.

    • Evaluation-ti.e [IF]-[ELSE]'s .av be nested.

    , ~re preCisely, it is an exression that must b. r~ducibl. to a constant expression. (See subsection 'Constant Expressions'.)

    A.James Cook - 115 - December 16, 1982

  • "o~tr.ft3 U.a~'. Gutde - 116 -

    7 ••••• 1 atrlRi Expr ••• 'o.s

    String expressions involve two types of atrings;

    I) Literals enclosed in apo.trophe. (like 'THIS'). 2) P.r ... ter •• rkers .nclosed In apost~oph.s (like t{P3)t).

    A per_etar to a string.

    reference enclosed in apostrophes convarts the String expression. are written:

    St relation Sz

    • $1 ... t be a .tring

    • $z .. y be (I •• tring. or (2 •• pecifier

    • rel.tion is I) the symbol "=" 2) the sy.bol "~"

    If SI i. not a .tring. unpredictable error. will result. If Sz ts not a .tring. it is assmumed to be • spacifier.

    In .ummary, string expressions May contain

    • Strings - Literals - Parameter references

    • Specifiers

    If both arguments ar. strings. the .trings .r. compared.

    If the first .rgument is • string and the then if the string satisfies the specifier TRUE is returned.

    second argument is and if the relation

    • specifier. is 'a' then

    Undefined specifiers in string expressions re.ult in an error ••••• g. and. v.lue of FALSE for the predic.te.

    The following are valid string expressions involving strings only:

    '(PI)'='{P3)' TRUE when parameter I i. identical to par_eter 3 • • {PI} '-' (P3)' FALSE when parameter I is identical to par_atar 3. '{PI)':'THIS' TRUE when parameter I is the literal THIS. 'THIS':'CPI1' TRUE when paramater I is t ha Ii tara1 THIS. '(PI)'-'THIS' TRUE when parameter I is not the 1 iteral THIS.

    A.Jame. Cook - 46 - December 16, 1982

  • "ortranJ User's Guide - '17 -

    The followins strinv axprasslons Involva • string and. spaciffer:

    ',PI)'.FHA"E '{PI)'-fNSME

    TRUE when par .. etar I .ati.fia. the spaclffer FN~E. issu.s en .rror .e.eg. if fHSnE he. not baen dafinad in a SPECIFY stat ... nt and raturn. FALSE.

    7 .•. ".2 The prl.ltlv •• lULL and EXIST

    Actual par .. atars May ba NUll (cont.in no 'YMbols). Thi. can happen whan a specifier has baan defined e5 optional. (S.a subsectton NULL 'ar ••• ters.) The pr;'aitiva. EXIST .nd HUll .ay b. used to d.ter.ina the status of actual arguMents.

    (EXIST n) (NULL n)

    n refe,.. to the nth actual par .... eter

    (EXIST n) rat urns TRUE if .ctu.l arguM.nt n is not .null. (EXIST n) returns FALSE if actual argument n is null.

    (NULL n) ret"rn. TRUE if actual argument n is null. (HULL n) returns FALSE if ectual argument n is not null.

    These primitives ere especially useful in evaluation time IF-ELSE predicates.

    A.James Cook - f7 - Dece.ber 16, 1982

  • Mo~t~.nJ Use~'s Guide - 118 -

    7.~ RECURlIVE APPLICATI'N IE ~.

    A rule •• y be evelueted recurstvely. no_ of the rule appears In the valu. illustrations:

    Direct" recursion re.ult. when the part of the rule. W. give two

    • The first illustrates the transfor •• tion of. function.l notation for f.ctori.l into .n expr •• sion.

    firat, we transform the notationl into the notetion:

    !d (where d i •• digit) d*(d-I)*(d-Z)· ••• ·(I)

    (7-13) REPLACE (!(DIGIT»

    WITH ([If] (PI»I [ (PI) • ! (COMPUTE (PI)-I) ]

    [ELSEl [ 1 ] )

    Rule (7-13) will transform: into:

    in tNt following steps:

    !II 11*3*2*1

    First step: Second step: Third step: fourth step:

    !f is ~eplaced by "*!3 !3 is replaced by 3*!Z !2 is replaced by 2*!1 II is replaced by 1

    • Rule (7-13) is not intended to be useful; It is intended to be • simple illustration of recursive application of a rule •

    • The name (I) app.ars in the value part of (7-13) with a new argu •• nt. to wit: !{COMPUTE {PI}-I}.

    • When (PI}=I, the predicate returns FALSE, substituted, preventing further recursion.

    and the the digit wlw is

    10 Indirect recursion can also take place when two or more rules "invoke" one another.

    A.James Cook - 1/8 - December 16, 1982

  • - 49 - CeT" 209

    In the •• cond eXaMple. the factori.l I. co.puted by n •• t~ Invocations of CO"UTE:

    RErLACE (I(DIGIT» (7-111) WITH ([IF] (PI»I [(CDI'IPUTE (PI)*'(CO"PUTE (PI)-I) ) ]

    [ELSE] [I] )

    Rule (7-111) will tr.nsfo~ !5 into 'ZD as follows:

    !5 i ... educed, (CO~UTE 5*!4) (nest level-')

    !/I i. reduced: (CO"PUTE 5*(COftPUTE "*!3» (leval-Z)

    !3 is ... duced: (COMPUTE 5*(CO"PUTE "*(COnFUTE 3*!2» (lavel a 3)

    !2 is .. educed: (CO"PUTE5*{COMPUTE "*(CO"PUTE 3*(CO"PUTE Z*{C~PUTE !I)))) (leval:lI)

    Now. b.cau •• the .rgu •• nt of !I I. not gr •• t ... then I. ...cu .. sion .tops and 1 is substituted. The nest is then evaluated fro. the inn .... ost outw ... d:

    (COMPUTE S*(COMPUTE f*{CO"PUTE 3*(CO"PUTE 2*1»)) (C~PUTE 5*(COMPUTE ".(COMPUTE 3*2»)) (COMPUTE S*(COMPUTE •• 5)} (CO~UTE 5*2.) 120

    When comput.tion i. cOMplata (laval=O).~epl.o. the text "!5" with "120".

    If the ELSE p ... t of (7-'/1) is ... moved, !5 will Bot retu .. n 120 8S ona .ight exp.ct. it will ... tu .. n D. end COMPUTE will issue the ..... or •• ss.,es:

    *WARNING INVALID C-EXPRESSION .STRANGE (2.)·

    Rul. (7-14) (without the ELSE p ... t) attempts to compute: (5*("*(3*(2*»»

    which is ••• ningl.s5. Rath ... than abandon the rule. it issues er .. or .essages and COMput.S:

    (5*(f*(3*0») which .ay not be what was intended. Thus. the ELSE part of (7-1.) serves a purpose othe .. then •• suring the cor .. ect value for argument. of! thet are I ••• than ... equal to ze .. o.

    A.James Cook - 119 - December 16. 1982

  • Mortran3"U •• r'. Guida - 50 - CGTM Z09

    7.:1.1 'IIMn'" hoynl.ol An iMproperly defin.d rule can rapidly fill ftortren'. workspece or w..t. tim. in infinite recursion.

    Space-filling example (7-IS) RErLACE(A)WITH(AA)

    Rule (7-15) will replace the first "A"· encountered in the input text with "AA". and ·then ,..placo tho fi,..t "A" of "AA" with "AA" resulting in "AAA", and so on until the remaining workspace is filled. Then Mortran will issue the •• ssage ""DRTRAN WORKSPACE EXHAUSTED", and stop.

    For those cases where one actually wants this type of rule, on. should use the pri.ifiv. EMIT (5 •• appendix A). In the case cited· above, on. should wr ite:

    REPLACE (A) WITH ((EMIT AA»

    Ti •• -wasting exa.ple (7-'G) REPLACE(A)WITH(A)

    Exampl. (7-16) will repeatedly repla.ce "A" with "A" until the replac •• ent li.it (default 100) is reached. Then Mortran will issue the error •• s.ag. "100 RULES EVALUATED WITH NO OUTPUT", and turn on TRACE. TRACE i. turned on so that the user may find the unwanted recursion without re-sub.itting the job. (S.a appendix A for a description of TRACE.)

    A.Jame. Cook - 50 - Dec.mb.r 16, 1982

  • "ortranJ User's Guide - 51 -..

    7. & DIE ICOPI: I[ lULl'

    A rule is ,lobal" to the text followiftg It. d.finitioft unle •• the .eope ,. restricted by the proc.ssor dtrectt,ve. t2 lLDCAL .nd lEND LOCAL.

    The !LOCAL .directive (in effect) _rks .11 .ubsequent rules •• "t_por.ry". The !END LOCAL directive del.te •• 11 "teMpOrary" rules, end recoyers the SplIC. they occupied.

    This f.ature is us.ful in • nUMber of ways, .. ong t~:

    • Rules •• y defined that apply only within _ SUBROUTINE or FUNCTION subprogrM.

    • Because rule definition ... v be ne.ted, the cre.tlon .nd eli.in.tion of rul.s thet "liy." only to carry out so.e teMpor.ry need Is facilitat.d.

    • In the cu ..... ftt v.rs,ion !LOCAL directiv ••• ey no# be ne.ted. (This will be corrected in the next Yersion.)

    't Appli.s .v.rywh ..... t2 See appendix D for. list of directives.

    A.J .... Cook - 51 - D.cember 16, 1982

  • - 52 -

    7.7 BEno,11I ~ III .rECIFIEBS

    Ther. ere two ways of re.ovin, Rules end Specifierst I) By defining thaM within _ LOCAL range as described .boye. Z) By the .tete.ents:

    REMOVE RULE 'f •• plat.' REMOYE SPECIFIER t.p.ciFi.r t

    The recovery of the .pace left by REMOVEd rule. or specifiers is .uto •• tic in the LOCAL case~ but Is not automatic for explicit RE"OYE stat •• ents. Th. user can force the recovery of "dead" space by the directive !RECOVER. In either ca5e, the recovery proc.dure prints the following:

    nnn LOCATIONS RECAINED IY RECOVERY mmm LOCATIONS REMAINING pp PERCENT RULE CAPACITY REMAINING

    Recovary is also auto.atically invoked whenever the Rul. and Specifier storage spece is exhausted.

    A.James Cook - 52 - December 16~ 1982

  • "ortran3 User's Guide - 53 -

    7.8 IITERlIL cpulTEll

    The~. a~. 35 u •• ~-acc •••• bl. counter •• 1 ••• 9 • • nd A ••• Z.

    Each of the •• count.rs can hold on. int .. er.

    The user IMV ecc •• s the •• count.rs with t .... following prl.itt".s:

    (IHCRc) (DEeR c) (SETR c=.) (COpy c) (COpy c BASE b)

    incr_ent c.unte~ c. c a (I ••• 9.A •.• Z) . decr ... nt counter c. c-(I ••• 9,A ••• Z) set counter c to the valu. of .xpr.ssion e. returns v.lu. of c ( .... 10) ••• digit string. returns value of c (bes. b) as. digit string.

    CITM 109

    The expression e Must· be reduclbl. to a constant int.ge~ .xpr.s.ion. A simple example will Illustrate the use. of COPY.

    ( 7-'7)

    SPECIfY N~ AS (',a)[DIGIT];

    REPLACE (SHOW DIGITS 1M (All) lASE 'MUM» WITH ( (SETR Aa'p,)]

    DIGITS OF (P') lASE 10 ARE: 'COpy A ]; DIGITS OF (PI) lASE (P2) ARE: (COpy A lASE (PZ»J

    )

    Example. of the application of (7-'7) follow:

    The text: yi.ld.: yields:

    The text: yields: yields:

    The text: yields: yi.ld.:

    The text: yields: yields:

    The text: yield.: yields:

    SHOW DIGITS IN 2**8-1 BASE Zi DIGITS OF 2**8-1 BASE 10 ARE: 255 DIGITS OF Z •• B-I lASe 2 ARE: III"'"

    SHOW DIGITS IN ' •• 3-1 BASE Bi DIGITS OF ' •• 3-' BASE 10 ARE: 511 DIGITS OF 8 •• 3-' BASE BARE: 777

    SHOW DIGITS IN 8 •• '-1 BASE '6; DIGITS OF 8**4-1 BASE 10 AREt 409S DIGITS DF 8**t-1 lASE 16 ARE: FFF

    SHOW DIGITS IN 8*9'2+4 lASE 36; DIGITS OF '.912+4 lASE 10 ARE: fa DIGITS OF .*9~2 •• • ASl: 36 ARE: III

    SHOW DIGITS IN 220 BASE 22; DIGITS OF 220 BASE 10 ARE: 220 DIGITS OF 220 lASE Z2 ARE: AD

    A.James Cook - 53 - Daca.bar 16, 1982

  • MortranJ U.er l • Guide - 511 -

    7.' lHE LENGTH ,II"IIIIE

    The LENGTH pri.itive I. written

    (LENGTH r)

    A per ... ter reference number i. a nu.ber ba.e 35 denoted by I thr.ugh Z. If there are fewer than r p.r .. eter .ark.r., the error.es.ege

    NOSUCH AIG. IN TE~LATE Of RULE

    will result.

    Wa give three examples of Its use:

    SPECIFY WORD AS (1,11)[LETTER1.

    REPLACE (COUHT(WORD» WITH ((PI) HAS (LENGTH I) LETTERS)

    The text: COUNT THIS yields: THIS HAS f LETTERS

    The text: COUNT BALDERDASH yield.: BALDERDASH HAS 10 LETTERS

    Th •• econd example illu.trates it. usa in _ hypothetical naMing convention. to wi t:

    I. Scalars are denoted by two-letter name. Z. Vectors are denoted by three-letter n.mes 3. Matrices are denoted by four-letter names

    Now suppose one wants to tran.form I no.. I into FORTRAN FUNCTION call. according to this convention.

    Example: yields:

    SPECIFY NAME AS (/,II)[LETTER]

    REPLACE (I (NAME) I) WITH { [IF] (LENGTH I}=Z [ AaS({PI}) 1

    }

    (IF] (LENGTH I}:J [ LENGTHC{P/}) J [IF] (LENGTH I) •• [ DETER"C(P/» 1

    I*rxxl + J*IVyyl + K*lzzzzl I*ABS(XX) + J*lENGTHCYYY) + K*DETRM(ZZZZ)

    A.James Cook - 511 - December 16, '982

  • Mortran3 U •• r'. Guida - 55 - CIT" 209

    The third example Is an extension of the COpy example frOM the pr.vious chapter.

    SPECIFY NU" AS (1 •• )[DIGIT1J

    REPLACE (SIZE«(ARI)) WITH ( (LEHGTH I) )

    REPLACE (SHOW DIGITS IN (H~) lASE (MU"») WITH ( (SETR Ac{P'»

    )

    THE SIZE«COPY A lASE ('2») DIGITS OF (PI)e(PZ» ARE: (COpy A lASE {P2)

    The text: SHOW DIGITS IN 255 lASE 2 yields: THE 8 DIGITS OF 255(2) ARE: 111"'11

    The text: SHOW DIGITS IN 511 lASE 8 yields: THE 3 DIGITS OF 511(S) ARE: 777

    The point of this example is that the ancillary rule SIZE is necess.ry because the .rgu .... nt of LENGTH Is • porll •• t.r r.'.r.ncfl nu.b.r. In other words an in.tance of the te.plate SIZE((ARI» .ust be recognized in order to deterMina the l.ngth of it. argu •• nt.

    A.James Cook - 55 - December 16. 1982

  • - 56 -

    ~. tl APPAlDI", !III-

    Text .ay b. appended to the value part of an existing rule. for •• :

    ( 7-1.' )1 ... __ A_P_P_E_N_D_{v_tl_' "_._)_T_O_{_,_._a_p_, 11_#._) __ .... and

    (7-19)~I ____ A_P_P_E_N_D __ ._V_II_,_,,_._. __ T_O __ ·_'_._._P_,_o_t_._. ____ ~

    There are two

    Th. two forms differ in one respect only: the latter preserves ALL blanks in its f.aplot. part.

    APPEND can produce two effects:

    I) It can append va'u. to the value part of a previously defined rule whose template part is identical to ' •• pltl' ••

    2) It can define a new rule if no rule with a t.-plate identical to f •• plaf. exist. In other words. it defaults to:

    NOTE: In searching for a rule with teMplate identical to f •• plat., the entire template (including parametar markers) ;s compared. as opposed to nor.al rule aplieation. In other words. in this case parameter .arkers are treated as if they were literals.

    "For exampl •• consider the following:

    (7-20) I 2

    APPEND ( FOUR ) TO (LINCOLN) APPEND (SCORE AND SEVEN) TO (LINCOLN)

    Assuming that no rule whose template is LINCOLN exists, then

    (7-20)-1 Defines a rule whose template is LINCOLN and whose value is FOUR.

    (7-20)-2 Appends SCORE AND SEVEN to FOUR. so that the yalue of LINCOLN becomes FOURSCORE AND SEVEN.

    Notice that leading and trailing blanks have be.n deleted and that •• bedded blanks have been reduced to a single blank in the appended text. This is ~ dona so that the value part will conform to tho "canonical" form for rule definition.

    A.James Cook - 56 - December 16, '982

  • Mortraft3·Us.~ts Guida - 57 - CGT" ZO~

    If It t. d •• ired that blanks be preserved in the appended taxt. the alternat. fo,.. of lPPEND should b. used. U.ing the alternate fOnl with tNt __ ex_pl.:

    I (7-21) Z

    3

    APPEND 'FOUR' TO 'LINCOLN' APPEND '·5COItE AND S£VEN' TO • LINCOLN' APPEND 'YEARS ACO t TO 'LINCOLN'

    If one denote. a blank by • lower ca.e "b", than the final value of LINCOLN produced by (7-Z~) would be:

    or

    In sum .... ry:

    fOUIt5COItEbAKDb$EYEHbYEARSbbbAGOb FOURSCORE AND SEVEN YEARS AGO

    • Text •• y b. APPENDed to • previoulsy DEFINEd rul.~

    • The alternat. for. May be used after the "standard" for •• _d vic. V.,.StI.

    A.James Cook - 57 - December 16. 1~82

  • "ortran3 User's .Gutde - 58 -

    7.11 RECIAL 'ntlOL'

    7.12 DIE BEsnUE, ,neIL

    One _y.bol is reserved for ",ystem" use and •• y not be used by the progr .... r ,. afty eofttext ~hat.v.r. ..ve one: it .. y be chenged. The aefault •• ttlng for the reserved symbol t, "a". If this .YMbol .ust be u.ed for other purposes, (e.g. the operating syst .. demands its uIe). the reserved 'YMbol •• Y be changed. The reserved .ymbol .ay b. s.t by the processor directive

    !SETrRESERVED (where "r" denote, an ASCII SYMbol.)

    For example, !SETIRESERVED would causa the symbol "I" to bee OM. the r.served symbol. Sub.equent to !SET.RESERVED. the .YMbol "a" would beco.e available for othar purpos.s.

    7. 1~ OTHEB "SPECIAL" SYHlOLS

    In addit;on to the reserved 'yntbol, Mortran3 recognizes. nuatber of 'YlBbols (in 10 •• context) el "speci.l". Thera era thraa categories:

    .) Del h,it.rs: Parentheses ------ () Braces ----------- {} Bracket. --------- [] Quot.tion mark ---Apostrophet 3 -----

    "

    b) Two directive indicators:

    Bang -------------Percent ---------- X

    c) One terminator: Semicolon -------- •

    t3 The apostrophe may also be treated as an "ordinery" symbol. "ortran3's treatMent of the apostrophe depends upon a togg'le that may be s.t by the !STRIHG processor directive. See appendix A end a1.0 the subsection "The Apostrophe" below.

    A.James Cook - 58 -

  • Mortran3 Us.r's Guide - 59 - CGTM 209

    7.13.1 Twr1II-t." ... ,,11.tt,ts

    • A '.,..inator .... ks tNt .nd of an object • Deli.iter • • ark both the b..inn;n. ~d the .nd of an obj.ct.

    Fo ... xempl., an .xcl ... tion point fer.in.f •• thl •• entenc.! In cont .... t. a r ... rk (lik.thi.) I. oft.n d.li.if.d by par.nthes.s. But a r •• ark, like this, -v also b. deli.lt.d by co..... In wrftt.n Engilsh. a "par.nthetlcal re .. rk- ;s not n.c •• sarily a r •• ark within par.nthes.sl it.ay b. a .. ..ark s.t off by co .. as.

    So •• d.limit.rs (lik. ~r.nthes.s) ... ploy •• parat., .V_.tric sV-bols" to ... ark the b •• inninSf and .nd of the d.li.it.d t.xt. The FORTRAN "languag." us.s par.nthes.s as d.li.it.rs In .any cont.xts, but .. kes Ittti. us. of t.r.inators. The FOITIA" "END .t.t ... nt- t.r.tnat.s (.ub)progr.... But .tat ... nts ar. not ,xplicltly t.r.inat.d. Ret her, theyar. I.plicitly t.rminat.d .t the end of a lin. unl.s. the following lin. i •• "continuation lin.".

    Mortran3 "languag. stat ••• nts" er. t.rMinat.d by s .. icolons as d.scrib.d in Part On ••

    In contrast, REPLACE(t •• p/a'.)WITH(valu.) is •• t a stat ••• nt. it is a function d.finition. It ,a not t.rMinat.d by a s .. Icolon, b.eaus. both the t •• plat. and yalue perts •• V contain .e.icolon.. loth the t..,lat. ~d value parts ar. d.li_it.d by braces. cons.qu.ntly n.ither MaY contain unbalanced braces.

    7. t3. t. t The Apostrophe

    The .postrophe is not the •••• (conceptually) a. a quotation .ark. But .ost FOITRAN compil.rs have be.n ext.nded t ' to inelud. the apostrophe as • "legal"

    " Th. French language •• ploys the symbols "

  • Mortran3 U •• r'. Guida - GO -

    charact.r. and thRy eMploy the apostrophe as a d.li.iter for Wllteral" data or "strings". MortranJ's predecessor, "ortran!, deli.it.d it. -patterns" (t.-plates) with _po.tr.p~s. And thereto hangs _ tal. of horror. To illustrate, consider the following for. of the Universal Truth:

    It don't .atter!

    We .ay write this in a FORMAT stat ... nt using the (extended) convention, as:

    I 'It don"t •• tt.rl'

    FORTRAN

    Hare, literal date is d.,i.ited by denot.d by a poi~ of apostroph ••• having said: "It don't .atter!".

    apostrophes, and a singl. apostrophe is Jut suppose w. want to quota 01' Jo. as

    '01" Joe said: "It don""t .atter!'·'

    Hare, a single apostrophe ·deli.lts the outer quotation and a pall" of apostrophes denote a sinl1e apo.trophe and also deli.it the inner quotation, while four apostrophes denote an apostrophe within the inner quotation. If w. quote 01' Pate quoting 01' Joe, we get:

    '01" Pate said: "01"" Joe said: ""It don,,·,·,··t matt.r!'······

    Using symmetric "French quotes" we could re-write the latter as:

  • Mortran3 User's Guide - 61 -

    "ortranZ fell Into the trap illustrat.d by the above eXaMple.. Mortran2 "patterns" (template.) were deli.ited by apostrophes. following the extended FORTRAN convent ton for .tring ••

    Mortran3 has eliMinated this horror to a large extent. but vestige. r .. ain. In particular, Mortran3 .ust .tlll accept and process FOR",T stat .. ents using this convention. "oreover, "ortranJ .ust per.it user-defined tran.for.ation rule. that •• nerot. FORTRAN-cOMpat.ble d.t. for FORMAT st.t .. ents.

    "ortranJ's fntepratatfon of the apostrophe depends upon. toggle that .ay be set by the progr .... r. The toggle ts turned "ON" by the processor direotive "!STRIMGSi" and is turned "OFF" by the processor direc' •• "!NOSTIINGS;-. The default setting is "ON". which .eans that the apostrophe Is a dell.lter of strings. "OFF" •• an. that the apo.trophe is tr.at.d like any other SYMbol.

    A.James Cook - 61 - December 16. 1982

  • Mortran3 U.er's Guide - 62 - CGTM 209

    AppellCltx A

    'ROCESSOR CONTROL

    There are two type. of proces.or control directive.:

    • Free-form • Column-ona-restrlcted.

    Free-form directives may app.ar anywhere on a line. directive •• ay appear on a line.

    Any number of Free-form

    Column-one-re.tricted directive. nUST besin in .column one and only one directive per line ;s recognized. (Column-one-restricted directives are a hold-over frOM MortranZ, and will b. eliminated in future versions.)

    A.1 FBEE-FOR" PIRECTIYES.

    IANNOTATE;

    !COMMENTS;

    !LIST;

    !DEFIHE;

    !LABELS n;

    A.James Cook

    Interl.ave Mortren .ource in FORTRAN output. Mortran statements become COMMENT. in FORTRAN output.

    !NOANNOTATE: Turn off !ANNOTATE.

    Print Mortran comments as FORTRAN comments. Mortran comment. are output to FORTRAN file with 'e' ·in column one.

    !HOCOMMENTS: Turn off !COMMENTS.

    Turn on Mortren listing

    !HOLIST: Turn off !LIST.

    Print out rules .t point of definition.

    !HODEFIHEi Turn off !DEFINE.

    Reset FORTRAN statement label generator to n.

    - 62 - December 16. 1982

  • Mortran3 User's Guid. - 63 -

    !LOCAL;

    lEND LOCAL;

    I RECOVER

    !SEQUENCE n;

    !TRACE n;

    A.James Cook

    a.,in "local" rule definitions. Local rules .pplV to the text betw.en the !LOCAL .nd !END LOCAL direct I., •••

    Re.o.,e ell rules defined after IEGIN LOCAL. and recover space.

    Recover workspec. occupi.d by "d •• d" rules. -

    n=l. Put the Mortran3 source fra. colu.ns L-& thru L into columns 73 thru 80 of the FORTRAN text. (where L is the line length.)

    n c 2. Put Mortran3 generated s.quence ,nUMbers into coluMns 73 thru .0 of the FORTRAN t.xt.

    n=(ongthing .' •• ), Put blanks into coluMns 73 thru 8D of the FORTRAN text.

    n=Z print t .. plate and param.ters each ti.e • rule is applied, NOT including nested applications.

    n=3 print template and p.r ... t.rs each tim. a rule i. applied, INCLUDING nested applications.

    n=6 print template and parameters each ti ••• rule is ,ATTEMPTED, INCLUDING n •• ted applications. (Produces VOLU"INOUS output. Not normally used.)

    - 63 - December 16, 1982

  • - 611 -

    A.2 COLYnN-OII-IESTIICTED PIRECTlyES.

    ~An For n-' .eM ••• !ANNOTATE; .boy. n=2 sa •• as !NOAHHOTATE. above

    Xln Set Input buffer size ·to 8D

  • MortranJ User's Guide - 65 -

    _ ... 'Ix. 'II"ITIVE SPECIFICATIONS.

    QUALIFIERS QUANTIFIERS ALTERNATIVES LITERALS

    Thes. primitives provide the interf.ce to the text containing user-defined notations. The "ortran processor d.flnes • "recognilton function" for each user-defined SPECIFY .tat_ent. The .".ci'i.r part beco ••• the ncr •• 0' .,,. 'unction. When a specifier ts used •• a par •• eter .arker in a _EPLACE statement, the recognition function 'a invoked. Therefore. ALL user-defined recognition functions (specifiers) Must (ulti.ately) be resolvable in terms of these four prl.ltives.

    a.1 IUALIFIERS

    where: and

    (St ••• 5z)

    51 and S2 ere symbols. 51 ~ 52

    This primitive t7 qualifies a single text sYllbol. Let T be • text symbol. Then,

    (St ••• Sz) returns •• t if St ~ T $ 5z end not-•• ., otherwise •

    • 7 This primitive depends upon "ortran's internel representation of symbols. 'In the present cont.xt it .uffic.s to note that D

  • "ortran3 User'. Guide - 66 -

    1.2 'VAMIIEII!S.

    C.in,.ax) [speciffcat ion]

    C.xoct) [spectficat fon]

    .in~ .ax, and exact .ust b. reduolble to constant expr ••• ion •• 'I

    • Quantifiers ere enclosed in par.nthes.s

    COT" 209

    • The specifications to which they apply are enclosed in square brackets.

    • ( .in,.ax) returns •• t for no fewer then .in nor .ore than .ax occurrences •

    • ( .xact) returns •• t for exactly .xact occurrence ••

    ,. See the Subsection "Constant Expressions".

    A.James Cook - 66 - December 16, 1982

  • "ortran3 Us.r's Guide - 67 -

    •. 3 ATE.Uln,

    [ A t I Az I ... I An 1

    • If an alternattve returns alternatives ar. skipped.

    • If the I;st is exhausted, not-•• t is returned.

    • The nuabe,. of alternattv •• t. not li.ited.

    • An alternative .ay •• t b. NULL (e.pty), but it .ay be the ."'pty .trlng: " An ent Ire 1 t.t of alt.,-nat iv ••. • ay ba spaclfied as "optional" by including the _pty string as the last alt.rnativ.. lecause the ampty string ;s always satisfied, it .ust be the last of the alternatives.

    • A list of .lternative. _ey quantified.

    In pDrticulDr, (',I)[AtIAzl ••• IAn]

    is equivalent to [AtIAzl ••• IAnI"l.

    • An unquantified list of alternatives:

    is equivalent' to

    A.James Cook

    [ ... 1···1···] (1)[·.·1···1···]

    - 67 - Dec •• ber 16, 1982

  • Mortrllft.J Us.r's Quid. - 68 -

    1.11 LITERALS

    LITERALS in specific.tions .re writtenz

    '.tring' I where

    Within .tring, • single .postrophe Must be

    repre.ented by • p.ir of apostroph.s.

    Literal. in .pecification. should not be confused with I;t.ral -M-bo/. in rut. definitions.

    Literal .y.bols in rule d.finitions (REPLACE .tate.ent.) are NOT enclosed In apostrophes.

    • In a rule that does not contain apo.trophes: In the templ.te part, .11 SYMbols not enclosed in brace •• r. literal SYMbols.

    • In a rule containing apostrophes,

    (I There MU.t be an even nUMber of apostrophes. (Z The doubling rule applies for embedded apostrophes. (3 In the template part the apostrophe. Must •• tch the text. (4 In the value part the apostrophes are generat.d.

    In summary:

    In specifications a string denotes a sequence of literal symbols.

    In rule defininttions a string denotes. literal in the FORTRAN sense.

    - 68 - December 16. 198Z

  • - s, -

    App.Btllx C

    PRI"ITIVE EVALUATORS

    All pri.itive evaluatfonfunctiOft reference." are denoted by:

    where IKI •• is the n_e of the funct ion .nd g~g ts an arbitrary string of .y.bols.

    COT" 209

    Pr;.itive evaluation function reference. "V be ne.ted.. The "depth" of the nesting is li_ited only by the .. ount of ·work-.pace" available to "ortran. (In other words. there i. no f txed 1 t.tt on the nest ing level.)

    Evaluation i. froM the inner.ost of the ne.t outward.

    c. t .'UCE

    (REDUCE arg) Recursively apply all (.yst .. and user) rules to the argument until no rule is applicable.

    C.2 cotrUfE

    (COMPUTE arg) Invoke REDUCE. REDUCEd argum.nt .hould b. constant expression.

    - If it is. returns value of constant expression. - If it i. not. i.sue. error .essag. end return. O.

    " Except the evaluation-time IF-ELSE.

    A.J .. es Cook - 69 - December 16. '982

  • "o .. trenJ U.e .. 's Guide - 70 -

    C.3 coUNTER PBIHITIYlS

    There .re 35 us.r-.cc •••• bl. counters. 1 ••• 9 • • nd A ••• Z.

    Each of these counter. c.n hold one bln.ry integer.

    The following prlmitiv •• refer to the.e counters.

    (INeR c) Incr .... nt counter c. c a ( I •• • I,A ••• Z) (DECR c) decrement " (SETR c=e) .e