-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
112 lines (84 loc) · 2.1 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
/* Parser part (White spaces are ignored after tokenizing) */
program: empty_lines "HAI" version eol statements "KTHXBYE" empty_lines;
empty_lines:
/* empty */
| empty_lines eol;
statements:
/* empty */
| statements statement;
statement:
var_decl
| var_assign
| array_decl
| array_new_index
| array_assign
| print
| if_then
| loop
| "ENUF" eol /*break or exit*/
| expr eol
| eol;
var_decl:
"I" "HAS" "A" identifier eol
| "I" "HAS" "A" identifier "ITZ" expr eol;
var_assign: identifier "R" expr eol;
array_decl: "I" "HAS" "A" identifier "ITZ" "A" "BUKKIT" eol;
array_new_index: identifier "HAS" "A" "SRS" expr "ITZ" expr eol;
array_assign: identifier "'Z" "SRS" expr "R" expr eol;
array_access: identifier "'Z" "SRS" expr;
print:
"VISIBLE" many_args eol
| "VISIBLE" many_args "!" eol;
join: "SMOOSH" many_args "MKAY";
many_args:
expr /* left recursion - right recursion uses more space */
| many_args expr
| many_args "AN" expr;
if_then: "O" "RLY?" eol "YA" "RLY" eol statements "OIC" eol
| "O" "RLY?" eol "YA" "RLY" eol statements "NO" "WAI" eol statements "OIC" eol;
loop:
loop_enter loop_operation loop_condition eol statements loop_leave eol
| loop_enter eol statements loop_leave eol;
loop_enter: "IM" "IN" "YR" identifier;
loop_operation: "UPPIN" "YR" identifier | "NERFIN" "YR" identifier;
loop_condition:
/* empty */
| "TIL" expr
| "WILE" expr;
loop_leave: "IM" "OUTTA" "YR" identifier;
expr:
number
| string
| boolean
| "IT"
| identifier
| logical_not
| binary_op
| array_access
| join;
boolean: "WIN" | "FAIL";
logical_not: "NOT" expr;
binary_op:
binary_op_name expr "AN" expr
| binary_op_name expr expr;
binary_op_name:
math_func "OF"
| "BOTH" "OF"
| "EITHER" "OF"
| "WON" "OF"
| "BOTH" "SAEM"
| "DIFFRINT";
math_func:
"SUM"
| "DIFF"
| "PRODUKT"
| "QUOSHUNT"
| "MOD"
| "BIGGR"
| "SMALLR";
/* Lexer part */
eol: \n+
number: num | -num
version: num.num
identifier: [a-zA-Z][a-zA-Z0-9_]*
string: "..."