-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgrammar.txt
134 lines (95 loc) · 3.16 KB
/
grammar.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<toplevel> ::= <expression>
| <expression> <division> <toplevel>
<expression> ::= <prec12>
<nonop_expression> ::= <array_literal>
| <assignment>
| <block>
| <cond_statement>
| <except>
| <for_loop>
| <function_definition>
| <literal>
| <new_obj>
| <require>
| <return>
| <try_catch>
| <type_definition>
| <variable_declaration>
| <variable>
| <while_loop>
<prec0> ::= <nonop_expression>
| <prec0> '.' <variable>
| <prec0> '(' <expr_list> ')'
| <prec0> '[' <expression> ']'
<prec1> ::= <prec0>
| '!' <prec1>
| '~' <prec1>
| '-' <prec1>
<prec2> ::= <prec1>
| <prec1> '**' <prec2>
<prec3> ::= <prec2>
| <prec2> '*' <prec3>
| <prec2> '/' <prec3>
| <prec2> '%' <prec3>
<prec4> ::= <prec3>
| <prec3> '+' <prec4>
| <prec3> '-' <prec4>
<prec5> ::= <prec4>
| <prec4> '>>' <prec5>
| <prec4> '<<' <prec5>
<prec6> ::= <prec5>
| <prec5> '&' <prec6>
<prec7> ::= <prec6>
| <prec6> '^' <prec7>
<prec8> ::= <prec7>
| <prec7> '|' <prec8>
<prec9> ::= <prec8>
| <prec8> 'to' <prec9>
<prec10> ::= <prec9>
| <prec9> '>' <prec10>
| <prec9> '<' <prec10>
| <prec9> '>=' <prec10>
| <prec9> '<=' <prec10>
<prec11> ::= <prec10>
| <prec10> '==' <prec11>
| <prec10> '!=' <prec11>
<prec12> ::= <prec11>
| <prec11> '&&' <prec12>
<prec13> ::= <prec12>
| <prec12> '||' <prec13>
<array_literal> ::= '[' <expr_list> ']'
<assignment> ::= <variable> '=' <expression>
<block> ::= 'do' <toplevel> 'end'
<cond_statement> ::= 'cond' <inner_cond_statement>
| 'if' <inner_cond_statement>
<except> ::= 'except' <expression>
<for_loop> ::= 'for' <variable> 'in' <expression> ':' <expression>
<function_definition> ::= 'fn' '(' <arg_list> ')' ':' <expression>
| 'fn' <variable> '(' <arg_list> ')' ':' <expression>
<literal> ::= <bool>
| <float>
| <integer>
| <nil>
| <string>
| <symbol>
<new_obj> ::= 'new' <variable> '(' <expr_list> ')'
<require> ::= 'require' <string>
<return> ::= 'return' <expression>
<try_catch> ::= 'try' ':' <expression> <division 'catch' <variable> ':' <expression>
<type_definition> ::= 'variable' <name> <method_list>
<variable_declaration> ::= 'let' <variable> '=' <expression>
<variable> ::= /\([^[:space:][:punct:]\|_\)+/
<while_loop> ::= 'while' <expression> ':' <expression>
<symbol> ::= '\'' <variable>
<integer> ::= /[1-9][0-9]* /
| /0[0-7]* /
| /0x[0-9a-fA-F]+/
| /0b[01]+/
<float> ::= /[1-9][0-9]*\.[0-9]+/
| /0\.[0-9]+/
<bool> ::= 'true'
| 'false'
<nil> ::= 'nil'
<string> ::= /".*"/
<division> ::= '\n'
| ';'