summaryrefslogtreecommitdiff
path: root/ast.h
diff options
context:
space:
mode:
authorCarson Fleming <[email protected]>2026-03-26 16:21:29 -0400
committerCarson Fleming <[email protected]>2026-03-26 16:22:00 -0400
commit7d9fb2c733c8c64f6f74eefa0eea35b36be102cd (patch)
tree16b6cded5f9611e0ff1948395578845c9688b926 /ast.h
parent68db110d34611fc8bb79035d3a11bba07dea43f3 (diff)
downloadccc-7d9fb2c733c8c64f6f74eefa0eea35b36be102cd.tar.gz
let's go we can parse return zero most useful program ever
Diffstat (limited to 'ast.h')
-rw-r--r--ast.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/ast.h b/ast.h
new file mode 100644
index 0000000..c82f089
--- /dev/null
+++ b/ast.h
@@ -0,0 +1,77 @@
+#ifndef AST_H
+#define AST_H
+
+struct stmt_node;
+struct expr_node;
+
+struct type_node {
+ char* type;
+};
+
+struct var_decl_node {
+ struct type_node type;
+ char* ident;
+
+ struct var_decl_node* next;
+};
+
+struct group_node {
+ struct stmt_node* body_head;
+};
+
+struct fn_decl_node {
+ struct type_node return_type;
+ char* name;
+ struct var_decl_node* args_head;
+ struct group_node body;
+};
+
+struct return_node {
+ struct expr_node* ret_val; /* null to return void */
+};
+
+struct int_lit_node {
+ long long val;
+};
+
+struct expr_node {
+ enum {
+ EXPR_EMPTY,
+ EXPR_VAR_DECL,
+ EXPR_RETURN,
+ EXPR_INT_LIT,
+ } type;
+ union {
+ struct var_decl_node _var_decl;
+ struct return_node _return;
+ struct int_lit_node _int_lit;
+ } as;
+};
+
+struct stmt_node {
+ enum {
+ STMT_EXPR,
+ STMT_GROUP,
+ } type;
+ union {
+ struct expr_node _expr;
+ struct group_node _group;
+ } as;
+
+ struct stmt_node* next;
+};
+
+struct root_node {
+ enum {
+ ROOT_FN_DECL,
+ } type;
+ union {
+ struct fn_decl_node _fn_decl;
+ } as;
+
+ struct root_node* next;
+};
+
+void ast_destroy(struct root_node* head);
+
+#endif