
      SKP 
* 
***                        ** 
**  <MAT STATEMENT> SYNTAX  **
***                        ** 
* 
MATS  JSB LTR       FIRST TWO 
      JSB SERRS+18,I  CHARACTERS
      JSB LETCK         LETTERS?
      JMP MATS3     NO
      ISZ SBPTR     YES,
      ALF,ALF         RETRIEVE
      IOR TEMP+1        FIRST CHARACTER 
      STA SBPTR,I   LOOK
      LDA .+5         FOR 
      STA MAXCR         'INPUT',
      LDA MATIO           'READ', 
      LDB .-3               OR
      JSB TBSRH               'PRINT' 
      JSB SERRS+18,I  NONE FOUND
      CPA PRTOP     IS IT 'PRINT'?
      JMP MATS2     YES 
      CPA INPOP     NO, 'INPUT' ? 
      JMP MATS1-2   YES 
      JSB RECRF     NO, READ FROM FILE? 
      JMP MATS1-3   NO
      CPA B73       YES, ';' ?
      JMP MATS1-2   YES 
      JSB SERRS+6,I NO
      JSB BCKSP 
      CLA,INA       TURN ON 
      STA DFLAG       'MATRIX SUBSCRIPT' MODE 
MATS1 JSB ARRID     RECORD AN ARRAY 
      JSB SBSCK     RECORD SUBSCRIPT
      NOP             IF PRESENT
      CPA .+15B     END OF STATEMENT? 
      JMP ACCSA,I   YES 
      CCB           NO, DEMAND
      JSB SYMCK       COMMA 
      DEF COMMA-1 
      JSB SERRS+6,I NOT FOUND 
      JMP MATS1 
MATS2 JSB SBPUD     ADVANCE SYNTAX BUFFER POINTER 
      JSB GETCR     FETCH NEXT CHARACTER
      JSB SERRS+6,I NONE FOUND
      JSB USTCK     CHECK FOR USING STATEMENT 
      JMP MAT13     NONE FOUND
      CPA .+15B     CARRIAGE RETURN ? 
      JMP ACCSA,I   YES 
      CCB           SEMI- 
      JSB SYMCK       COLON 
      DEF SEMI-1        FOLLOWS?
      JSB SERRS+34,I NO 
MAT12 JSB SBPUD     ADVANCE SYNTAX BUFFER POINTER 
      JSB GETCR     FETCH NEXT CHARACTER
      JSB SERRS+6,I NONE FOUND
      STA SBPTR,I   SAVE CHARACTER
      JSB PFSRH     SEARCH FOR PRINT FUNCTION 
      RSS           FOUND 
      JSB ARRID     RECORD AN ARRAY 
      CPA .+15B     CARRIAGE RETURN FOLLOWS?
      JMP ACCSA,I   YES 
      CCB           NO, 
      JSB SYMCK       COMMA?
      DEF COMMA-1 
      JSB SERRS+6,I NO, ERROR 
      JMP MAT12     YES 
MAT13 JSB RECRF     WRITE ON FILE?
      JMP MAT11     NO
      CPA B73       YES, ';' ?
      CCB,RSS       YES 
      JSB SERRS+6,I NO
      STB FILRF     NOTE 'FILE' MODE
MAT10 JSB ARRID     RECORD AN ARRAY 
      CPA .+15B     END OF STATEMENT? 
      JMP ACCSA,I   YES 
      LDB .-2       NO, DEMAND
      JSB SYMCK       COMMA OR
      DEF COMMA-1       SEMICOLON 
      JSB SERRS+6,I NOT FOUND 
      JSB GETCR     END OF STATEMENT? 
      JMP *+3       YES 
MAT11 JSB BCKSP     NO
      JMP MAT10 
      JSB SBPUD     UPDATE POINTER
      ISZ FILRF     'FILE' MODE?
      JMP ACCSA,I   NO
      JSB SERRS+2,I   YES 
MATS3 LDB SBPTR     SAVE ADDRESS
      STB ARYAD       OF ARRAY OPERAND
      LDA TEMP+1    RECORD
      STA SSTAK,I     AND SAVE
      LDB .+46          THE ARRAY 
      JSB STROP           IDENTIFIER
      LDA TEMP+2    RETRIEVE
      CCB             NEXT CHARACTER
      JSB SYMCK         AND TEST FOR
      DEF ASSOP-1         ASSIGNMENT OPERATOR 
      JSB SERRS+3,I NOT FOUND 
      JSB LTR       LETTER NEXT?
      JMP MATS5     NO
      JSB LETCK     YES, ANOTHER LETTER?
      JMP MATS6     NO
      ISZ SBPTR     YES,
      ALF,ALF         CONCATENATE 
      IOR TEMP+1        LETTERS 
      STA SBPTR,I         AND 
      LDA MATFN             SEARCH FOR
      LDB .-5                 AN ARRAY
      JSB TBSRH                 FUNCTION
      JSB SERRS+7,I NONE FOUND
      ALF,ALF       FOUND,
      ALF,RAR         CONVERT 
      IOR PDFFL         TO OPERAND
      CCB           COMBINE 
      ADB SBPTR       WITH
      IOR 1,I           OPERATOR
      STA 1,I             AND RECORD
      AND B777      'INV' 
      ADA D577        OR
      SSA,RSS           'TRN' ? 
      JMP MATS4     YES 
      JSB GETCR     NO, END OF STATEMENT? 
      JMP ACCSA,I   YES 
      CLB,INB       NO, TURN ON 
      STB DFLAG       'MATRIX SUBSCRIPT' MODE 
      JSB SBSCK     DEMAND SUBSCRIPT
      JSB SERRS+5,I NONE FOUND
      JMP EOST      DEMAND END OF STATEMENT 
MATS4 SZA,RSS       ALLOW INVERSION 
      STA SSTAK,I     INTO SELF 
      JSB GETCR     DEMAND
      JSB SERRS+22,I  LEFT
      JSB LPCK          PARENTHESIS 
      JSB ARRID     DEMAND ARRAY
      JSB RPCK      DEMAND RIGHT PARENTHESIS
      LDB TEMP+1    SAME SOURCE AND 
      CPB SSTAK,I     DESTINATION ARRAYS? 
      JSB SERRS+19,I  YES 
      JMP EOST      NO, DEMAND END OF STATMENT
MATS5 JSB BCKSP     BACK UP AND 
      JSB GETPF       DEMAND PARENTHESIZED FORMULA
      CCB           SEEK
      JSB SYMCK 
      DEF TIMES-1     '*' 
      JSB SERRS+20,I  NOT FOUND 
      JSB ARRID     DEMAND ARRAY
      JMP EOST      DEMAND END OF STATEMENT 
MATS6 LDA TEMP+1    RECORD
      LDB .+46        ARRAY 
      JSB STROP         OPERAND 
      LDA TEMP+2    END OF
      CPA .+15B       STATEMENT?
      JMP ACCSA,I   YES 
      LDB .-3       NO, SEEK
      JSB SYMCK       '+', '-', 
      DEF PLUS-1        OR '*'
      JSB SERRS+21,I  NOT FOUND 
      CLB           SET '*' FLAG TO FALSE 
      CPA MULOP     '*' ? 
      JMP MATS9     YES 
MATS7 STB PFLAG     NO
      JSB ARRID     DEMAND ARRAY
      STA TEMP+2    SAVE CHARACTER
      ISZ PFLAG     '*' ? 
      JMP MATS8     NO
      LDA TEMP+1    YES, DOES ARRAY 
      CPA SSTAK,I     MATCH LEFT-HAND SIDE? 
      JSB SERRS+19,I  YES 
MATS8 LDA TEMP+2    NO, RETRIEVE CHARACTER
      JMP EOST      DEMAND END OF STATEMENT 
MATS9 CCB           SET '*' FLAG TO TRUE
      LDA TEMP+1    DOES ARRAY
      CPA SSTAK,I     MATCH LEFT-HAND SIDE? 
      JSB SERRS+19,I
      JMP MATS7     NO
      HED FORMULA SYNTAX CHECKER
* 
***                          ** 
**  <FORMULA> SYNTAX CHECKER  **
***                          ** 
* 
* 
*  FSC ANALYZES THE INPUT STRING UNDER THE ASSUMPTION 
*  THAT A LEGITIMATE FORMULA IS THERE.  EXIT TO ERROR ON
*  UNRECOGNIZABLE OR OBVIOUSLY INCORRECT INPUT.  EXIT TO
*  (P+1) WHEN CONTINUED INPUT CANNOT BE A PART OF THE 
*  FORMULA AND THE INPUT SCANNED SO FAR FORMS A COMPLETE
*  FORMULA IN ITSELF (I.E., ... A+B TO ... EXITS AFTER
*  THE 'B').  ON EXIT (A) HOLDS THE FIRST CHARACTER NOT 
*  PARSED INTO THE FORMULA, (B) = 0, AND SBPTR,I = 0
*  (END-OF-FORMULA OPERATOR).  DURING THE FORMULA PARSE,
*  SSTAK,I HOLDS THE COUNT OF UNMATCHED LEFT PARENTHESES. 
*  IF THE FIRST SYMBOL ENCOUNTERED IS A STRING VARIABLE,
*  EXIT TO ERROR IF IT IS NOT ENABLED ELSE RECORD THE 
*  VARIABLE AND ANY FOLLOWING SUBSCRIPT AND EXIT TO (P+1) 
*  WITH THE NEXT CHARACTER IN (A), (B) = -1, AND SFLAG = -1.
* 
#FSC  CLA           SET LEFT PARENTHESIS
      STA SSTAK,I     COUNT TO ZERO 
      LDA .+3       SET MULTICHARACTER SEARCH 
      STA MAXCR       TO MAXIMUM OF 3 CHARACTERS
FSC1  CCA           ENABLE
      STA UFLAG       UNARY OPERATORS 
*                         * 
**  LOOK FOR AN OPERAND  ** 
*                         * 
FSC2  JSB VAROP     SEEK VARIABLE OPERAND 
      JMP FSC7      FIRST CHARACTER NOT A LETTER
      JMP FSC13-3   SUBSCRIPTED OR STRING VARIABLE
      JSB LETCK     SIMPLE VARIABLE.  LETTER NEXT?
      JMP FSC13     NO
*                                              *
**  DOES 'AND', 'OR', 'MAX', OR 'MIN' FOLLOW  **
**    A SIMPLE VARIABLE?                      **
*                                              *
      LDB .-4 
      STA SBPTR,I   SEARCH FOR
      LDA MCBOP       'AND', 'OR',
      JSB TBSRH         'MAX', AND 'MIN'
      RSS           NONE FOUND
      JMP FSC6      FOUND 
*                                         * 
**  SEE IF OPERAND IS A FUNCTION RATHER  ** 
**    THAN A SIMPLE VARIABLE.            ** 
*                                         * 
      LDA TEMP+2
      ALF,ALF       WERE
      IOR TEMP+1      TWO LETTERS 
      CPA FN            'FN' ?
      JMP FSC4      YES 
      STA SBPTR,I   NO, 
      LDA PDFNS       PREDEFINED
      LDB .-15
      JSB TBSRH 
      JMP FSC11     NO
      ALF,ALF       YES,
      ALF,RAR         BUILD 
      IOR PDFFL         NAME
FSC3  STA TEMP+1    SAVE FUNCTION 
      CCB           RETRIEVE
      ADB SBPTR       PREVIOUS
      STB SBPTR         OPERATOR- 
      LDA 1,I             OPERAND 
      AND OPMSK     REPLACE 
      IOR TEMP+1      OPERAND 
      STA SBPTR,I       WITH FUNCTION 
      LDA TEMP+1
      CPA LENCN     'LEN' ? 
      JMP FSC0      YES 
      LDB .-9       NO, TURN OFF
      STB MSFLG       'MULTIPLE STORE' MODE 
      JSB GETPF     DEMAND PARENTHSIZED 
      JMP FSC13       FORMULA 
FSC4  JSB GETCR     DOES
      JSB SERRS+7,I   LETTER
      JSB LETCK         FOLLOW? 
      JSB SERRS+7,I NO
      ADA D100      YES,
      ALF             BUILD 
      ADA .+17B         FUNCTION
      JMP FSC3            NAME
FSC0  ISZ SBPTR     MOVE TO CORRECT PROGRAM WORD
      JSB GETCR     RECORD
      JSB SERRS+22,I  LEFT
      JSB LPCK          PARENTHESIS 
      JSB LTR       LETTER NEXT?
      JSB SERRS+24,I  NO
      CPA .+44B     YES, FOLLOWED BY '$' ?
      RSS           YES 
      JSB SERRS+24,I  NO
      LDA TEMP+1    RECORD
      LDB .+53B       STRING
      JSB STROP         VARIABLE
      JSB GETCR     RECORD
      JSB SERRS+23,I  RIGHT 
      JSB RPCK          PARENTHESIS 
      JMP FSC8
*                                *
**  CHECK FOR LEFT PARENTHESIS  **
*                                *
FSC5  LDA LPOP      RECORD
      STA SBPTR,I     A '(' 
      ISZ SSTAK,I   COUNT IT
FSC6  LDB .-9       TURN OFF
      STB MSFLG       'MULTIPLE STORE'
      JMP FSC1          MODE
FSC7  JSB SBPUD     UPDATE POINTER
      CPA .+40      '(' ? 
      JMP FSC5      YES 
      CPA B133      NO, '[' ? 
      JMP FSC5      YES 
*                        *
**  CHECK FOR A NUMBER  **
*                        *
      CLB           SET '+' 
      STB SIGN        AS SIGN 
      JSB NUMCK     SEEK A NUMBER 
      JMP FSC9      NOT FOUND 
      JSB SERRS+14,I  BAD EXPONENT
      LDB SBPTR     RETRIEVE
      ADB .-3         PRECEDING 
      LDA 1,I           OPERATOR
      IOR FLGBT     SET FLAG TO SAY 
      STA 1,I         NUMBER FOLLOWS
      LDA TEMP+1    RETRIEVE CHARACTER
FSC8  LDB .-9       TURN OFF
      STB MSFLG       'MULTIPLE STORE'
      JMP FSC13         MODE
*                                *
**  CHECK FOR A UNARY OPERATOR  **
*                                *
FSC9  ISZ UFLAG     UNARY OPERATORS PERMITTED?
      JSB SERRS+25,I  NO
      LDB UNMNC     YES LOAD UNARY MINUS OPCODE 
      CPA .+43      '+' ? 
      JMP *+4       YES 
      CPA .+45      NO, '-' ? 
      JMP *+3       YES 
      JSB SERRS+25,I  NO
      LDB UNPLC     CONVERT (B) TO UNARY '+' OPCODE 
      STB SBPTR,I   RECORD UNARY OPERATOR 
FSC10 LDB .-9       TURN OFF
      STB MSFLG       'MULTIPLE STORE'
      JMP FSC2          MODE
*                                            *
**  CHECK POSSIBILITY OF 'NOT' RATHER THAN  **
**    A SIMPLE VARIABLE                     **
*                                            *
FSC11 ISZ UFLAG     'NOT' PERMITTED?
      JMP FSC14-1   NO
      LDA SBPTR,I   YES 
      ALF,ALF 
      STA SBPTR,I 
      LDA ANOT      SEEK
      CCB 
      JSB TBSRH       'NOT' 
      JMP FSC14-1   'NOT' NOT FOUND 
      STA SBPTR,I   FOUND 
      CCB           ERASE 
      ADB SBPTR 
      LDA 1,I         SPURIOUS
      AND OPMSK 
      STA 1,I           OPERAND 
      JMP FSC10 
*                                 * 
**  CHECK FOR RIGHT PARENTHESIS  ** 
*                                 * 
FSC12 LDB .-2       ')' 
      JSB SYMCK       OR
      DEF RPARN-1       ']' ? 
      JMP FSC14     NO
      LDA RPOP      YES,
      STA SBPTR,I     RECORD ')'
      LDA .+41      RETRIEVE ')'
      CCB           MATCHING
      ADB SSTAK,I     LEFT
      SSB               PARENTHESIS?
      JMP FSC14     NO
      STB SSTAK,I   YES 
      JSB SBPUD     UPDATE POINTER
      JSB GETCR     FETCH NEXT
      JMP FSC14       CHARACTER 
      JMP FSC13 
*                                 * 
**  CHECK FOR A BINARY OPERATOR  ** 
*                                 * 
      CCB           STRING VARIABLE 
      CPB SFLAG       JUST FOUND? 
      JMP FSC,I     YES 
FSC13 CPA .+15B     NO, END OF STATEMENT? 
      JMP FSC14     YES 
      STA UFLAG     NO, DISABLE UNARY OPERATORS 
      STA TEMP+1    SAVE CHARACTER
      LDB .-7       SEARCH
      STA SBPTR,I     FOR A 
      LDA MCBOP         MULTICHARACTER
      JSB TBSRH           BINARY OPERATOR 
      RSS           NONE FOUND
      JMP FSC6      FOUND 
      LDA TEMP+1    NO, RECOVER A CHARACTER 
      LDB MSFLG     SINGLE
      JSB SYMCK       CHARACTER 
      DEF PLUS-1        BINARY OPERATOR?
      JMP *+4       NO
      CPA EXPOP     YES, '^' ?
      JMP FSC10     YES 
      JMP FSC6      NO
      CCB           ASSIGNMENT
      JSB SYMCK 
      DEF ASSOP-1     OPERATOR? 
      JMP FSC12     NO
      LDA .-2       YES, SET FLAG 
      STA SFLAG       TO SAY
      JMP FSC1          STORE OCCURRED
      SKP 
*                    *
**  END OF FORMULA  **
*                    *
      LDA TEMP+2    RETRIEVE CHARACTER
FSC14 CLB           RECORD
      STB SBPTR,I     END-OF-FORMULA
      CPB SSTAK,I   ALL LEFT PARENTHESES MATCHED? 
      JMP FSC,I     YES 
      JSB SERRS+23,I  NO
**                                 ** 
***  SAVE LOCAL VARIABLES OF FSC  *** 
**                                 ** 
* 
*  SAVING MSFLG, UFLAG, VAROP, GETPF, AND FSC MAKES FSC A 
*  RE-ENTRANT SUBROUTINE.  THEY ARE SAVED ON THE SYNTAX 
*  STACK BELOW THE ACTIVE SYNTAX BUFFER.  ON ENTRY (B)
*  CONTAINS THE NUMBER OF WORDS TO BE SAVED.
* 
#FRCR ISZ SSTAK     SAVE PREVIOUS '(' COUNT 
      ADB SSTAK     SUFFICIENT
      CMB             USER
      ADB LWAUS         SPACE 
      SSB                 LEFT? 
      JSB SERRS,I   NO
      LDB MSFLG     YES, SAVE 
      STB SSTAK,I     'MULTIPLE STORE'
      ISZ SSTAK         FLAG
      LDB UFLAG     SAVE
      STB SSTAK,I     'UNARY OPERATOR'
      ISZ SSTAK         FLAG
      LDB VAROP     SAVE
      STB SSTAK,I     VAROP 
      ISZ SSTAK         RETURN ADDRESS
      LDB GETPF     SAVE
      STB SSTAK,I     GETPF 
      ISZ SSTAK         RETURN ADDRESS
      LDB FSC       SAVE
      STB SSTAK,I     FSC 
      ISZ SSTAK         RETURN ADDRESS
      CCA           DISABLE 
      ADA SFLAG       SFLAG 
      STA SFLAG         VALUE 
      JMP FRCUR,I 
**                                 ** 
***  RESTORE FSC LOCAL VARIABLES  *** 
**                                 ** 
* 
*  INVERSE OF FRCUR.  (A) IS SAVED BUT (B) IS NOT.
* 
#FPOP STA TEMP+1    SAVE (A)
      LDB SSTAK     RESET 
      ADB .-6         SYNTAX STACK
      STB SSTAK         POINTER 
      INB           RESTORE 
      LDA 1,I         'MULTIPLE STORE'
      STA MSFLG         FLAG
      INB           RESTORE 
      LDA 1,I         'UNARY OPERATOR'
      STA UFLAG         FLAG
      INB           RESTORE 
      LDA 1,I         VAROP 
      STA VAROP         RETURN ADDRESS
      INB 
      DLD 1,I       RESTORE GETPF 
      STA GETPF       RETURN ADDRESS AND
      STB FSC           FSC RETURN ADDRESS
      ISZ SFLAG     RESTORE SFLAG VALUE 
      LDA TEMP+1    RESTORE (A) 
      JMP FPOP,I
      SPC 2 
**                                               ** 
***  SINGLE CHARACTER AND/OR FORMULA OPERATORS  *** 
**                                               ** 
* 
*  BITS 15-9 OF THE OCTAL WORD ARE THE OPERATOR CODE. 
*  BITS 3-0 ARE THE PRECEDENCE FOR FORMULA OPERATORS. 
*  THE ASCII WORD IS USED TO RECOGNIZE THE OPERATOR ON
*  INPUT AND TO PROVIDE THE PRINT NAME ON OUTPUT.  THE
*  ORDERING OF THE TABLE FACILITATES SEARCHING. 
* 
QUOTE OCT 1000      STRING DELIMITER
      ASC 1," 
COMMA OCT 2000      COMMA 
      ASC 1,, 
SEMI  OCT 3000      SEMICOLON 
      ASC 1,; 
HATCH OCT 4000      HATCH SIGN
      ASC 1,# 
UNMNC OCT 15000 
UNPLC OCT 14000 
RBOP  OCT 11000 
FN    ASC 1,NF
TO    ASC 1,TO
OF    ASC 1,OF
RPARN OCT 10001     RIGHT PARENTHESIS 
      ASC 1,) 
      OCT 11001     RIGHT BRACKET 
      ASC 1,] 
LBRAC OCT 12013     LEFT BRACKET
      ASC 1,[ 
      OCT 13013     LEFT PARENTHESIS
      ASC 1,( 
      OCT 14011     UNARY PLUS
      ASC 1,+ 
      OCT 15011     UNARY MINUS 
      ASC 1,- 
SCMMA OCT 16002     SUBSCRIPT SEPARATOR 
      ASC 1,, 
ASSOP OCT 17002     ASSIGNMENT OPERATOR 
      ASC 1,= 
PLUS  OCT 20007     ADDITION
      ASC 1,+ 
      OCT 21007     SUBTRACTION 
      ASC 1,- 
TIMES OCT 22010     MULTIPLICATION
      ASC 1,* 
      OCT 23010     DIVISION
      ASC 1,/ 
      OCT 24012     EXPONENTIATION
      ASC 1,^ 
RELOS OCT 25005     GREATER THAN
      ASC 1,> 
      OCT 26005     LESS THAN 
      ASC 1,< 
      OCT 27005     UNEQUAL 
      ASC 1,# 
      OCT 30005     EQUAL 
      ASC 1,= 
MATFN DEF MATFS 
MATIO DEF IOSTS 
      OCT 32004     AND 
DFLAG NOP 
      OCT 33003     OR
MSFLG NOP 
      OCT 34006     MINIMUM 
AEND  DEF EOFOP 
      OCT 35006     MAXIMUM 
SFLAG NOP 
      OCT 36005     UNEQUAL 
UFLAG NOP 
      OCT 37005     GREATER THAN OR EQUAL 
ARYAD NOP 
      OCT 40005     LESS TAAN OR EQUAL
ASTEP DEF STEP
      OCT 41011     NOT 
