start ast + fix type names in tokenizer

This commit is contained in:
2024-12-15 00:04:23 +02:00
parent 6863e34fbc
commit c2915d2eaa
6 changed files with 1135 additions and 587 deletions

38
ast.c Normal file
View File

@@ -0,0 +1,38 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ast.h"
int ast_parse(const char* source, uint32_t len, ast *result) {
uint32_t estimated_token_count = len / 8;
tokenizer_tag* tokens_tag = calloc(estimated_token_count, sizeof(tokenizer_tag));
if (tokens_tag == NULL) {
perror("calloc");
return 1;
}
ast_index* tokens_start = calloc(estimated_token_count, sizeof(ast_index));
if (tokens_start == NULL) {
free(tokens_tag);
perror("calloc");
return 1;
}
tokenizer tokenizer = tokenizer_init(source, len);
for (uint32_t i = 0; i <= estimated_token_count; i++) {
if (i == estimated_token_count) {
fprintf(stderr, "too many tokens, bump estimated_token_count\n");
return 1;
}
tokenizer_token token = tokenizer_next(&tokenizer);
tokens_tag[i] = token.tag;
tokens_start[i] = token.loc.start;
}
/* TODO parser */
return 0;
}