nits
parent
d05ac2ac6a
commit
9d4292ac85
@ -1,11 +1,11 @@
|
|||||||
#lang brag
|
#lang brag
|
||||||
|
|
||||||
top : (func-def | expr)*
|
top : (func-def | func-app)*
|
||||||
func-def : /"fun" var /"(" vars /")" /"=" expr
|
func-def : /"fun" var /"(" vars /")" /"=" expr
|
||||||
/vars : [var [/"," var]*]
|
/vars : [var (/"," var)*]
|
||||||
@expr : sum
|
@expr : sum
|
||||||
sum : [sum ("+" | "-")] product
|
sum : [sum ("+" | "-")] product
|
||||||
product : [product ("*" | "/")] value
|
product : [product ("*" | "/")] value
|
||||||
@value : var | INT | func-app | /"(" expr /")"
|
@value : var | INT | func-app | /"(" expr /")"
|
||||||
func-app : var /"(" [value [/"," value]*] /")"
|
func-app : var /"(" [expr (/"," expr)*] /")"
|
||||||
@var : ID
|
@var : ID
|
@ -1,19 +1,15 @@
|
|||||||
#lang brag
|
#lang brag
|
||||||
|
|
||||||
top : @statement*
|
top : @statement*
|
||||||
statement : assignment | func-def | expr | return | for | if | print
|
statement : func-def | expr | return | if
|
||||||
assignment : ID /"=" expr
|
func-def : /"def" var /"(" ids /")" /":" @block
|
||||||
|
/ids : [var (/"," var)*]
|
||||||
|
block : /INDENT @statement* /DEDENT
|
||||||
@expr : comparison
|
@expr : comparison
|
||||||
comparison : [comparison ("<" | ">")] sum
|
comparison : [comparison "<"] value
|
||||||
sum : [sum ("+" | "-")] product
|
@value : var | INTEGER | func-app | STRING
|
||||||
product : [product ("*" | "/")] value
|
func-app : var /"(" @exprs /")"
|
||||||
@value : ID | INTEGER | func-app | STRING
|
|
||||||
func-app : ID /"(" @exprs /")"
|
|
||||||
exprs : [expr (/"," expr)*]
|
exprs : [expr (/"," expr)*]
|
||||||
func-def : /"def" ID /"(" ids /")" /":" @block
|
|
||||||
/ids : [ID (/"," ID)*]
|
|
||||||
block : /INDENT @statement* /DEDENT
|
|
||||||
return : /"return" expr
|
return : /"return" expr
|
||||||
for : /"for" ID /"in" expr /":" @block
|
|
||||||
if : /"if" expr /":" block [/"else" /":" block]
|
if : /"if" expr /":" block [/"else" /":" block]
|
||||||
print : /"print" expr
|
@var : ID
|
@ -1,51 +1,27 @@
|
|||||||
#lang pythonesque-demo
|
#lang pythonesque-demo
|
||||||
|
|
||||||
a = 3
|
"escaped quote: middle \" and end \""
|
||||||
b = 4
|
"escaped backslash: middle \\ and end \\"
|
||||||
|
|
||||||
"middle \" escaped quote"
|
def nothing():
|
||||||
"ending escaped quote\""
|
42
|
||||||
"middle \\ escaped backslash"
|
|
||||||
"ending escaped backslash\\"
|
|
||||||
|
|
||||||
def ft():
|
def fortytwo():
|
||||||
return 42
|
return 42
|
||||||
|
|
||||||
def gt(x, y):
|
def eightyfour():
|
||||||
return x > y
|
return 84
|
||||||
def noop():
|
def noop():
|
||||||
return "double dedent here"
|
return "double dedent next"
|
||||||
|
|
||||||
|
nothing() # no output
|
||||||
|
|
||||||
def squaresum(x, y):
|
if fortytwo() < eightyfour():
|
||||||
def add(c, d):
|
"left is less than right"
|
||||||
return c + d
|
|
||||||
return add(x, y) * add(x, y)
|
|
||||||
|
|
||||||
gt(a, b) # #f
|
|
||||||
squaresum(b, a) # 49
|
|
||||||
|
|
||||||
println(a)
|
|
||||||
|
|
||||||
expt(2, 4)
|
|
||||||
|
|
||||||
range(1, 5)
|
|
||||||
|
|
||||||
# keep indented example next to eof
|
|
||||||
for x in range(1, 5):
|
|
||||||
println(x * x)
|
|
||||||
|
|
||||||
def foo(x):
|
|
||||||
x
|
|
||||||
|
|
||||||
foo(42) # no return value
|
|
||||||
|
|
||||||
if a < b:
|
|
||||||
print "a is less than b"
|
|
||||||
else:
|
else:
|
||||||
print "a is not less than b"
|
"left is not less than right"
|
||||||
|
|
||||||
def bar(x, y):
|
def last():
|
||||||
return x > y
|
return 42
|
||||||
def noop():
|
def noop():
|
||||||
return "double dedent here"
|
return "double dedent next"
|
Loading…
Reference in New Issue