home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / FORTRAN.ZIP / SBM.LS2 < prev    next >
Encoding:
Text File  |  1991-01-10  |  21.2 KB  |  621 lines

  1.  
  2.  
  3.  
  4.  
  5.                                   CONTENTS
  6.  
  7.     Introduction to SBM fortran. . . . . . . . . . . . . . . . . . . . iii
  8.     Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
  9.     Current status . . . . . . . . . . . . . . . . . . . . . . . . . . v
  10.  
  11.     Fortran statements . . . . . . . . . . . . . . . . . . . . . . . . 1-1
  12.     Statement lables . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
  13.     Symbolic names and keywords  . . . . . . . . . . . . . . . . . . . 1-1
  14.     Statement order  . . . . . . . . . . . . . . . . . . . . . . . . . 1-1
  15.  
  16.     Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
  17.     Include  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
  18.  
  19.     Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
  20.              Byte, Character, Integer*1, Logical . . . . . . . . . . . 1-3
  21.              Word, Integer, Integer*2  . . . . . . . . . . . . . . . . 1-3
  22.              Doubleword, Integer*4 . . . . . . . . . . . . . . . . . . 1-3
  23.              Character strings, ASCIIZ . . . . . . . . . . . . . . . . 1-3
  24.  
  25.     Quoted strings . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
  26.     Data declaration and initialization  . . . . . . . . . . . . . . . 1-5
  27.     Data statement . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
  28.  
  29.     OPEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
  30.              UNIT (5-255). . . . . . . . . . . . . . . . . . . . . . . 2-1
  31.              IOCB names  . . . . . . . . . . . . . . . . . . . . . . . 2-1
  32.              FILE  . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
  33.              ALIAS (alternate name for io unit). . . . . . . . . . . . 2-1
  34.              STATUS (old, new, append) . . . . . . . . . . . . . . . . 2-1
  35.              RECL  . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1
  36.  
  37.     READ STATEMENTS  . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
  38.            Unformatted . . . . . . . . . . . . . . . . . . . . . . . . 2-3
  39.            formatted . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
  40.            List directed . . . . . . . . . . . . . . . . . . . . . . . 2-4
  41.  
  42.            Next character from keyboard (NEXCHAR). . . . . . . . . . . 2-4
  43.  
  44.     WRITE STATEMENTS . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
  45.            Unformatted . . . . . . . . . . . . . . . . . . . . . . . . 2-5
  46.            formatted . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
  47.            List directed . . . . . . . . . . . . . . . . . . . . . . . 2-6
  48.  
  49.            SHOW_CHAR (display a character on screen) . . . . . . . . . 2-6
  50.            CRLF  (write cr,lf to specified IOCB) . . . . . . . . . . . 2-6
  51.  
  52.     FORMAT STATEMENTS  . . . . . . . . . . . . . . . . . . . . . . . . 2-7
  53.            Field and edit descriptors. . . . . . . . . . . . . . . . . 2-7
  54.  
  55.     ARITHMETIC EXPRESSIONS . . . . . . . . . . . . . . . . . . . . . . 3-1
  56.            INC, DEC  (incrementing and decrementing variables. . . . . 3-1
  57.            ADD, SUB  (adding to, or subtracting from variables . . . . 3-1
  58.            Subscripts  . . . . . . . . . . . . . . . . . . . . . . . . 3-2
  59.  
  60.  
  61.  
  62.  
  63.  
  64.                      INTRODUCTION TO SBM FORTRAN
  65.  
  66.     This manual describes  SBM FORTRAN.  SBM is based on American National
  67.     Standards Institute FORTRAN 77 language.  It is assumed that the reader
  68.     has knowledge of an existing FORTRAN language and is familiar with MSDOS
  69.     or PCDOS operating system.  This manual is not intended to teach
  70.     FORTRAN, but is intended to be used as reference material only.
  71.  
  72.     The original intention of SBM fortran was the author's answer to the 'C'
  73.     language. The cryptic nature of 'C', while appealing to many
  74.     programmers, leaves me cold. While I fully appreciate the power of the
  75.     'C' language (as with assembler), I felt that there was needed something
  76.     that would better suit my style.
  77.  
  78.     I also remember when I brought my first XT home. There were many
  79.     fortran-written utilities that I had on the Z-80 without which I felt
  80.     very helpless. By the time I had rounded up the money to buy the system,
  81.     I had none left for the software that I very sorely needed.  An
  82.     affordable compiler of an easily learned language seemed to the the
  83.     answer.  A good reason  for someone, such as I, to write SBM fortran.
  84.  
  85.     The powerful fortran systems that are now on the market are designed with
  86.     the high-level user in mind.  Program size is not important.  I needed
  87.     something that would generate about the same code as if I wrote the it in
  88.     assembler.
  89.  
  90.     This compiler operates by converting FORTRAN source code into assembler
  91.     instructions,  which are then converted into machine code using WASM, an
  92.     assembler written by ERIC TAUK, of Merengo, IL.  The result is a COM
  93.     file, which can then be run on any MSDOS based system.
  94.  
  95.     THIS IS VERSION 1.00. To most of us this means a system that works well
  96.     enough for the author, but sometimes awkward for the user. Here is a
  97.     problem. I am in the process of moving to Wyoming.  Here in Denver, I
  98.     have access to many excellent bulletin boards. In Wyoming, that will
  99.     not be the case. I must therefore release this version knowing that
  100.     there may be bugs.  Since I will no longer have easy access to the
  101.     boards, I will not longer have easy access to you, the user. I must
  102.     therefore go to a 'shareware' mode.
  103.  
  104.     To provide this connection, You must send me your name and mailing
  105.     address. That will make you a registered user. To receive ANY updates of
  106.     this compiler, you MUST be a registered user. At a minimum, I will
  107.     upgrade to provide some of the functions that I need. Registered users
  108.     will receive the first (or most recent) update. I most certainly need
  109.     your suggestions for improvements and bug removal. If you like this
  110.     compiler as I believe you will, your $20 contribution will be
  111.     appreciated.  Since I will no longer have access to the boards, that's
  112.     the only way that you can receive the update.
  113.  
  114.  
  115.  
  116.     MSDOS is a registered trademark of Microsoft Corporation.
  117.     PCDOS is a registered trademark of IBM Corporation.
  118.  
  119.  
  120.  
  121.  
  122.  
  123.                                    iii
  124.  
  125.  
  126.  
  127.  
  128.  
  129.     CURRENT STATUS OF SBM FORTRAN
  130.  
  131.     BE VERY CAUTIOUS USING ANY SORTWARE!  Do not trust it!  Even if you
  132.     have been using it for awhile, mentally EDIT the output.  Does it look
  133.     reasonable?  You are the best judge.
  134.  
  135.     SBM fortran is not a  scientific compiler. i.e., it does not have
  136.     floating point.
  137.  
  138.     Integer*4 is there, but needs more hooks before it can be used.
  139.  
  140.     Arithmetic expressions are primitive, but gramatically correct and
  141.     transportable.  This feature will be upgraded to some extent.
  142.  
  143.     Needs more diagnostic messages.  SBM fortran is not just forgiving. It's
  144.     actually permissive.
  145.  
  146.     But, on the other hand, if you accept the above limitations, and write a
  147.     program using standard fortran coding techniques, it will work, and the
  148.     code can be put up and run under most other F77 compilers, without
  149.     modification.
  150.  
  151.  
  152.  
  153.  
  154.     FUTURE OF SBM FORTRAN
  155.  
  156.     SBM fortran was not, and is not intended to be a full-blown fortran
  157.     compiler. It is not intended to compete with the more powerful
  158.     systems.
  159.  
  160.     Integer*4 is one feature that will certainly be implememted. With large
  161.     integers, you can do quite a lot.  Accounting work and other related
  162.     types of work require precise calculations. Large integers makes that
  163.     precision possible. Instead of dollars and cents, you can carry
  164.     everything in total cents. i.e. $156.25 is 15625 cents. For output,
  165.     the format statement can direct that a decimal point be inserted (this
  166.     feature is already installed, but not yet usable).
  167.  
  168.     The compiler needs compile time and runtime error detection that it does
  169.     not now have. Some errors simply lock up the system.  That is something
  170.     that must be addressed in the first update.
  171.  
  172.     The direction of its future is mostly up to you.  I have some floating-
  173.     point routines that could be implemented, but I will probably not work in
  174.     that direction unless there's enough response.  The routines are in
  175.     another  fortran compiler of mine which I chose not to release at this
  176.     time.
  177.  
  178.  
  179.     There's  another feature, TONTO (trace-on, trace_off), that might also be
  180.     moved  from my other compiler.
  181.  
  182.                                     v
  183.  
  184.  
  185.  
  186.     1-2
  187.  
  188.     COMMENTS - You can use a semi-colon(;), an asterisk(*) or hyphen (-) in
  189.     column 1 to specify that the line is a comment. In addition, if you place
  190.     a ';' anywhere in the statement portion of a source line, the rest of
  191.     that statement will be treated as a comment. A blank line is also
  192.     considered to be a comment.
  193.  
  194.     Individual assembler code statements can be inserted anywhere by placing
  195.     a plus (+) in column 1.
  196.  
  197.  
  198.     INCLUDE
  199.  
  200.     Blocks of fortran statements, assembler code, and macros may be inserted
  201.     using the INCLUDE option.
  202.  
  203.     Syntax:    INCLUDE pathname   Pathname can name any file that is
  204.                                   currently on line, on any disk.
  205.  
  206.     To include assembler code or macros, the statement must have a '+' in
  207.     column 1 and the pathname must be in quotes.
  208.  
  209.     Example:  +   include 'maclib.asm'
  210.  
  211.  
  212.     A small macro library is provided to generate some of the code that the
  213.     compiler needs.  You may build one of your own choosing and insert it
  214.     using the + INCLUDE option.
  215.  
  216.  
  217.  
  218.  
  219.     1-4
  220.  
  221.     QUOTED STRINGS
  222.  
  223.     Over the years, we programmers have created a standard that would not be
  224.     acceptable to people other than programmers. That is, calling an
  225.     apostrophy a quote! When we think of quoted strings, we think of an ascii
  226.     string enclosed in apostrophies, not quotes. Don't know how this started,
  227.     but we all do it. Anyway, format statements sometimes require us to
  228.     specify a 'quoted' string for output. With this in mind, in this manual,
  229.     when we talk of a quoted string, we mean a string that is enclosed in
  230.     apostrophies.
  231.  
  232.     When entering a quoted string that we wish wish to contain an imbedded
  233.     quote, SBM FORTRAN requires that you use an ACTUAL quote(").  Standard
  234.     fortran wants you to use two apostrophies in a row.  We do it differently
  235.     here.
  236.  
  237.  
  238.  
  239.     example:  standard fortran requires:
  240.  
  241.               FORMAT('We sometimes don''t follow standards')
  242.  
  243.  
  244.  
  245.     We do it this way:
  246.  
  247.               FORMAT('We sometimes don"t follow standards')
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.     2-2
  258.  
  259.     READ STATEMENTS
  260.  
  261.     READ statements transfer data from a specified I/O unit to memory.  You
  262.     can reference both external and internal files.  The input data may be
  263.     any ASCII stream.
  264.  
  265.     Syntax:   READ(UNIT [,FMAT]) list
  266.  
  267.  
  268.     UNIT is one of:
  269.  
  270.         (1) An integer constant in the range of 5 to 255 that identifies an
  271.             external unit previously referenced in an OPEN statement.
  272.  
  273.         (2) An asterisk (*) specifying the default I/O unit (console).
  274.             May be redirected.
  275.  
  276.         (3) The name of an internal array (such as the input buffer)
  277.             containing data. This is the manner by which you can re-read
  278.             a data record.  explanation:  on any read, the data is read into
  279.             the input buffer as raw data.  If a format has been specified,
  280.             the record is transformed into the corresponding input fields.
  281.             But: even after formatting, the raw data is still in the input
  282.             buffer.
  283.  
  284.     FMAT is a parameter that specifies whether explicit or list-directed
  285.             formatting is to be applied. It may take either of the following
  286.             forms.
  287.  
  288.          (1) A statement label of a format statement. The statement label
  289.              must begin with a numeric character 0-9. The rest of the label
  290.              can be anything of your own choosing.
  291.  
  292.          (2) '*' that specifies list-directed formatting.
  293.  
  294.  
  295.     If FMAT is omitted, a 'null' read is performed, effectively passing over
  296.     an input record.  The unformatted contents of the record are not lost,
  297.     however, but are preserved in the input-output control buffer (IOCB).
  298.     The string is available by its IOCB name, and may be treated as any
  299.     other character array.
  300.  
  301.  
  302.     LIST names the variables, arrays, array elements and character strings
  303.     to which data will be transferred.
  304.  
  305.     If end of file is sensed, the logical variable 'EOF' is set to TRUE.
  306.  
  307.  
  308.  
  309.     2-4
  310.  
  311.     FORMATTED READ
  312.  
  313.     Syntax:   READ(UNIT,FMAT]) list
  314.  
  315.     This is a two-step operation.
  316.  
  317.     Step 1 reads the record into the IOCB (an unformatted read).
  318.  
  319.     Step 2 applies the formatting and transforms the ascii data into the
  320.     various input fields.
  321.  
  322.  
  323.  
  324.  
  325.     LIST-DIRECTED READ
  326.  
  327.     Syntax:   READ(UNIT,*) list
  328.  
  329.     Read statements are either unformatted or formatted. The difference in a
  330.     list-directed read is that the compiler is going to create a format for
  331.     itself, based on what kind of data we have in the 'list'.
  332.  
  333.     This is a two-step operation.
  334.  
  335.     Step 1 reads the record into the IOCB (an unformatted read).
  336.  
  337.     Step two applies the compiler-designed formatting and transforms the
  338.     ascii data into the various input fields.
  339.  
  340.  
  341.  
  342.  
  343.     NEXCHAR
  344.  
  345.     Reads a character from the keyboard.  Does not echo to the console. If
  346.     no character is ready, waits for operator to enter one.  The character
  347.     is available to the program in register AL.  Execution resumes.
  348.  
  349.     See 'testall.for' for a practical example. (NEXCHAR and WAIT are same)
  350.  
  351.  
  352.  
  353.     2-6
  354.  
  355.     LIST-DIRECTED WRITE
  356.  
  357.     Syntax:   WRITE(UNIT,*) list
  358.  
  359.     In a list-directed write, a format is constructed by the compiler based
  360.     upon the data type of the various fields. Other than that, it is exactly
  361.     like the formatted write.
  362.  
  363.     While most compilers require that the first character of an output record
  364.     be used for carriage control, SBM fortran does not. When output is to be
  365.     directed to a printer, feel free to insert ascii control codes, 0Ch for
  366.     eject, 0Dh for double space.
  367.  
  368.  
  369.  
  370.  
  371.     SHOW_CHAR
  372.  
  373.     Display the character that is in the AL register.  You can use this
  374.     statement immediately after NEXCHAR.
  375.  
  376.  
  377.  
  378.  
  379.     SHOW_CHAR  'char'
  380.  
  381.     Display specific character.  The character can be a printable
  382.     character enclosed in quotes, or a hex constant.
  383.     Example:    show_char 8   gives us a back-space on the console.
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.     3-2
  392.  
  393.     SUBSCRIPTING
  394.  
  395.  
  396.     Any variable may be accessed by using the variable name in a fortran
  397.     statement. To access variables in positions other than the first, you
  398.     must (1) use an integer offset or (2) use a subscript.
  399.  
  400.     An integer offset may be used by simply appending the variable name with
  401.     a plus-or-minus constant. Example: 'ARRAY+4' points to the fifth
  402.     position of a integer*1 or character array. If the array was integer*2,
  403.     it would point to the third position, since each element in an integer*2
  404.     array requires two positions. While this is not a standard fortran
  405.     method of accessing data, it is by far the most efficient.
  406.  
  407.     Subscripts, on the other hand, indicate the position of an element by
  408.     enclosing a subscript expression within a pair of parentheses.
  409.  
  410.     The subscript expression can be an integer constant, and integer
  411.     variable, or an integer variable plus-or-minus an integer constant.
  412.  
  413.       Examples: array(k), date(m+2), etc..
  414.  
  415.     Other informative examples can be found in the program 'TESTALL.FOR'.
  416.  
  417.  
  418.     A word of caution: Do not allow the expression to go negative. You will
  419.     access something, but who knows what...
  420.  
  421.  
  422.  
  423.     4-2
  424.  
  425.                             CONTROL STATEMEMTS
  426.  
  427.  
  428.     CMP variable, constant
  429.  
  430.     Compare a variable to a known value. This statement is identical to it's
  431.     ASM equivalent. Subscripts are not permitted, but offsets can be used.
  432.  
  433.     Usage:  CMP  Name, 'A'
  434.             CMP  Name+2,'B'
  435.             CMP  Year, 99
  436.  
  437.     This statement essentially subtracts the constant from the variable, does
  438.     not change any values in memory but, sets the control flags. You must
  439.     then use a conditional jump for program control.
  440.  
  441.  
  442.  
  443.  
  444.  
  445.     COMPARE
  446.  
  447.     Compare a string of characters against a model. Not case sensitive,
  448.     'TOKEN' should be upper case.
  449.  
  450.     Usage:  COMPARE KEWORD, 'TOKEN'
  451.  
  452.  
  453.     Example, from the compiler.
  454.  
  455.     -   see if prefix 'byte' or 'word'
  456.         compare keword,'BYTE'    ;
  457.         if(eq) goto destin_ok    ; if 'byte' or 'word',
  458.         compare keword,'WORD'    ; accept it as-is.
  459.         if(eq) goto destin_ok    ;
  460.  
  461.  
  462.     GOTO          Unconditional transfer of control.
  463.     JMP           Same as GOTO
  464.  
  465.  
  466.  
  467.     WAIT
  468.  
  469.     Wait for operator. Program execution stops. When operator has pressed
  470.     any key, execution resumes.
  471.  
  472.  
  473.  
  474.     PAUSE ['message']
  475.  
  476.     Stops, waits for operator. If message included, displays the message.
  477.     Otherwise, displays the phrase 'FORTRAN PAUSE'. Execution of the program
  478.     will continue with the press of any key.
  479.  
  480.  
  481.     STOP, CALL EXIT
  482.  
  483.     Use either to close all files, update directory and return control
  484.     to the operating system.
  485.  
  486.  
  487.  
  488.     4-4
  489.  
  490.                             IF statements
  491.  
  492.     An IF statement conditionally executes one statement or a block of
  493.     statements.
  494.  
  495.     The IF statement has the form:
  496.  
  497.       IF (exp) stmt
  498.  
  499.     Where exp is a logical or relational expression.
  500.  
  501.  
  502.  
  503.     In a LOGICAL IF statement, we have, as the result of a TEST or
  504.     input/output operation, a condition of true(non-zero) or false(zero). The
  505.     statement, or block of statements, will be executed only if the condition
  506.     is true. In a logical IF, exp simply names the logical variable. In
  507.     addition to the normal variable names, SBM fortran also allows the
  508.     following:
  509.  
  510.                    (EQ), (NE), (ZR), (NZ), (CY), (NC)
  511.  
  512.           or    (EOF),  (NOT.EOF),  (NUMERIC), (NOT.NUMERIC)
  513.  
  514.     stmt can be any non-labled executable statement, but not another IF.
  515.  
  516.  
  517.     The RELATIONAL IF statement performs an on-the-fly comparison of a
  518.     variable to a known value.
  519.  
  520.     Character-strings can be compared, no matter what their length, but only
  521.     for EQ or NE. Other operators may be used, but use with caution. The
  522.     comparison is NOT case sensitive.
  523.  
  524.     The relational IF has the following syntax:
  525.  
  526.           IF (VARIABLE.OP.Constant) stmt
  527.  
  528.     where  OP will be EQ, NE, LT, GT, LE, GE
  529.  
  530.     Constant may be (1) numeric,
  531.                       (2) Ascii character (excluding ';' and '|') , or
  532.                       (3) AsciiZ string.
  533.  
  534.  
  535.  
  536.     4-6
  537.  
  538.  
  539.     The block IF conditionally executes blocks of statements. It has the
  540.     following form:
  541.  
  542.     IF (exp) THEN
  543.        block
  544.  
  545.     ELSE
  546.        block
  547.  
  548.     ENDIF
  549.  
  550.     where:
  551.       exp is a logical expression.
  552.  
  553.     THEN must appear on the same line.
  554.  
  555.     block is a series of statements, none of which can be another block-IF.
  556.  
  557.     The ENDIF terminates the block-IF construct.
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.     4-8
  565.  
  566.  
  567.     DO Statement
  568.  
  569.     Here you can specify that a block of statements be executed for a
  570.     specific number of times.
  571.  
  572.  
  573.     Syntax:   DO label index=first,last
  574.  
  575.     where: label is a numeric statement label of a CONTINUE statement which
  576.            is forward from this statement.
  577.  
  578.            index is an integer*2 variable that will be set, and then
  579.            incremented.
  580.  
  581.            first is an integer constant.
  582.  
  583.            last is an integer constant.
  584.  
  585.  
  586.  
  587.  
  588.     CONTINUE statement
  589.  
  590.     Used only in conjunction with the DO statement, this statement is labled
  591.     and is used as the terminator of the block of statements to be executed.
  592.  
  593.  
  594.     Example:  from "testall.for"
  595.  
  596.               do 809 counter=1,10
  597.               write(16,309) counter
  598.           309 format('test output record',i3)
  599.           809 continue
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.     6-2
  607.  
  608.     MISCELLANEOUS INTRINSIC FUNCTIONS
  609.  
  610.  
  611.  
  612.  
  613.     PARSE STRING, KEY  [, 'delims']
  614.  
  615.     Given the ascii STRING, isolate the first token. Copy the isolated token
  616.     to KEY and shift STRING left to remove the token KEY. Delimiters are
  617.     blank, comma or equals. Carry is set if no data available to parse (EOR).
  618.  
  619.     You can specify an  additional list of delimiters to be used.
  620.  
  621.     Example:  Consider the string 'now is the-time'
  622.  
  623.         parse string,keword,'(/-+'
  624.  
  625.     After the parse,  keword will be 'now'
  626.                       string will be 'is the-time'
  627.  
  628.                       carry is not set.
  629.  
  630.  
  631.     PARSE_ONLY String, Keword, 'char'
  632.  
  633.     Parse until a specific character is found. We ignore the standard
  634.     delimiters. In fact, the standard delimiters (including blanks) are
  635.     passed to the 'keword' array.
  636.  
  637.     Example:  As above, the string 'now is the-time'
  638.  
  639.         parse_only string, keword,'-'
  640.  
  641.     After the parse,  keword will be 'now is the'
  642.                       string will be 'time'
  643.  
  644.  
  645.  
  646.     LDA           Load address to a register:      LDA VARIABLE, REG
  647.  
  648.  
  649.     UPCASE        Convert a character string to upper case.
  650.  
  651.                   Usage:  UPCASE String
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.