21 BASIC Characters and Operators

This section lists all the ATOM BASIC special characters and operators. They are followed by a description of the character or operator, and its name enclosed in {} brackets. Lower case characters in <> brackets refer to the syntax definition in Chapter 26.

21.1 Special Character

  Line terminator {RETURN}

This character is used to terminate a statement or command, or a line input to the INPUT statement, and as the terminator for strings.

  Cancel input {CAN (CTRL-X)}

This character will, when typed from the keyboard, delete the current input buffer and give a new line.

  Escape {Esc}

This character, typed on the keyboard, will stop any BASIC program and return to direct mode. BASIC checks for escape at every statement terminator. Typing escape when in direct mode resets the screen to character mode.

The ESC key can be disabled from a program by executing:

#B000=10
  Separator {space}

This character is stored intact to allow formatting of programs. Space may be used anywhere except:
1. In control words.
2. After the # {hash} symbol.
3. Between line number and label.

It may be necessary to insert spaces to avoid ambiguity as, for example, in:

FORZ=V TOW STEPX

Here a separator character is needed between V and T, and similarly between W and S, to eliminate the possibility of a function called VTOWSTEP.

" String delimiter {double quote}

This character is used as the delimiting character whenever a string is to be part of a BASIC statement (i.e. everywhere except when inputting strings with an INPUT statement). If you wish to include in a string it should be written "". The simple rule for valid strings is that they have an even number of "characters in them.

' New line {single quote}

This character may be used in PRINT and INPUT statements to generate a new line by generating both CR and LF codes. The value of COUNT will be set to zero.

()   {round brackets}

These characters provide a means of overriding the normal arithmetic priority of the operators in an <EXPRESSION>. The contents of brackets are worked out first, starting with the innermost brackets.

, Separator {comma}

This character is used to separate items in PRINT and INPUT statements.

.   {stop}

This character is used to allow a shorter representation for some of the key-words, thus using less memory space to store the program.

; Statement terminator {semi -colon}

This character is the statement terminator used in multi-statement lines.

@ Numeric field width {at}

This character is a variable which controls the PRINT statement. It specifies the number of spaces in which a number will be printed, right justified. If the field size is too small to print the number, the number is printed in full without any extra spaces; thus field sizes of 0 and 1 give the same result of minimum-width printing. The - siqn is printed in front of a negative number and counts towards the number of characters in the number. On initial entry into BASIC, any error, or following use of the LIST statement or assembler, @ is set to 8. Example:

  @=5;PRINT1,12,123,1234,12345,123456'
1   12  123 123412345123456
a -- z Labels  

These characters provide a very fast means of transferring control with the GOTO and GOSUB statements. A line may be labelled by putting one of a-z immediately after the line number (no blanks are allowed before the label). Transfer to a labelled line is achieved by a GOTO or GOSUB statement followed by the required label. Example:

      10a PRINT"looping"'
      20 GOTO a
>RUN
looping
looping
looping

21.2 Operators

! Word indirection {pling}

This character provides word indirection. It can be both a binary and a unary operator and appear on the left-hand side of an equal siqn as well as in <EXPRESSION>s.

As a unary operator on the LEFT of an equals sign it takes a <FACTOR> as an argument and will treat this as an address. The <EXPRESSION> on the right of the equals sign is evaluated and then stored, startinq with the least siqnificant byte, in the four locations starting at this address. Example:

!A=#12345678

will store values in memory as follows:

78 56 34 12
A A+1 A+2 A+3

As a binary operator on the LEFT of an equals sign it takes two arguments; a <VARIABLE> on the left and a <FACTOR> on the right. These two values are added together to create the address, and the value is stored at this address as above. Example:

A!B=#12345678

As a unary operator in an <EXPRESSION> it takes a <FACTOR> as an argument and will treat this as an address. The value is that contained in the four bytes at this address. For example, if the contents of memory are as follows:

18 00 00 00
A A+1 A+2 A+3

Then the value printed by

PRINT !A

will be 24 (decimal).

As a binary operator in an <EXPRESSION> it takes two arguments, a <FACTOR> on either side. The sum of these two values is used as the address, as above. Example:

PRINT A!B
# Hexadecimal constant {hash or pound}

This character denotes the start of a hexadecimal value in <FACTOR>. It cannot be followed by a space and there is no check made for overflow of the value. The valid hexadecimal characters are 0 to 9 and A to F.

$ String pointer {dollar}

This character introduces a pointer to a string; whenever it appears it can be followed by an <EXPRESSION>. In a PRINT statement, if the pointer is less than 256, the ASCII character corresponding to the value of the pointer will be printed. Dollar can be used on the left of an equals sign as well as anywhere a string can be used. If the only choice allowed is either a dollar or a string in double quotes, then it is possible to omit the dollar. Strings may contain up to 255 characters. Examples:

IF$A=$B........    string equality test
IF$A="FRED"....    string equality test
$A="JIM".......    move string JIM to where A is pointing
$A=$B..........    copy B's string to where A points
PRINT$A........    print the string A is pointinq at
PRINT$A+1......    print the string (A+1) is pointing at
PRINT$64.......    print ASCII character 64 i.e. @
% Remainder {percent}

This character is the operation of signed remainder between two values. Its form is <FACTOR a>%<FACTOR b>. The sign of the result is the same as the sign of the first operand.

& Hexadecimal/AND {ampersand}

This character has two distinct uses:

1. To print hexadecimal values in the PRINT statement. Its form here is as a prefix in front of the particular print item which is to be printed in hexadecimal.

2. As the operation of bitwise logical AND between two values. Its form here is <FACTOR a> & <FACTOR b> and the result is a 32 bit word, each bit of which is a logical AND between corresponding bits of the operands.

* Multiply {star}

This character is the operation of signed multiplication between two 32 bit values. Its form is <FACTOR a> * <FACTOR b>.

+ Add {plus}

This character has two similar uses:

1. As the unary operation "do not change sign". Its form here is +<FACTOR>.

2. As the operation of addition between two 32 bit values. Its form here is <TERM a> + <TERM b>.

- Subtract (minus}

This character has two similar uses:

1. As the unary operation of negate. Its form here is -<FACTOR>, and the result is 0 - <FACTOR>.

2. As the operation of subtraction between two 32 bit values. Its form here is <TERM a> -<TERM b> and the result is found by subtracting <TERM b> from <TERM a>.

/ Divide {slash}

This character is the operation of signed division between two 32 bit values. Its form is <FACTOR a>/<FACTOR b> and the result is found by dividing <FACTOR a> by <FACTOR b>.

: Exclusive OR {colon}

This character is the operation of bitwise logical exclusive-OR between two 32 bit <TERM>s. Its form is <TERM a>:<TERM b> and the result is a 32 bit word each bit of which is the exclusive-OR of corresponding bits in <TERM a> and <TERM b>.

< Less-than {left trianqular bracket}

This character is the relational operator "less than" betveen two <EXPRESSION>s. Its form is <EXPRESSION a> < <EXPRESSION b> and it returns a truth value, of 'true' if <EXPRESSION a> is less than <EXPRESSION b> and 'false' otherwise, which can be tested by IF and UNTIL statements.

= Equals {equal}

This character has two uses:

l. As the relational operator "equal to" between two <EXPRESSION>s. Its form is <EXPRESSION a> = <EXPRESSION b> and it returns a truth value, of 'true' if <EXPRESSION a> is equal to <EXPRESSION b> and 'false' otherwise, which can be tested by IF and UNTIL statements.

2. As the assignment operation "becomes". The object on the left hand side is assigned the value of the right hand side. There are three similar uses of this:

1. Arithmetic                                Example:
       <VARIABLE>=<EXPRESSION>                 A=2
       <VARIABLE>!<FACTOR>=<EXPRESSION>        A!J=3
       <VARIABLE>?<FACTOR>=<EXPRESSION>        A?J=4
       !<FACTOR>=<EXPRESSION>                  !J=5
       ?<FACTOR>=<EXPRESSION>                  ?J=6
       <ARRAY element>=<EXPRESSION>            W(1)=7
2. String movement
       $<EXPRESSION>=<STRING right>        $A="FRED"
3. FOR statement
       FOR<VARIABLE>=<EXPRESSION>....         FOR A=O TO..
> Greater-than {right triangular bracket}

This character is the relational operator "greater than" between two <EXPRESSION>s. Its form is <EXPRESSION a> > <EXPRESSION b> and it returns a logical value, of 'true' if <EXPRESSION a> is greater than <EXPRESSION b> and 'false' otherwise, which can be tested by IF and UNTIL statements.

? Byte indirection {query}

This character provides byte indirection. It can be either a binary or a unary operator and appear on the left-hand of an equals sign as well as in <EXPRESSION>s.

As a unary operator on the LEFT of an equals sign it takes a <FACTOR> as an argument and will treat this as an address; the <EXPRESSION> on the right of the equals sign is evaluated and its least significant byte is stored at that address. Example:

?A=#12345678

will store into memory as follows:

78
A

As a binary operator on the LEFT of an equals sign it takes two arguments, a <VARIABLE> on the left and a <FACTOR> on the right. These two values are added together to create the address where the value will be stored as above. Example:

A?B=#12345678

As a unary operator in an <EXPRESSION> it takes a <FACTOR> as an argument and will treat this as an address; the value is a word whose most significant three bytes are zero and whose least significant byte is the contents of that address. Example:

PRINT ?A

As a binary operator in an <EXPRESSION>, it takes two arguments, a <FACTOR> on either side. The sum of these two values is the address used as above. Example :

PRINT A?B
\
OR {inverted backslash}

This character is the binary operation of bitwise logical OR between two 32 bit <TERM>s. Its form is <TERM a>g<TERM b> and the result is a 32 bit word each bit of which is an or operation between corresponding bits of <TERM a> and <TERM b>.

<> Not equal {left and right triangular brackets}

This symbol is the relational operator "not equal to" between two <EXPRESSION>s. Its form is <EXPRESSION a> <> <EXPRESSION b> and it returns a truth value, of 'true' if <EXPRESSION a> is not equal to <EXPRESSION b> and 'false' otherwise, which can be tested by IF and UNTIL statements.

<= Less or equal (left triangular bracket, equal}

This symbol is the relational operator "less than or equal" between two <EXPRESSION>s. Its form is <EXPRESSION a> <= <EXPRESSION b> and it returns a truth value, of 'true' if <EXPRESSION a> is less than or equal to <EXPRESSION b> and 'false' otherwise, which can be tested by IF and UNTIL statements.

>= Greater or equal {right triangular bracket, equal}

This symbol is the relational operation "greater than or equal to" between two <EXPRESSION>s. Its form is <EXPRESSION a> >= <EXPRESSION b> and it returns a truth value, of 'true' if <EXPRESSION a> is greater than or equa1 to <EXPRESSION b> and false otherwise, which can be tested by IF and UNTIL statements.

Next chapter