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.
25 lines
721 B
Racket
25 lines
721 B
Racket
#lang brag
|
|
|
|
top : @statement*
|
|
statement : (var | expr | return) /";" | if | while
|
|
var : /"var" id /"=" expr
|
|
@expr : comparison
|
|
comparison : [comparison ("!=" | "==")] add-or-sub
|
|
add-or-sub : [add-or-sub ("+" | "-")] mult-or-div
|
|
mult-or-div : [mult-or-div ("*" | "/")] value
|
|
@value : id | NUMBER | STRING | object
|
|
| fun | app | increment
|
|
increment : id /"++"
|
|
object : /"{" @kvs /"}"
|
|
kvs : [kv (/"," kv)*]
|
|
/kv : expr /":" expr
|
|
fun : /"function" /"(" ids /")" @block
|
|
/ids : [id (/"," id)*]
|
|
@id : ID | deref
|
|
deref : DEREF
|
|
block : /"{" @statement* /"}"
|
|
return : /"return" expr
|
|
app : id /"(" @exprs /")"
|
|
exprs : [expr (/"," expr)*]
|
|
if : /"if" /"(" expr /")" @block ["else" @block]
|
|
while : /"while" /"(" expr /")" @block |