diff options
| author | onelin <oscar@nelin.dk> | 2026-09-22 16:13:43 +0000 |
|---|---|---|
| committer | onelin <oscar@nelin.dk> | 2026-09-22 16:13:57 +0000 |
| commit | 5b29903b6370a5fbca89ac305c865f1956848ee3 (patch) | |
| tree | c5de4f2bbfffd533dda0ed65d5c9fc5663845291 /main.c | |
| parent | 0d78ac413234479d552494a23fb0e6978b0269f3 (diff) | |
chore: Cleanup
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 102 |
1 files changed, 0 insertions, 102 deletions
@@ -71,7 +71,6 @@ typedef struct AExp { static usize f_read(FILE* restrict stream, char** restrict dst); static usize f_size(FILE* restrict stream); -static void l_print_token(Token_t token, const char* restrict text); static line_offsets_t* l_read(char const* restrict text, usize text_length, TokenList_t** restrict dst); static AExp_t* p_arith(char const* restrict text, TokenList_t* restrict tokens); @@ -115,43 +114,11 @@ main(int argc, char* argv[]) { if (lines != NULL) { const isize num_tokens = tokens->length; printf("%ld tokens\n", num_tokens); - for (int tokenidx = 0; tokenidx < num_tokens; tokenidx++) { - l_print_token(tokens->elements[tokenidx], contents); - } AExp_t* expression = p_arith(contents, tokens); printf("ast:\n"); print_aexp(expression); printf("\n"); - // i16 indentation = 0; - // for (int tokenidx = 0; tokenidx < num_tokens; tokenidx++) { - // switch (expression[tokenidx].type) { - // case e_mul: - // printf("%*s*\n", indentation, " "); - // indentation++; - // break; - // case e_div: - // printf("%*s/\n", indentation, " "); - // indentation++; - // break; - // case e_add: - // printf("%*s+\n", indentation, " "); - // indentation++; - // break; - // case e_sub: - // printf("%*s-\n", indentation, " "); - // indentation++; - // break; - // case e_number: - // printf("%*d\n", indentation, expression[tokenidx].data.number); - // indentation--; - // break; - // case e_error: - // default: - // printf("%*s\n", indentation, "error: invalid token"); - // break; - // } - // } } if (tokens != NULL) { @@ -234,51 +201,6 @@ f_size(FILE* restrict stream) { return (usize)size; } -static void -l_print_token(Token_t token, const char* restrict text) { - - // fprintf(stdout, "[%4d] %2d:%d-%d ", token.pos.offset, token.pos.line, - // token.pos.column, token.pos.size); - switch (token.type) { - case t_error: - fputs("%% error ", stdout); - break; - case t_size: - fprintf(stdout, "size"); - break; - case t_multiply: - fputs(" * ", stdout); - break; - case t_divide: - fputs(" / ", stdout); - break; - case t_add: - fputs(" + ", stdout); - break; - case t_subtract: - fputs(" - ", stdout); - break; - case t_number: - fwrite(&text[token.pos.offset], token.pos.size, sizeof(char), stdout); - break; - // case t_space: - // fprintf(stdout, "space:%d", token.pos.size); - // break; - // case t_tab: - // fprintf(stdout, "tab:%d", token.pos.size); - // break; - // case t_newline: - // fprintf(stdout, "\\n offset:%d line:%d column:%d length:%d", - // token.pos.offset, token.pos.line, token.pos.column, - // token.pos.size); - // break; - default: - break; - } - - // puts(""); -} - /* Reads text and parses it into an array of tokens * @param text A buffer holding the input text * @return a pointer to dst @@ -375,15 +297,6 @@ l_read(char const* restrict text, usize text_length, (*dst)->elements[tokenno - 1].pos.size = ++cursor.size; } - // if (token == t_newline && token == token_previous) { - // cursor.size = 1; - - // (*dst)->elements[tokenno].type = token; - // (*dst)->elements[tokenno].pos = cursor; - - // token_previous = token; - //} - if (token != token_previous) { cursor.size = 1; @@ -405,10 +318,6 @@ l_read(char const* restrict text, usize text_length, (*dst)->length = tokenno; lines->length = cursor.line; - - // for (int line = 0; line < lines->length; line++) { - // printf("%d: line:%d\n", line, lines->elements[line]); - // } } return lines; @@ -459,8 +368,6 @@ p_arith(char const* restrict text, TokenList_t* restrict tokens) { tokens->elements[tokenidx].pos.column); return exp; } - printf("\nroot=node + "); - l_print_token(tokens->elements[tokenidx], text); expression[exp_idx] = p_number(text, &tokens->elements[tokenidx]); root->data.e_binary.b = &expression[exp_idx]; // "pop" "root" stack here? @@ -496,7 +403,6 @@ p_arith(char const* restrict text, TokenList_t* restrict tokens) { if ((expression[exp_idx].type == e_mul || expression[exp_idx].type == e_div) && (root->type == e_add || root->type == e_sub)) { - printf("\n # root < t # \n"); expression[exp_idx].data.e_binary.a = root->data.e_binary.b; // TODO: check precedence of exp vs root exp = root; @@ -511,14 +417,6 @@ p_arith(char const* restrict text, TokenList_t* restrict tokens) { exp_idx++; } - printf("\nexp:"); - print_aexp(exp); - printf("\nroot:"); - print_aexp(root); - printf("\n"); - for (int i = tokenidx; i < num_tokens; i++) { - l_print_token(tokens->elements[i], (const char* restrict)text); - } } return exp; } |
