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

38 lines
1.4 KiB
Racket

8 years ago
#lang brag
8 years ago
b-program : [b-line] (/NEWLINE [b-line])* | b-statement /NEWLINE
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
8 years ago
@b-line-num : INTEGER
8 years ago
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
8 years ago
| b-def | b-import
8 years ago
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)
b-if : /"if" b-expr /"then" (b-statement | b-expr)
[/"else" (b-statement | b-expr)]
b-input : /"input" b-id
@b-id : ID
8 years ago
b-gosub : /"gosub" b-expr
b-return : /"return"
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-def : /"def" b-id /"(" ID [/"," ID]* /")" /"=" b-expr
8 years ago
b-import : /"import" b-import-name
@b-import-name : (ID | STRING)
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
@b-value : b-number | b-id | /"(" b-expr /")" | b-func
8 years ago
b-func : ID /"(" b-expr [/"," b-expr]* /")"
@b-number : INTEGER | DECIMAL
b-repl : (b-statement | b-expr) (/":" [b-repl])*