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/scriptish-demo/grammar.rkt

31 lines
1.1 KiB
Racket

6 years ago
#lang brag
top : @statement*
5 years ago
statement : (var | expr | return | defun) /";" | if-else | while
5 years ago
var : /"var" (varname /"=")+ expr
5 years ago
@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
5 years ago
add-or-sub : [add-or-sub ("+" | "-")] mult-or-div
mult-or-div : [mult-or-div ("*" | "/")] value
5 years ago
@value : NUMBER | STRING | object
| fun | app | increment | varname | /"(" expr /")"
increment : ("++" | "--") varname | varname ("++" | "--")
6 years ago
object : /"{" @kvs /"}"
kvs : [kv (/"," kv)*]
/kv : expr /":" expr
5 years ago
defun : /"function" ID /"(" varnames /")" @block
fun : /"function" /"(" varnames /")" @block
/varnames : [varname (/"," varname)*]
@varname : ID | deref
6 years ago
deref : DEREF
block : /"{" @statement* /"}"
return : /"return" expr
5 years ago
app : varname /"(" @exprs /")"
6 years ago
exprs : [expr (/"," expr)*]
5 years ago
if-else : /"if" /"(" expr /")" @block ["else" @block]
6 years ago
while : /"while" /"(" expr /")" @block