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

33 lines
1.1 KiB
Racket

#lang brag
8 years ago
;; program & lines
b-program : [b-line] (/NEWLINE [b-line])*
8 years ago
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
@b-line-num : INTEGER
b-rem : REM
8 years ago
@b-statement : b-end | b-print | b-goto
| b-let | b-input | b-if
| b-gosub | b-return | b-for | b-next
b-end : /"end"
8 years ago
b-print : /"print" [b-printable] (/";" [b-printable])*
@b-printable : STRING | b-expr
8 years ago
b-goto : /"goto" b-expr
8 years ago
b-let : [/"let"] b-id /"=" (STRING | b-expr)
8 years ago
b-if : /"if" b-expr /"then" (b-statement | b-expr)
[/"else" (b-statement | b-expr)]
8 years ago
b-input : /"input" b-id
8 years ago
@b-id : ID
8 years ago
b-gosub : /"gosub" b-expr
b-return : /"return"
8 years ago
b-for : /"for" b-id /"=" b-expr /"to" b-expr [/"step" b-expr]
8 years ago
b-next : /"next" b-id
8 years ago
b-expr : b-or-expr
b-or-expr : [b-or-expr "or"] b-and-expr
b-and-expr : [b-and-expr "and"] b-not-expr
b-not-expr : ["not"] b-comp-expr
b-comp-expr : [b-comp-expr ("="|"<"|">"|"<>")] b-sum
8 years ago
b-sum : [b-sum ("+"|"-")] b-product
8 years ago
b-product : [b-product ("*"|"/"|"mod")] b-neg
b-neg : ["-"] b-expt
b-expt : [b-expt ("^")] b-value
8 years ago
@b-value : b-number | b-id | /"(" b-expr /")"
8 years ago
@b-number : INTEGER | DECIMAL