EXPRESSION EVALUATION THE 'SCANNING' SUBROUTINE This subroutine is used to produce an evaluation result of the 'next expression'. The result is returned as the 'last value' on the calculator stack. For a numerical result, the last value will be the actual floating point number. However, for a string result the last value will consist of a set of parameters. The first of the five bytes is unspecified, the second and third bytes hold the address of the start of the string and the fourth and fifth bytes hold the length of the string. Bit 6 of FLAGS is set for a numeric result and reset for a string result. When a next expression consists of only a single operand, e.g. ... A ..., ... RND ..., ... A$ (4, 3 TO 7) ... , then the last value is simply the value that is obtained from evaluating the operand. However when the next expression contains a function and an operand, e.g. ... CHR$ A..., ... NOT A ... , SIN 1 ..., the operation code of the function is stored on the machine stack until the last value of the operand has been calculated. This last value is then subjected to the appropriate operation to give a new last value. In the case of there being an arithmetic or logical operation to be performed, e.g. ... A+B ... , A*B ..., ... A=B ... , then both the last value of the first argument and the operation code have to be kept until the last value of the second argument has been found. Indeed the calculation of the last value of the second argument may also involve the storing of last values and operation codes whilst the calculation is being performed. It can therefore be shown that as a complex expression is evaluated, e.g. ... CHR$ (T+A - 26*INT ((T+A)/26)+65)..., a hierarchy of operations yet to be performed is built up until the point is reached from which it must be dismantled to produce the final last value. Each operation code has associated with it an appropriate priority code and operations of higher priority are always performed before those of lower priority. The subroutine begins with the A register being set to hold the first character of the expression and a starting priority marker - zero - being put on the machine stack. 24FB SCANNING RST 0018,GET-CHAR The first character is fetched. LD B,+00 The starting priority marker. PUSH BC It is stacked. 24FF S-LOOP-1 LD C,A The main re-entry point. LD HL,+2596 Index into scanning function CALL 16DC,INDEXER table with the code in C. LD A,C Restore the code to A. JP NC,2684,S-ALPHNUM Jump if code not found in table. LD B,+00 Use the entry found in the table LD C,(HL) to build up the required address ADD HL,BC in HL, and jump to it. JP (HL) Four subroutines follow; they are called by routines from the scanning function table. The first one, the 'scanning quotes subroutine', is used by S-QUOTE to check that every string quote is matched by another one. 250F S-QUOTE-S CALL 0074,CH-ADD+1 Point to the next character. INC BC Increase the length count by one. CP +0D Is it a carriage return? JP Z, 1C8A,REPORT-C Report the error if so. CP +22 Is it another '"'? JR NZ,250F,S-QUOTE-S Loop back if it is not. CALL 0074,CH-ADD+1 Point to next character; set zero CP +22 flag if it is another '"'. RET Finished. The next subroutine, the 'scanning: two co-ordinates' subroutine, is called by S-SCREEN$, S-ATTR and S-POINT to make sure the required two co-ordinates are given in their proper form. 2522 S-2-COORD RST 0020, NEXT-CHAR Fetch the next character. CP +28 Is it a '('?