diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2023-11-29 03:55:59 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2023-11-29 03:55:59 -0500 |
commit | 05de972109f323d972760af09f565b04cf26f69e (patch) | |
tree | 680e582fda3fdc626ecd768506342553a0d0c031 /compiler.c | |
parent | a646419ee347f8a26e81b96f86add1c123a508e9 (diff) |
initial compilation - print token list for testing
Diffstat (limited to 'compiler.c')
-rw-r--r-- | compiler.c | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -206,7 +206,7 @@ char *art_to_str(Artifact *art, char join) { for (size_t i = 0; i < art->count; i++) { char ** cpy = vect_get(art, i); - for(int j = 0; cpy[j] != 0; j++) { + for(int j = 0; (*cpy)[j] != 0; j++) { out[out_len] = (*cpy)[j]; out_len += 1; out = realloc(out, out_len + 1); @@ -612,6 +612,9 @@ Token parse_string_literal(int *ch, int *line, int *col, FILE *fin) { vect_push(&str, &first); + if (*ch == first) + *ch = fgetc(fin); + out.data = vect_as_string(&str); return out; @@ -788,7 +791,32 @@ Vector parse_file(FILE *fin) { // Compiler funcs void compile (Artifact path_in, Artifact path_out) { - + char *full_path = art_to_str(&path_in, '/'); + FILE *fin = fopen(full_path, "r"); + free(full_path); + + if (fin == NULL) + return; + + Vector tokens = parse_file(fin); + + fclose(fin); + + full_path = art_to_str(&path_out, '/'); + FILE *fout = fopen(full_path, "w"); + free(full_path); + + if (fout != NULL) { + // Write all tokens + for (size_t i = 0; i < tokens.count; i++) { + Token *t = vect_get(&tokens, i); + fprintf(fout, "{ line: %d, column: %d, type %d, data: %s }\n", t->line, t->col, t->type, t->data); + free(t->data); + } + } + vect_end(&tokens); + + fclose(fout); } // Entrypoint |