-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
104 lines (79 loc) · 1.77 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
// NOTE: VERY OUTDATED, NOT WHAT THE GRAMMER LOOKS LIKE
// SEE src/Language/Parser.y
base: statement+ 'eol'
statement:
| assignment
| 'return' expression
| 'break'
| if_statement
| for_statement
| while_statement
| function_definition
| worker_definition
assignment: 'let' variable_name assignment_operator expression
variable_name: [A-Z](_?[A-Z0-9])*
assignment_operator:
| '='
| '+='
| '-='
| '*='
| '/='
| '!='
expression:
| conjunction ('||' conjunction)+
| conjunction
conjunction:
| inversion ('&&' inversion)+
| inversion
inversion:
| '!' inversion
| sum
sum:
| sum '+' term
| sum '-' term
| term
term:
| term '*' factor
| term '/' factor
| term '//' factor
| term '%' factor
| factor
factor:
| '+' factor
| '-' factor
| power
power:
| molecule '**' factor
| molecule
molecule:
| '(' expression ')'
| atom
atom:
| 'true'
| 'false'
| 'null'
| string_literal
| number_literal
| anonymous_function
| variable_name
string_literal:
| '[a-z0-9]'
| "[a-z0-9]"
if_statement:
| 'if' '(' expression ')' block
| if_statement 'else' block
if_statement_without_else:
| 'if' '(' expression ')' block
| if_statement_without_else 'else' if_statement_without_else
block:
| expression
| '{' statement+ '}'
for_statement: 'for' '(' not sure ')' block
while_statement: 'while' '(' expression ')' block
function_definition: 'func' variable_name '(' parameter_list ')' '->' type block
anonymous_function: 'func' '(' ')' '->' return_value block
parameter_list:
| type variable_name, parameter_list
| type variable_name
type: variable_name
worker_definition: 'worker' variable_name block