26 Syntax Definition

This syntax definition is written in B.N.F., or Backus-Naur Form, with some additions. In the places where a proper definition in B.N.F. would be far too long, a description has been used. The rules are:

Things in triangular <> brackets are defined things, "syntactic entities", everything else is itself

The ::= symbol is read as "is defined".
The | sign is read as OR: one of the alternatives must be true.
Concatenation of things is read as "followed by".
The ^ sign is read as "any number of".
The {} brackets allow concatenations to be grouped together.

26.1 BASIC Syntax Definition

26.1.1 Basic Symbols

! " # $ % & ' ( ) * + , - . / O 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C
D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l
m n o p q r s t u v w x y z [ \ <> <= >= @@ AA BB CC CH DD DO EE FF GG
HH II IF JJ KK LL MM NN 00 OR PP QQ RR SS TO TT UU VV WW XX YY ZZ ABS
AND DIM END EXT FIN FOR GET LEN LET NEW OLD PTR PUT REM RND RUN TOP
BGET BPUT DRAW FOUT GOTO LINK LIST LOAD MOVE NEXT PLOT SAVE SGET SHUT
SPUT STEP THEN WAIT CLEAR COUNT GOSUB INPUT PRINT UNTIL RETURN

No multi-character basic symbols may include blanks; otherwise blanks may be used freely to improve the readability of the program. The character '.' can be used to provide a shorter representation of all multi-character basic symbols

<ASCIIC>::={ascii characters excluding carriage return}
<DIGIT>::=0|1|2|3|4|5|6|7|8|9
<HEX digit>::=<DIGIT>|A|B|C|D|E|F
<POSITIVE number>::=<DIGIT><DIGIT>^
      such that <POSITIVE number> is less than 2147483648
<HEX number>::=<HEX digit><HEX digit>^
<INTEGER size field>::=@
<P-VARIABLE>::=<INTEGER size field>|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q
          |R|S|T|U|V|W|X|Y|Z
<VARIABLE>::=<P-VARIABLE>{character which is not <P-VARIABLE> or .}
<ARRAY name>::=@@|AA|BB|CC|DD|EE|FF|GG|HH|II|JJ|KK|LL|MM|NN|OO|PP|QQ
          |RR|SS|TT|UU|VV|WW|XX|YY|ZZ
<LABEL>::=a|b|c|d|e|f|q|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z
<CONJUNCTION>::=AND|OR
<RELATION operation>::= < | > | <= | >= | = | <>
<EXPRESSION operator>::=+|-|\|:
<TERM operator>::=*|/|%|&|!|?
<FACTOR>::=+<UNARY plus>|-<UNARY plus>|<UNARY plus>
<UNARY plus>::=<VARIABLE>|<POSITIVE number>|#<HEX number>|
          (<TESTABLE expression>)|!<FACTOR>|?<FACTOR>)TOP|COUNT
          |RND|ABS<FACTOR>|LEN<FACTOR>|CH<STRING right>
          |PTR<FACTOR>|EXT<FACTOR>|GET<FACTOR>|BGET<FACTOR>|
          FIN<STRING right>|FOUT<STRING right>|
          <ARRAY name><FACTOR>
<TERM>::=<FACTOR>{<TERM operation><FACTOR>}^
<EXPRESSION>::=<TERM>{<EXPRESSION operator><TERM>}^
<RELNL expression>::=<EXPRESSION>|<EXPRESSION><RELATION operation>
          <EXRESSION>|$<EXPRESSION>=<STRING right>
<TESTABLE expression>::=<RELNL expression>{<CONJUNCTION>
          <RELNL expression>}^
<DELIMIT quote>::="{any ascii character not a "}
<STRING right>::=<EXPRESSION>|$<EXPRESSION>|"<ASCIIC>^<DELIMIT quote>
<SD>::=<STATEMENT delimiter>::={carriage return}|;
<WORKING let>::={{{<VARIABLE>|!<FACTOR>|?<FACTOR>|<VARIABLE>!<FACTOR>|
          <VARIABLE>?<FACTOR>}=<EXPRESSION>}|$<EXPRESSION>=
          <STRING right>}<SD>
<LET statement>::=LET<WORKING let><SD>|<WORKING let><SD>
<VECTOR statement>::=<ARRAY name><FACTOR>=<EXPRESSION>
<PRINTABLE string>::={'|"<ASCIIC>^<DELIMIT quote>}^
<INPUT section>::=<PRINTABLE string>{<VARIABLE>|$<EXPRESSION>|{null}}
<INPUT statement>::=INPUT<INPUT section>{,<INPUT section>}^<SD>
<RETURN statement>::=RETURN<SD>
<NEW command>::=NEW<SD>
<OLD statement>::=OLD<SD>
<LINK statement>::=LINK<FACTOR><SD>
<OS statement>::=*<ASCIIC>^
<PLOT statement>::=PLOT<FACTOR>,<FACTOR>,<FACTOR><SD>
<DRAW statement>::=DRAW<FACTOR>,<FACTOR><SD>
<MOVE statement>::=MOVE<FACTOR>,<FACTOR><SD>
<CLEAR statement>::=CLEAR<FACTOR><SD>
<WAIT statement>::=WAIT<SD>
<GO entity>::=<LABEL>|<FACTOR>
<GOTO statement>::=GOTO<GO entity><SD>
<GOSUB statement>::=GOSUB<GO entity><SD>
<END statement>::=END<SD>
<ENTER statement assembler>:=[
<DO statement>::=DO
<UNTIL statement>::=UNTIL<TESTABLE expression><SD>
<NEXT statement>::=NEXT<SD>|NEXT<VARIABLE><SD>
<HALF for>::=FOR<VARIABLE>=<EXPRESSION>TO<EXPRESSION>
<FOR statement>::=<HALF for><SD>|<HALF for><STEP<expression><SD>
<DIM section>::=<VARIABLE)<FACTOR>|<ARRAY name><FACTOR>
<DIM statement>::=DIM<DIM section>{,<DIM section>}^<SD>
<SAVE statement>::=SAVE<STRING right><SD>
<LOAD command>::=LOAD<STRING right><SD>
<RUN statement>::=RUN<SD>
<LIST command>::=LIST<SD>|LIST<POSITIVE number><SD>|
          LIST,<POSITIVE number><SD>|LIST<POSITIVE number>,<SD>|
          LIST<POSITIVE number>,<POSITIVE number><SD>
<IF statement>::=IF<TESTABLE expression>{THEN<STATEMENT>|<STATEMENT>}
<PRINT comma>::={nothing, if possible}|,
<PRINT statement>::=PRINT{<PRINTABLE string>{<EXPRESSION>|
          $<EXPRESSION>|{nothing}}<PRINT comma>}^<SD>
<ENTER command line>::=<POSITIVE number><ASCIIC>"(carriage return}
<PUT statement>::=PUT<FACTOR>,<EXPRESSION><SD>
<BPUT statement>::=BPUT<FACTOR>,<EXPRESSION><SD>
<SPUT statement>::=SPUT<FACTOR>,<STRING right><SD>
<SGET statement>::=SGET<FACTOR>,<EXPRESSION><SD>
<PTR statement>::=PTR<FACTOR>=<EXPRESSION><SD>
<NULL statement>::=<SD>

26.2 Assembler Syntax Definition

This uses the same syntax as Section 26.1, and refers to some of the syntactic entities given there. Basic symbols may not be abbreviated; spaces may be used freely to improve readability.

26.2.1 Basic Symbols

( ) , : @ A X Y \ ] ADC AND ASL BCC BCS BEQ BIT BMI BNE BPL BRK BVC
BVS CLC CLD CLI CLV CMP CPX CPY DEC DEX DEY EOR INC INX INY JMP JSR
LDA LDX LDY LSR NOP ORA PHA PHP PLA PLP ROL ROR RTI RTS SBC SEC SED
SEI STA STX STY TAX TAY TSX TXS TXA TXS TYA
<SET statement label>::=<TWO chars>:<LABEL name><ASSEMBLER statement>
<COMMENT statement>::=<two chars>\<comment field>
<back to basic>::=]
<empty statement>::=<two chars><sd>
<two chars>::=<asciic>|<asciic><asciic>|{no character at all}
<comment field>::={ascii until <sd>}
<immed>::=@<expression>
<indexX>::=<expression>,X
<indexY>::=<expression>,Y
<groupl>::=<indexX>|<indexY>|(<indexX>)|(<expression>),Y|<expression>
<branch>::={BCC|BCS|BEQ|BMI|BNE|BPL|BVC|BVS}<expression>
<memory to A>::=ADC|AND|CMP|EOR|LDA|ORA|SBC{<groupl>(<immed>}
<A to memory>::=STA<groupl>
<single byte A>::={ASL|LSR|ROL|ROR}A
<single byte>::=<single byte A>|BRK|CLC|CLD|CLI|CLV|DEX|DEY|INX|INY
          |NOP|PHA|PHP|PLA|PLP|RTI|RTS|TAX|TAY|TSX|TXA|TXS|TYA
<read modify write>::={ASL|DEC|INC|LSR|ROL|ROR}{<indexX>|<expression>}
<bit>::=BIT<expression>
<cp>.:={CPX|CPY}{<immed>(<expression>}
<jmp>::=JMP{<expression>|(<expression>)}
<jsr>::=JSR<expression>
<ldx>::=LDX{<immmed>|<indexY>|<expression>}
<1dy>::=LDY{<immmed>|<indexX>|<expression>}
<stx>::=STX{<indexY|<expression>}
<sty>::=STY{<indexX>|<expression>}
<assembler statement>::={<branch>|<memory to A>|<A to memory>
          |<single byte>|<read modify write>|<bit>|<cp>|<jmp>|<jsr>
          |<1dx>|<ldy>|<stx>|<sty>|<comment field>

Next chapter