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