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.
19 lines
595 B
Racket
19 lines
595 B
Racket
#lang brag
|
|
|
|
top : @statement*
|
|
statement : assignment | func-def | expr | return | for | if | print
|
|
assignment : ID /"=" expr
|
|
@expr : comparison
|
|
comparison : [comparison ("<" | ">")] sum
|
|
sum : [sum ("+" | "-")] product
|
|
product : [product ("*" | "/")] value
|
|
@value : ID | INTEGER | func-app | STRING
|
|
func-app : ID /"(" @exprs /")"
|
|
exprs : [expr (/"," expr)*]
|
|
func-def : /"def" ID /"(" ids /")" /":" @block
|
|
/ids : [ID (/"," ID)*]
|
|
block : /INDENT @statement* /DEDENT
|
|
return : /"return" expr
|
|
for : /"for" ID /"in" expr /":" @block
|
|
if : /"if" expr /":" block [/"else" /":" block]
|
|
print : /"print" expr |