-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhll.y
185 lines (148 loc) · 2.75 KB
/
hll.y
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
%{
#define YYSTYPE char *
%}
%token TOK_PRIVATE
%token TOK_PUBLIC
%token TOK_GLOBALS
%token TOK_LOCALS
%token TOK_FUNCTION
%token TOK_IF
%token TOK_ELSE
%token TOK_RETURN
%token TOK_TRY
%token TOK_CATCH
%token TOK_FINALLY
%token TOK_IDENTIFIER
%token TOK_INTEGER
%token TOK_LBR
%token TOK_RBR
%token TOK_ASSIGN
%token TOK_LPAREN
%token TOK_RPAREN
%token TOK_DOT
%token TOK_COMMA
%token TOK_SEMIC
%start compilation_unit
%%
identifier: TOK_IDENTIFIER;
expr_list:
expr_list TOK_COMMA expr
| expr
;
expr_list_or_empty:
expr_list
| /* empty */
;
function_call:
identifier TOK_LPAREN expr_list_or_empty TOK_RPAREN
;
method_call:
expr TOK_DOT identifier TOK_LPAREN expr_list_or_empty TOK_RPAREN
;
expr:
TOK_LPAREN expr TOK_RPAREN
| TOK_INTEGER
| identifier
| function_call
| method_call
;
assignment_statement:
identifier TOK_ASSIGN expr TOK_SEMIC
;
if_statement:
TOK_IF expr statement_block TOK_ELSE statement_block
| TOK_IF expr statement_block
;
return_statement:
TOK_RETURN expr TOK_SEMIC
;
except_clause_try:
TOK_TRY TOK_LBR statement_list_or_empty TOK_RBR
;
except_clause_catch:
TOK_CATCH TOK_LPAREN TOK_INTEGER TOK_RPAREN TOK_LBR statement_list_or_empty TOK_RBR
;
except_clause_catch_list:
except_clause_catch_list except_clause_catch
| except_clause_catch
;
except_clause_catch_list_or_empty:
except_clause_catch_list
| /* empty */
;
except_clause_finally_or_empty:
TOK_FINALLY TOK_LBR statement_list_or_empty TOK_RBR
| /* empty */
;
except_clause:
except_clause_try
except_clause_catch_list_or_empty
except_clause_finally_or_empty
;
statement:
assignment_statement
| if_statement
| return_statement
| except_clause
| expr TOK_SEMIC
;
statement_list:
statement_list statement
| statement
;
statement_list_or_empty:
statement_list
| /* empty */
;
locals_declaration:
TOK_LOCALS identifier_list_or_empty TOK_SEMIC
;
locals_declaration_or_empty:
locals_declaration
| /* empty */
;
statement_block:
TOK_LBR
locals_declaration_or_empty
statement_list_or_empty
TOK_RBR
;
scope_optional:
TOK_PUBLIC
| TOK_PRIVATE
| /* empty */
;
globals_declaration:
scope_optional TOK_GLOBALS identifier_list_or_empty TOK_SEMIC
;
function_name: identifier;
function_body: statement_block;
identifier_list:
identifier_list TOK_COMMA identifier
| identifier
;
identifier_list_or_empty:
identifier_list
| /* empty */
;
function_arguments:
TOK_LPAREN
identifier_list_or_empty
TOK_RPAREN
;
function_declaration:
scope_optional TOK_FUNCTION function_name function_arguments
function_body
;
top_level_statement:
globals_declaration
| function_declaration
;
top_level_statement_list:
top_level_statement_list top_level_statement
| top_level_statement
;
compilation_unit:
top_level_statement_list
| /* empty */
;