You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket/br/demo/basic/parser.rkt

63 lines
1.3 KiB
Racket

#lang ragg
;; adapted from http://www.ittybittycomputers.com/IttyBitty/TinyBasic/TBuserMan.txt
8 years ago
;; MS Basic extensions
;; http://www.atariarchives.org/basicgames/showpage.php?page=i12
8 years ago
;; games
;; http://www.vintage-basic.net/games.html
8 years ago
;; chipmunk basic
;; http://www.nicholson.com/rhn/basic/basic.man.html
8 years ago
8 years ago
basic-program : [CR] lines [CR]
8 years ago
8 years ago
lines : INTEGER statements [CR | CR lines]
8 years ago
8 years ago
statements : statement [":" statements]
8 years ago
statement : "CLOSE" "#" INTEGER
| "END"
| "FOR" ID "=" expr "TO" expr ["STEP" expr]
| "GOTO" expr
| "IF" expr "THEN" (statement | expr) ; change: add expr
| "INPUT" id-list
| ["LET"] ID "=" expr ; change: make "LET" opt
| "NEXT" id-list
| "PRINT" printlist
| "REM" STRING
8 years ago
id-list : ID ["," id-list]
8 years ago
value-list : value ["," value-list]
8 years ago
constant-list : constant ["," constant-list]
8 years ago
integer-list : INTEGER ["," integer-list]
8 years ago
expr-list : expr ["," expr-list]
8 years ago
printlist : [expr [";" printlist]]
8 years ago
expr : and-expr ["OR" expr]
8 years ago
and-expr : not-expr ["AND" and-expr]
8 years ago
not-expr : ["NOT"] compare-expr
8 years ago
compare-expr : add-expr [("=" | "<>" | "><" | ">" | ">=" | "<" | "<=") compare-expr]
8 years ago
add-expr : mult-expr [("+" | "-") add-expr]
8 years ago
mult-expr : negate-expr [("*" | "/") mult-expr]
8 years ago
negate-expr : ["-"] power-expr
power-expr : [power-expr "^"] value
value : "(" expr ")"
| ID ["(" expr-list ")"]
| constant
constant : INTEGER | STRING | REAL