12 %token_type {PSI_Token *}
13 %token_destructor {free($$);}
14 %extra_argument {PSI_Lexer *L}
16 printf("ERROR: Syntax error on line %zu in '%s': '%s...'\n", L->line, L->fn, L->tok);
23 blocks ::= blocks block.
25 block ::= decl(decl_). {
26 L->decl.list = realloc(L->decl.list, ++L->decl.count * sizeof(*L->decl.list));
27 L->decl.list[L->decl.count-1] = decl_;
29 block ::= impl(impl_). {
30 L->impl.list = realloc(L->impl.list, ++L->impl.count * sizeof(*L->impl.list));
31 L->impl.list[L->impl.count-1] = impl_;
36 decl(decl) ::= decl_arg(func) LPAREN decl_args(args) RPAREN EOS. {
37 decl = init_decl(func, args);
39 %type decl_var {decl_var*}
40 decl_var(var) ::= NAME(T). {
41 var = init_decl_var(T->text, 0);
44 decl_var(var) ::= pointers(p) NAME(T). {
45 var = init_decl_var(T->text, p);
49 %type decl_vars {decl_vars*}
50 decl_vars(vars) ::= decl_var(var). {
51 vars = init_decl_vars(var);
53 decl_vars(vars) ::= decl_vars(vars_) COMMA decl_var(var). {
54 vars = add_decl_var(vars_, var);
57 %type decl_arg {decl_arg*}
58 decl_arg(arg) ::= decl_type(type) decl_var(var). {
59 arg = init_decl_arg(type, var);
62 %type decl_args {decl_args*}
63 decl_args(args) ::= decl_arg(arg). {
64 args = init_decl_args(arg);
66 decl_args(args) ::= decl_args(args_) COMMA decl_arg(arg). {
67 args = add_decl_arg(args_, arg);
70 %type decl_type {decl_type*}
71 decl_type(type_) ::= VOID(T). {
72 type_ = init_decl_type(T->type, T->text);
75 decl_type(type_) ::= INT(T). {
76 type_ = init_decl_type(T->type, T->text);
79 decl_type(type_) ::= FLOAT(T). {
80 type_ = init_decl_type(T->type, T->text);
83 decl_type(type_) ::= DOUBLE(T). {
84 type_ = init_decl_type(T->type, T->text);
87 decl_type(type_) ::= SINT8(T). {
88 type_ = init_decl_type(T->type, T->text);
91 decl_type(type_) ::= UINT8(T). {
92 type_ = init_decl_type(T->type, T->text);
97 impl(impl) ::= impl_func(func) LCURLY impl_stmts(stmts) RCURLY. {
98 impl = init_impl(func, stmts);
101 %type impl_func {impl_func*}
102 impl_func(func) ::= FUNCTION NSNAME(NAME) LPAREN impl_args(args) RPAREN COLON impl_type(type). {
103 func = init_impl_func(NAME->text, args, type);
107 %type impl_def_val {impl_def_val*}
108 impl_def_val(def) ::= NULL. {
110 def = init_impl_def_val();
112 impl_def_val(def) ::= number. {
114 def = init_impl_def_val();
117 %type impl_var {impl_var*}
118 impl_var(var) ::= DOLLAR NAME(T). {
119 var = init_impl_var(T->text, 0);
122 impl_var(var) ::= REFERENCE DOLLAR NAME(T). {
123 var = init_impl_var(T->text, 1);
127 %type impl_arg {impl_arg*}
128 impl_arg(arg) ::= impl_type(type) impl_var(var). {
129 arg = init_impl_arg(type, var, NULL);
131 impl_arg(arg) ::= impl_type(type) impl_var(var) EQUALS impl_def_val(def). {
132 arg = init_impl_arg(type, var, def);
135 %type impl_args {impl_args*}
136 impl_args(args) ::= impl_arg(arg). {
137 args = init_impl_args(arg);
139 impl_args(args) ::= impl_args(args_) COMMA impl_arg(arg). {
140 args = add_impl_arg(args_, arg);
143 %type impl_stmts {impl_stmts*}
144 impl_stmts(stmts) ::= impl_stmt(stmt). {
145 stmts = init_impl_stmts(stmt);
147 impl_stmts(stmts) ::= impl_stmts(stmts_) impl_stmt(stmt). {
148 stmts = add_impl_stmt(stmts_, stmt);
151 %type impl_stmt {impl_stmt*}
152 impl_stmt(stmt) ::= let_stmt(let). {
153 stmt = init_impl_stmt(PSI_T_LET, let);
155 impl_stmt(stmt) ::= set_stmt(set). {
156 stmt = init_impl_stmt(PSI_T_SET, set);
158 impl_stmt(stmt) ::= ret_stmt(ret). {
159 stmt = init_impl_stmt(PSI_T_RET, ret);
162 %type let_stmt {let_stmt*}
163 let_stmt(let) ::= LET decl_var(var) EQUALS let_value(val) EOS. {
164 let = init_let_stmt(var, val);
167 %type let_value {let_value*}
168 let_value(val) ::= let_func(func) LPAREN impl_var(var) RPAREN. {
169 val = init_let_value(func, var);
171 let_value(val) ::= let_reference_null_pointer. {
172 val = init_let_value(NULL, NULL);
175 let_reference_null_pointer ::= REFERENCE NULL.
177 %type let_func {let_func*}
178 let_func(func) ::= STRVAL(T). {
179 func = init_let_func(T->type, T->text);
182 let_func(func) ::= INTVAL(T). {
183 func = init_let_func(T->type, T->text);
186 let_func(func) ::= FLOATVAL(T). {
187 func = init_let_func(T->type, T->text);
190 let_func(func) ::= BOOLVAL(T). {
191 func = init_let_func(T->type, T->text);
195 %type set_stmt {set_stmt*}
196 set_stmt(set) ::= SET impl_var(var) EQUALS set_value(val) EOS. {
197 set = init_set_stmt(var, val);
200 %type set_value {set_value*}
201 set_value(val) ::= set_func(func) LPAREN decl_vars(vars) RPAREN. {
202 val = init_set_value(func, vars);
205 %type set_func {set_func*}
206 set_func(func) ::= TO_STRING(T). {
207 func = init_set_func(T->type, T->text);
210 set_func(func) ::= TO_INT(T). {
211 func = init_set_func(T->type, T->text);
214 set_func(func) ::= TO_FLOAT(T). {
215 func = init_set_func(T->type, T->text);
218 set_func(func) ::= TO_BOOL(T). {
219 func = init_set_func(T->type, T->text);
223 %type ret_stmt {ret_stmt*}
224 ret_stmt(ret) ::= RET set_func(func) LPAREN decl_var(var) RPAREN EOS. {
225 ret = init_ret_stmt(func, var);
228 %type impl_type {impl_type*}
229 impl_type(type_) ::= VOID(T). {
230 type_ = init_impl_type(T->type, T->text);
233 impl_type(type_) ::= MIXED(T). {
234 type_ = init_impl_type(T->type, T->text);
237 impl_type(type_) ::= BOOL(T). {
238 type_ = init_impl_type(T->type, T->text);
241 impl_type(type_) ::= INT(T). {
242 type_ = init_impl_type(T->type, T->text);
245 impl_type(type_) ::= FLOAT(T). {
246 type_ = init_impl_type(T->type, T->text);
249 impl_type(type_) ::= STRING(T). {
250 type_ = init_impl_type(T->type, T->text);
253 impl_type(type_) ::= ARRAY(T). {
254 type_ = init_impl_type(T->type, T->text);
259 digits ::= digits DIGIT.
260 decimals ::= digits DOT digits.
261 decimals ::= DOT digits.
262 decimals ::= digits DOT.
264 number ::= PLUS digits.
265 number ::= MINUS digits.
267 number ::= MINUS decimals.
268 number ::= PLUS decimals.
270 %type pointers {unsigned}
271 pointers(p) ::= POINTER. {++p;}
272 pointers(p) ::= pointers(P) POINTER. {p = ++P;}