Files
tsvm/assets/tbas/syntax.txt
2020-12-12 00:17:50 +09:00

89 lines
2.6 KiB
Plaintext

line = linenumber , stmt , {":" , stmt} ;
linenumber = digits ;
stmt =
"IF" , if_conditional , "THEN" , stmt , ["ELSE" , stmt] ; //TODO
| "DEFUN" , [ident] , "(" , [ident , {" , " , ident}] , ")" , "=" , expr //TODO
| "ON" , if_conditional , ident , if_conditional , {"," , if_conditional}
| "(" , stmt , ")"
| expr ;
expr = // ALL TODO
"(" , expr , ")"
| function_call , op , function_call
| op_uni , function_call
| function_call ; //TODO
function_call = // ALL TODO
"IF" , if_conditional , "THEN" , expr , ["ELSE" , expr] ; //TODO
| lit
| ident , "(" , [expr , {argsep , expr} , [argsep]] , ")"
| ident , expr , {argsep , expr} , [argsep] ;
if_conditional =
"(" , if_conditional , ")"
| function_call , op - "=" , function_call
| op_uni , function_call
| function_call ; //TODO
(* don't bother looking at these, because you already know the stuff *)
function = lit ;
argsep = ","|";" ;
ident = alph , [digits] ;
lit = alph , [digits] | num | string ; (* example: "MyVar_2" *)
op = "^" | "*" | "/" | "MOD" | "+" | "-" | "<<" | ">>" | "<" | ">" | "<="
| "=<" | ">=" | "=>" | "==" | "<>" | "><" | "BAND" | "BXOR" | "BOR"
| "AND" | "OR" | "TO" | "STEP" | "!" | "~" | "#" | "=" ;
op_uni = "-" | "+" ;
alph = letter | letter , alph ;
digits = digit | digit , digits ;
hexdigits = hexdigit | hexdigit , hexdigits ;
bindigits = bindigit | bindigit , bindigits ;
num = digits | digits , "." , [digits] | "." , digits
| ("0x"|"0X") , hexdigits
| ("0b"|"0B") , bindigits ; (* sorry, no e-notation! *)
visible = ? ASCII 0x20 to 0x7E ? ;
string = '"' , (visible | visible , stringlit) , '"' ;
letter = "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" | "_" ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
hexdigit = "A" | "B" | "C" | "D" | "E" | "F" | "a" | "b"
| "c" | "d" | "e" | "f" | "0" | "1" | "2" | "3" | "4" | "5" | "6"
| "7" | "8" | "9" ;
bindigit = "0" | "1" ;
(* all possible token states: lit num op bool qot paren sep *)
IF (type: function, value: IF)
1. cond
2. true
[3. false]
DEFUN (type: function, value: DEFUN)
1. funcname
1. arg0
[2. arg1]
[3. argN...]
2. stmt
ON (type: function, value: ON)
1. varname
2. functionname
3. arg0
[4. arg1]
[5. argN...]
FUNCTION_CALL (type: function, value: PRINT or something)
1. arg0
2. arg1
[3. argN...]