ECMA minimal BASIC(1978)より、構文規則(120行)です。
letter = A..Z
digit = 0..9
plain-string-character = [+-.] | digit | leter
quoted-string-character = [!#$%&'()*,/:;<=>?^_] | plain-string-character
unquoted-string-character = " " | plain-string-character
string-character = " | quoted-string-character
remark-string = string-character*
quoted-string = " quoted-string-character* "
unquoted-string = plain-string-character (unquoted-string-char plain-string-character)*
program = block* end-line
block = ( line | for-block )*
line = line-number statement end-of-line
end-of-line = \r | \n | :
end-line = line-number end-statement end-of-line
end-statement = END
statement = data-statement
| def-statement
| dimension-statement
| gosub-statement
| goto-statement
| if-then-statement
| input-statement
| let-statement
| on-goto-statement
| option-statement
| print-statement
| randomize-statement
| read-statement
| remark-statement
| restore-statement
| return-statement
| stop-statement
numeric-constant = sign? numeric-rep
sign = + | -
numeric-rep = significand exrad?
significand = integer .? | integer? fraction
integer = digit+
fraction = . digit+
exrad = E sign? integer
string-constant = quoted-string
variable = numeric-variable | string-variable
numeric-variable = simple-numeric-variable
| numeric-array-element
simple-numeric-variable = letter digit?
numeric-array-element = numeric-array-name subscript
numeric-array-name = letter
subscript ='(' numeric-expression (, numeric-expression)* ')'
string-variable = letter $
expression = numeric-expression | string-expression
numeric-expression = sign? term (sign term)*
term = factor ([*/] factor)*
factor = primary (^ primary)*
primary = numeric-variable
| numeric-rep
| numeric-function-ref
| '(' numeric-expression ')'
numeric-function-ref = numeric-function-name argument-list?
numeric-function-name = numeric-defined-function | numeric-supplied-function
argument-list = '(' argument ')'
argument = numeric-expression
string-expression = string-variable | string-constant
def-statement = DEF numeric-defined-function parameter-list? = numeric-expression
numeric-defined-function = FN letter
parameter-list = '(' parameter ')'
parameter = simple-numeric-variable
let-statement = numeric-let-statement | string-let-statement
numeric-let-statement = LET numeric-variable = numeric-expression
string-let-statement = LET string-variable = string-expression
goto-statement = GO ' '* TO line-number
if-then-statement = IF relational-expression THEN line-number
relational-expression = numeric-expression relation numeric-expression
| string-expression ( = | <> ) string-expression
relation = ( = | <> | < | > | >= | <=)
gosub-statement = GO ' '* SUB line-number
return-statement = RETURN
on-goto-statement = ON numeric-expression GO ' '* TO line-number (, line-number)*
stop-statement = STOP
for-block = for-line for-body
for-line = line-number for-statement end-of-line
for-statement = FOR control-variable = initial-value TO limit (STEP increment)?
control-variable = simple-numeric-variable
initial-value = numeric-expression
limit = numeric-expression
increment = numeric-expression
for-body = block next-line
next-line = line-number next-statement end-of-line
next-statement = NEXT control-variable
print-statement = PRINT print-list?
print-list = (print-item? print-separator)* print-item?
print-item = expression | tab-call
tab-call = TAB '(' numeric-expression ')'
print-separator = [,;]
input-statement = INPUT variable-list
variable-list = variable (, variable)*
read-statement = READ variable-list
restore-statement = RESTORE
data-statement = DATA data-list
data-list = datum (comma datum)*
datum = quoted-string | unquoted-string
dimension-statement = DIM array-declaration (, array-declaration)
array-declaration = numeric-array-name '(' bounds ')'
bounds = integer (, integer)?
option-statement = OPTION BASE (0|1)
randomize-statement = RANDOMIZE