diff options
| author | hachem <im@hachem.wtf> | 2026-08-30 03:32:51 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-30 03:32:51 +0200 |
| commit | 5767110816ca9452ef77d15245d1a747bfdd896b (patch) | |
| tree | 1f7e5dec5f1fb4fe7a53c1c81f94043ba7db5676 /src/parser/ast.c | |
| parent | 6a6e79cb233e795b78c9ec750dbae9d26bd51654 (diff) | |
add: top level parser
Diffstat (limited to 'src/parser/ast.c')
| -rw-r--r-- | src/parser/ast.c | 33 |
1 files changed, 33 insertions, 0 deletions
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 <stdlib.h> + +#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; +} |
