aboutsummaryrefslogtreecommitdiff
path: root/src/parser.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y44
1 files changed, 8 insertions, 36 deletions
diff --git a/src/parser.y b/src/parser.y
index a51eb9a..62afcac 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -134,7 +134,7 @@
%nterm <node> var_init proc
%nterm <node> alias trait enum_val enums enum top unit id
%nterm <node> embed param_decl members
-%nterm <node> top_if const_if const_for defer goto assign
+%nterm <node> top_if const_if const_for goto assign
%nterm <node> construct construct_args construct_arg
%nterm <node> statelet
@@ -157,6 +157,7 @@
%nterm <type> opt_types opt_sign_decls sign_decls sign_decl sign_var_decl
%nterm <node> opt_construct_args
%nterm <node> opt_behaviours behaviours behaviour
+%nterm <node> opt_deferred_statement
/* reverse lists */
%nterm <type> rev_sign_decls;
@@ -241,9 +242,6 @@ static char match_escape(char c);
*/
static char *strip(const char *s);
-static struct ast *reverse_ast_list(struct ast *root);
-static struct type *reverse_type_list(struct type *root);
-
%}
%start input;
@@ -344,9 +342,6 @@ opt_decls
: decls
| {$$ = NULL;}
-defer
- : "defer" body { $$ = gen_defer($2, src_loc(@$)); }
-
const_binop
: const_expr "+" const_expr {
$$ = gen_binop(AST_ADD, $1, $3, src_loc(@$));
@@ -480,16 +475,19 @@ statement
| struct
| struct_cont
| for
- | defer
| if
| const
| enum
| macro
| ID ":" { $$ = gen_label($[ID], NULL, src_loc(@$)); }
+opt_deferred_statement
+ : statement
+ | "defer" statement { $$ = gen_defer($2, src_loc(@$)); }
+
rev_statements
- : rev_statements statement { $$ = $2; $2->n = $1; }
- | statement
+ : rev_statements opt_deferred_statement { $$ = $2; $2->n = $1; }
+ | opt_deferred_statement
statements
: rev_statements { $$ = reverse_ast_list($1); }
@@ -1002,32 +1000,6 @@ static char *strip(const char *str)
}
-static struct ast *reverse_ast_list(struct ast *root)
-{
- struct ast *new_root = NULL;
- while (root) {
- struct ast *next = root->n;
- root->n = new_root;
- new_root = root;
- root = next;
- }
-
- return new_root;
-}
-
-static struct type *reverse_type_list(struct type *root)
-{
- struct type *new_root = NULL;
- while (root) {
- struct type *next = root->n;
- root->n = new_root;
- new_root = root;
- root = next;
- }
-
- return new_root;
-}
-
struct parser *create_parser()
{
return calloc(1, sizeof(struct parser));