summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-11-29 03:55:59 -0500
committerKyle Gunger <kgunger12@gmail.com>2023-11-29 03:55:59 -0500
commit05de972109f323d972760af09f565b04cf26f69e (patch)
tree680e582fda3fdc626ecd768506342553a0d0c031
parenta646419ee347f8a26e81b96f86add1c123a508e9 (diff)
initial compilation - print token list for testing
-rw-r--r--compiler.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/compiler.c b/compiler.c
index dc945bf..2081209 100644
--- a/compiler.c
+++ b/compiler.c
@@ -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