-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbnf.txt
52 lines (50 loc) · 1.52 KB
/
bnf.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
template -> (funcdef | stmt)* EOF
funcdef -> 'function' id '(' defargs ')' block
defargs -> id [',' id]*
stmt -> for | if | return | 'break' ';'
| 'continue' ';' | block | expr
for -> 'for' '(' forexpr (fortable | forclassic) ')' body
if -> 'if' '(' expr ')' body ['else' body]
return -> 'return' [expr] ';'
forexpr -> expr | _
fortable -> 'in' [fordir]
forclassic -> ';' forexpr ';' forexpr
body -> block | stmt
block -> '{' stmt* '}'
expr -> assign [',' assign]*
assign -> ternary [assignop ternary]*
ternary -> or ['?' or ':' or]*
or -> and ['|' and]*
and -> rel ['&' rel]*
rel -> nextto [relop nextto]
nextto -> cat [nextop cat [nexttoops]]*
nexttoops -> ':' string
cat -> add ['~' add]*
add -> mult [addop mult]*
mult -> unary [multop unary]*
unary -> prestep | ref | not | sign | address
prestep -> stepop address
ref -> refop address
not -> '!' address
sign -> addop address
address -> val [index | attr]*
val -> call | '(' expr ')' | float | int | string
call -> id [args]
args -> '(' assign [',' assign]* ')'
index -> ['%'] '[' indexexpr ';' indexexpr ']'
indexexpr -> assign | range | filter
range -> assign '..' assign
filter -> '{' assign '}'
attr -> '.' id
id -> /^[a-zA-Z_]+[a-zA-Z_0-9]*/
float -> /^[0-9]*\.[0-9]+([eE][-+]?[0-9]+)?/
int -> /^[0-9]+/+
assignop -> '=' | '+=' | '-=' | '*=' | '/=' | '~='
stepop -> '--' | '++'
nexttoop -> '^' | '<-'
relop -> '==' | '^' | '!=' | '>=' | '<=' | '<' | '>'
addop -> '+' | '-'
multop -> '*' | '/'
refop -> '$' | '%'
string -> ...
fordir -> cols | rows