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-demo/basic-demo/parser.rkt

42 lines
894 B
Racket

#lang brag
9 years ago
basic-program : line*
9 years ago
line: NUMBER statement [/":" statement]*
9 years ago
statement : "def" id /"(" id /")" /"=" expr
| "dim" id-expr [/"," id-expr]*
| "end" | "stop"
9 years ago
| "gosub" expr
| "goto" expr
| "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]*
| [/"let"] id-expr "=" expr
9 years ago
| "print" [print-list]
| "return"
| "for" id /"=" expr /"to" expr [/"step" expr]
9 years ago
| "next" [id]
print-list : expr [[";"] [print-list]]
expr : comp-expr [("and" | "or") expr]
9 years ago
comp-expr : sum [("=" | ">" | ">=" | "<" | "<=" | "<>") comp-expr]
9 years ago
sum : [sum ("+" | "-")] product
9 years ago
product : [product ("*" | "/")] power
power : value [/"^" value]
9 years ago
8 years ago
@value : maybe-negative-val
9 years ago
| id-expr
9 years ago
| /"(" expr /")"
| STRING
9 years ago
id-expr : id [/"(" expr [/"," expr]* /")"]
9 years ago
@id : ID
8 years ago
maybe-negative-val : ["-"] (id-expr | NUMBER)