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