demo details
parent
e0944fea24
commit
ad48faa13d
@ -1,25 +1,31 @@
|
||||
#lang brag
|
||||
|
||||
top : @statement*
|
||||
statement : (var | expr | return) /";" | if | while
|
||||
var : /"var" id /"=" expr
|
||||
@expr : comparison
|
||||
comparison : [comparison ("!=" | "==")] add-or-sub
|
||||
statement : (var | expr | return | defun) /";" | if-else | while
|
||||
var : /"var" varname /"=" expr
|
||||
@expr : reassignment
|
||||
reassignment : ID [("+=" | "-=") expr] | ternary
|
||||
ternary : expr /"?" expr /":" expr | logical-or
|
||||
logical-or : [logical-or "||"] logical-and
|
||||
logical-and : [logical-and "&&"] equal-or-not
|
||||
equal-or-not : [equal-or-not ("!=" | "==")] gt-or-lt
|
||||
gt-or-lt : [gt-or-lt ("<" | "<=" | ">" | ">=")] 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 /"++"
|
||||
@value : NUMBER | STRING | object
|
||||
| fun | app | increment | varname | /"(" expr /")"
|
||||
increment : ("++" | "--") varname | varname ("++" | "--")
|
||||
object : /"{" @kvs /"}"
|
||||
kvs : [kv (/"," kv)*]
|
||||
/kv : expr /":" expr
|
||||
fun : /"function" /"(" ids /")" @block
|
||||
/ids : [id (/"," id)*]
|
||||
@id : ID | deref
|
||||
defun : /"function" ID /"(" varnames /")" @block
|
||||
fun : /"function" /"(" varnames /")" @block
|
||||
/varnames : [varname (/"," varname)*]
|
||||
@varname : ID | deref
|
||||
deref : DEREF
|
||||
block : /"{" @statement* /"}"
|
||||
return : /"return" expr
|
||||
app : id /"(" @exprs /")"
|
||||
app : varname /"(" @exprs /")"
|
||||
exprs : [expr (/"," expr)*]
|
||||
if : /"if" /"(" expr /")" @block ["else" @block]
|
||||
if-else : /"if" /"(" expr /")" @block ["else" @block]
|
||||
while : /"while" /"(" expr /")" @block
|
Loading…
Reference in New Issue