implement `print` and `goto`
parent
36ca9f1442
commit
6962bc331d
@ -1,32 +1,55 @@
|
|||||||
#lang ragg
|
#lang ragg
|
||||||
|
;; adapted from http://www.ittybittycomputers.com/IttyBitty/TinyBasic/TBuserMan.txt
|
||||||
|
|
||||||
basic-program : line*
|
basic-program : line*
|
||||||
|
|
||||||
line : CR | NUMBER statement CR | statement CR
|
line : NUMBER statement CR | statement CR | CR
|
||||||
| NUMBER statement | statement
|
|
||||||
|
|
||||||
statement : "PRINT" expr-list
|
statement : "PRINT" printlist
|
||||||
| "IF" expression relop expression "THEN" statement
|
| "PR" printlist
|
||||||
| "GOTO" expression
|
| "INPUT" varlist
|
||||||
| "INPUT" var-list
|
|
||||||
| "LET" var "=" expression
|
| "LET" var "=" expression
|
||||||
|
| var "=" expression
|
||||||
|
| "GOTO" expression
|
||||||
| "GOSUB" expression
|
| "GOSUB" expression
|
||||||
| "RETURN"
|
| "RETURN"
|
||||||
|
| "IF" expression relop expression "THEN" statement
|
||||||
|
| "IF" expression relop expression statement
|
||||||
|
;| "REM" commentstring ; todo: implement in tokenizer
|
||||||
| "CLEAR"
|
| "CLEAR"
|
||||||
| "LIST"
|
|
||||||
| "RUN"
|
| "RUN"
|
||||||
| "END"
|
| "RUN" exprlist
|
||||||
|
| "LIST"
|
||||||
|
| "LIST" exprlist
|
||||||
|
|
||||||
|
printlist : printitem [(":" | separator printlist)]
|
||||||
|
|
||||||
expr-list : (STRING | expression) ("," (STRING | expression) )*
|
printitem : expression | STRING
|
||||||
|
|
||||||
var-list : var ("," var)*
|
varlist: var ["," varlist]
|
||||||
|
|
||||||
expression : term (("+"|"-") term)*
|
exprlist : expression ["," exprlist]
|
||||||
|
|
||||||
term : factor (("*"|"/") factor)*
|
expression : [("+"|"-")] unsignedexpr
|
||||||
|
|
||||||
factor : var | NUMBER | (expression)
|
unsignedexpr : term [("+"|"-") unsignedexpr]
|
||||||
|
|
||||||
|
term : factor [("*"|"/") term]
|
||||||
|
|
||||||
|
factor : var
|
||||||
|
| number
|
||||||
|
| "(" expression ")"
|
||||||
|
| function
|
||||||
|
|
||||||
|
function : "RND(" expression ")"
|
||||||
|
| "USR(" exprlist ")"
|
||||||
|
|
||||||
|
number : NUMBER
|
||||||
|
|
||||||
|
separator : "," | ";"
|
||||||
|
|
||||||
var : UPPERCASE
|
var : UPPERCASE
|
||||||
|
|
||||||
relop : "<" (">"|"="|"ε") | ">" ("<"|"="|"ε") | "="
|
digit: DIGIT
|
||||||
|
|
||||||
|
relop : "<" [("="|">")] | ">" [("="|"<")] | "="
|
@ -1,2 +1,7 @@
|
|||||||
#lang br/basic
|
#lang br/basic
|
||||||
20 GOTO 10
|
10 PRINT "shit"
|
||||||
|
20 PRINT "bird"
|
||||||
|
25 PRINT "dork"
|
||||||
|
30 GOTO 10
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue