#include #include #include #include #include #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; }