From 5767110816ca9452ef77d15245d1a747bfdd896b Mon Sep 17 00:00:00 2001 From: hachem Date: Sun, 30 Aug 2026 03:32:51 +0200 Subject: add: top level parser --- src/parser/ast.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/parser/ast.c (limited to 'src/parser/ast.c') diff --git a/src/parser/ast.c b/src/parser/ast.c new file mode 100644 index 0000000..979dff0 --- /dev/null +++ b/src/parser/ast.c @@ -0,0 +1,33 @@ +#include + +#include "parser/ast.h" + +struct Program create_program(void) +{ + struct Program program; + program.consts = NULL; + program.const_count = 0; + program.const_capacity = 0; + return program; +} + +void free_program(struct Program* program) +{ + free(program->consts); + program->consts = NULL; + program->const_count = 0; + program->const_capacity = 0; +} + +void add_const(struct Program* program, struct ConstDecl decl) +{ + if (program->const_count == program->const_capacity) + { + size_t capacity = program->const_capacity < 8 ? 8 : program->const_capacity * 2; + program->consts = realloc(program->consts, capacity * sizeof(struct ConstDecl)); + program->const_capacity = capacity; + } + + program->consts[program->const_count] = decl; + program->const_count += 1; +} -- cgit v1.3