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.
45 lines
891 B
Racket
45 lines
891 B
Racket
9 years ago
|
#lang brag
|
||
9 years ago
|
|
||
9 years ago
|
basic-program : line*
|
||
9 years ago
|
|
||
9 years ago
|
line: NUMBER statement [/":" statement]*
|
||
9 years ago
|
|
||
9 years ago
|
statement : "def" id /"(" id /")" /"=" expr
|
||
9 years ago
|
| "dim" id-expr [/"," id-expr]*
|
||
9 years ago
|
| "end" | "stop"
|
||
9 years ago
|
| "gosub" expr
|
||
|
| "goto" expr
|
||
9 years ago
|
| "on" expr ("gosub" | "goto") expr [/"," expr]*
|
||
9 years ago
|
| "if" expr /"then" (statement | expr) [/"else" (statement | expr)]
|
||
9 years ago
|
| "input" [print-list /";"] id [/"," id]*
|
||
9 years ago
|
| [/"let"] id-expr "=" expr
|
||
9 years ago
|
| "print" [print-list]
|
||
|
| "return"
|
||
9 years ago
|
| "for" id /"=" expr /"to" expr [/"step" expr]
|
||
9 years ago
|
| "next" [id]
|
||
9 years ago
|
|
||
9 years ago
|
print-list : expr [[";"] [print-list]]
|
||
9 years ago
|
|
||
9 years ago
|
expr : comp-expr [("and" | "or") expr]
|
||
9 years ago
|
|
||
|
comp-expr : sum [("=" | ">" | ">=" | "<" | "<=" | "<>") comp-expr]
|
||
9 years ago
|
|
||
9 years ago
|
sum : [sum ("+" | "-")] product
|
||
9 years ago
|
|
||
9 years ago
|
product : [product ("*" | "/")] power
|
||
|
|
||
|
power : value [/"^" value]
|
||
9 years ago
|
|
||
9 years ago
|
@value : id-val
|
||
9 years ago
|
| id-expr
|
||
9 years ago
|
| /"(" expr /")"
|
||
9 years ago
|
| number
|
||
9 years ago
|
| STRING
|
||
9 years ago
|
|
||
9 years ago
|
id-expr : id [/"(" expr [/"," expr]* /")"]
|
||
9 years ago
|
|
||
|
@id : ID
|
||
9 years ago
|
|
||
9 years ago
|
id-val : ["-"] id-expr
|
||
9 years ago
|
|
||
|
number : ["-"] NUMBER
|