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.
24 lines
665 B
Racket
24 lines
665 B
Racket
5 years ago
|
#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 /"+"] value
|
||
|
@value : id | INTEGER | 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
|