diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -1,23 +1,26 @@ #include <assert.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> #include <stdarg.h> #include <string.h> #include <ctype.h> #include <limits.h> -#include "util/colored_text.c" +#include <stdint.h> +#include <stdbool.h> #include "util/err.c" +#include "util/arr.c" #include "identifiers.c" #include "tokenizer.c" +#include "parse.c" int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "Please specify an input file.\n"); return EXIT_FAILURE; } - - FILE *in = fopen(argv[1], "r"); + + const char *in_filename = argv[1]; + FILE *in = fopen(in_filename, "r"); if (!in) { fprintf(stderr, "Could not open file: %s.\n", argv[1]); return EXIT_FAILURE; @@ -38,18 +41,28 @@ int main(int argc, char **argv) { fprintf(stderr, "Error reading input file: %s.\n", argv[1]); return EXIT_FAILURE; } + + err_filename = in_filename; + Tokenizer t; + if (!tokenize_string(&t, contents)) { + err_fprint(TEXT_IMPORTANT("Errors occured while preprocessing.\n")); + return EXIT_FAILURE; + } - Tokenizer t = tokenize_string(contents); - - for (size_t i = 0; i < t.ntokens; i++) { - if (i) + arr_foreach(t.tokens, Token, token) { + if (token != t.tokens.data) printf(" "); - token_fprint(stdout, &t.tokens[i]); + token_fprint(stdout, token); } printf("\n"); + + ParsedFile f; + parse_file(&f, &t); + parsed_file_fprint(stdout, &f); + + tokr_free(&t); free(contents); - tokenizer_free(&t); fclose(in); idents_free(); |