; ABML Atari Basic Meta Language
; ABML is a custom implementation of BNF
;
; This definition of the ABML grammar of Atari Basic has been modified
; from the original because of the different techniques and algorythms
; used in the Basic4Android ABML parser
;
; ABML Tokens
;
; ; Remark
; identifier Terminal symbol, parsed literally
; <identifier> Nonterminal definition name
; [identifier] External subroutine call (increases parsing speed)
; = Nonterminal definition assignment
; "identifier" Terminal symbol when reserved characters are used
; | AMBL alternative - OR
; # End of nonterminal definition
; & Accept to this point, even if failed
; (allows for multiple nonterminals)
; $ Hex character, 2 digit (not part of the original ABML definition)
;
; Expression
; Expression definition
<EXP> = (<EXP>)<NOP>|<UNARY><EXP>|<NV><NOP>#
; Unary operator
<UNARY> = +|.|NOT#
; Numeric value
<NV> = <NFUN>|<NVAR>|[TNCON]|<STCOMP>#
; Numeric operation (optional)
<NOP> = <OP><EXP>|&#
; Numeric operators
<OP> = +|-|*|/|"<="|">="|"<>"|"<"|">"|"="|AND|OR#
; Numeric variable
<NVAR> = [TNVAR]<NMAT>#
; Numeric array matrix optional [(x1[,x2])]
<NMAT> = (<EXP><NMAT2>)|&#
; Optional second matrix (x2 in above)
<NMAT2> = ,<EXP>|&#
; Numeric function
<NFUN> = <NFNP><NFP>|<NFSP><SFP>|<NFUSR>#
; Numeric function parameter
<NFP> = (<EXP>)#
; String function parameter
<SFP> = (<STR>)#
; String compare expression
<STCOMP> = <STR><SOP><STR>#
; String value
<STR> = <SFUN>|<SVAR>|[TSCON]#
; String function
<SFUN> = <SFNP><NFP>#
; String variable
<SVAR> = [TSVAR]<SMAT>#
; String variable matrix (optional)
<SMAT> = (<EXP><SMAT2>)|&#
; Optional second string variable matrix value
<SMAT2> = ,<EXP>|&#
; String expression operators
<SOP> = "<="|"<>"|">="|"<"|">"|"="#
; Numeric or string variable
<NSVAR> = <NVAR>|<SVAR>#
; One or more numeric/string variable parameter list
<NSVRL> = <NSVAR><NSV2>|&#
<NSV2> = ,<NSVRL>|&#
; One or more comma separated expression parameters
<EXPL> = <EXP><EXPL1>#
<EXPL1> = ,<EXPL>|&#
; Numeric array / string var matrix
<NSMAT> = [TNVAR](<EXP><NMAT2>)|[TSVAR](<EXP>)#
; One or more comma separated numeric array / string variable definitions
<NSML> = <NSMAT><NSML2>|&#
<NSML2> = ,<NSML>|&#
; One or more comma separated expression parameters
; (seems to duplicate <EXPL><EXPL1>
; External subroutine calls (written in machine language)
[TNVAR] Check for valid numeric variable name
[TSVAR] Check for valid string variable name
[TNCON] Check for valid numeric constant
[TSCON] Check for valid string constant
[EIF] Check for valid statement after ELSE
[EREM] Check for valid REMark string
[EDATA] Check for valid DATA sequence
; Functions
; Numeric function, numeric parameter
<NFNP> = ATN|COS|PEEK|SIN|RND|FRE|EXP|LOG|CLOG|SQR|SGN|ABS|INT|PADDLE|
STICK|PTRIG|STRIG#
; Numeric function, string parameter
<NFSP> = ASC|VAL|ADR|LEN#
; String function, numeric parameter
<SFNP> = STR|CHR#
; USR(...) function where 1 or more parameters are possible
<NFUSR> = USR(<PUSR>)#
<PUSR> = <EXP><PUSR1>#
<PUSR1> = ,<PUSR>|&#
; Statement support
; End of statement - CR or :
<EOS> = :|$0D#
; <EOS2> is a duplicate of <EOS> - don't know why...
<EOS2> = <CEOS>|<CCR>#
<CEOS> = :#
<CCR> = $0D#
; Not sure why this is here...
<TEXP> = <EXP>,<EXP>#
; Statement commands (in the same order as in the Atari Basic Source Book)
<STMT> = <PUT>|<MULT1>|<MULT2>|<LET>|<FOR>|<LOCATE>|<GET>|<NEXT>|<RESTORE>|
<INPUT>|<READ>|<PRINT>|<LPRINT>|<XIO>|<OPEN>|<CLOSE>|<MULT3>|<RUN>|
<LIST>|<STATUS>|<MULT4>|<SOUND>|<MULT5>|<DIM>|<ON>|<IF>|<REM>|<DATA>#
; PUT
<PUT> = PUT<D1>,<EXP><EOS>#
; Statements with a single expression argument
; TRAP, GOTO, GOSUB, GRAPHICS, COLOR
<MULT1> = <MULT1A><EXP><EOS>#
<MULT1A> = TRAP|GOTO|GOSUB|GRAPHICS|COLOR#
; Statements with no arguments
; CSAVE, CLOAD, DOS, CLR, RETURN, END, STOP, POP, NEW, BYE, CONT, DEG, RAD
<MULT2> = <MULT2><EOS>#
<MULT2A> = CSAVE|CLOAD|DOS|CLR|RETURN|END|STOP|POP|NEW|BYE|CONT|DEG|RAD#
' LET - the LET keyword itself is optional in the assignment statement
<LET> = <LET2><LET3>#
<LET2> = LET|&#
<LET3> = <NVAR>=<EXP><EOS>|<SVAR>=<STR><EOS>#
; FOR
<FOR> = FOR[TNVAR]=<EXP>TO<EXP><FSTEP><EOS>#
<FSTEP> = STEP<EXP>|&#
; LOCATE
<LOCATE> = LOCATE<EXP>,<EXP>,[TNVAR]<EOL>#
; GET
<GET> = GET<D1>,[TNVAR]#
; NEXT
<NEXT> = NEXT[TNVAR]<EOS>#
; RESTORE
<RESTORE> =RESTORE<EXP><EOS>|<EOS>#
; INPUT
<INPUT> = INPUT<OPD><READ>#
<OPD> = <D1>,|&#
; READ
<READ> = READ<NSVRL><EOS>#
; PRINT
<PRINT> = PRINT<PRINT1>#
<PRINT1> = <D1><EOS>|<OPD><LPRINT1>#
<D1> = <CPND><EXP>#
<CPND> = "#"#
; LPRINT
<LPRINT> = LPRINT<LPRINT1>#
<LPRINT1> = <PR1><EOS>#
<PR1> = <PEL>|<PSL><PR2>|&#
<PR2> = <PEL>|&#
<PEL> = <PES><PELA>#
<PES> = <EXP>|<STR>#
<PELA> = <PSL><PEL>|&#
<PSL> = <PS><PSLA>#
<PSLA> = <PSL>|&#
<PS> = ,|,#
; XIO
<XIO> = XIO<AEXP>,<DS2><FS>,<AEXP><EOS>#
<FS> = <STR># ;Filespec
; OPEN
<OPEN> = OPEN<D1>,<EXP>,<EXP>,<FS>,<EOS>#
; CLOSE
<CLOSE> = CLOSE<D1><EOS>#
; Statements with a single filename string parameter
; ENTER, LOAD, SAVE
<MULT3> = <MULT3A><FS><EOS>#
<MULT3A> = ENTER|LOAD|SAVE#
; RUN
<RUN> = RUN<RUN1>#
<RUN1> = <FS><EOS2>|<EOS2>#
; LIST
<LIST> = LIST<LIST1>#
<LIST1> = <FS><EOS>|<FS><LIS>|<LIS>#
<LIS> = <L1><EOS>#
<L1> = <EXP><L2>|&#
<L2> = ,<EXP>|&#
; STATUS
<STATUS> = STATUS<STAT><EOS>#
<STAT> = <D1>,<NVAR>#
; Statements with a drive designation and a single numeric variable
; NOTE, POINT
<MULT4> = <MULT4A><STAT>,<NVAR><EOS2>#
<MULT4A> = NOTE|POINT#
; SOUND
<SOUND> = SOUND<EXP>,<EXP>,<EXP>,<EXP><EOS>#
; Statements with two expression parameters
; POKE, PLOT, POS, DRAWTO
<MULT5> = <MULT5A><EXP>,<EXP><EOS>#
<MULT5A> = POKE|PLOT|POS|DRAWTO#
; DIM
<DIM> = DIM<NSML><EOS>#
; ON (as in ON GOSUB and ON GOTO)
<ON> = ON<EXP><ON1><EXPL><EOS>#
<ON1> = GOTO|GOSUB#
; IF
<IF> = IF<EXP>THEN<IFA><EOS>#
<IFA> = [TNCON]|[EIF]#
; REM
<REM> = [EREM]#
; DATA
<DATA> = [EDATA]#