From 0cabbd2a0853c332c82af621b8716643741d758a Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Tue, 21 Jul 2026 14:36:02 -0700 Subject: more faithful grammar --- ast.h | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'ast.h') diff --git a/ast.h b/ast.h index 21a4e72..a51bfea 100644 --- a/ast.h +++ b/ast.h @@ -33,35 +33,23 @@ struct var_ref_node { struct var_decl_node { struct type_ref_node type; struct var_def* def_ref; -}; - -struct lval_node { - enum { - LVAL_VAR_DECL, - LVAL_VAR_REF, - } type; - union { - struct var_ref_node var_ref; - struct var_decl_node var_decl; - } inner; - - const struct type_def* resolved_type; + struct expr_node* initial_value; }; struct assign_node { - struct lval_node lval; + struct expr_node* lval; struct expr_node* rval; }; -struct args_eval_node { +struct expr_list_node { struct expr_node* expr; - struct args_eval_node* next; + struct expr_list_node* next; }; struct call_node { - /* TODO: eventually this could also be a function pointer */ + /* TODO: function pointers */ struct fn_decl_node* called_fn_ref; /* borrowed */ - struct args_eval_node* args; + struct expr_list_node* args; }; struct unary_node { @@ -114,15 +102,15 @@ struct group_node { struct scope* scope; }; -struct args_decl_node { +struct decl_list_node { struct var_decl_node* decl; - struct args_decl_node* next; + struct decl_list_node* next; }; struct fn_decl_node { struct type_ref_node return_type; char* name; - struct args_decl_node* args; + struct decl_list_node* args; struct group_node body; struct scope* scope; @@ -140,8 +128,19 @@ struct if_node { struct scope* scope; }; +struct loop_init_node { + enum { + INIT_EXPR_LIST, + INIT_DECL, + } type; + union { + struct expr_list_node* expr_list; + struct var_decl_node* decl; + }; +}; + struct loop_node { - struct expr_node* init; /* null if absent */ + struct loop_init_node* init; /* null if absent */ struct expr_node* cond; /* null if absent */ struct expr_node* incr; /* null if absent */ struct stmt_node* body; -- cgit v1.2.3