diff options
author | Bad Diode <bd@badd10de.dev> | 2021-10-29 19:11:40 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2021-10-29 19:11:40 +0200 |
commit | 5ed73b695e6b463149ab0c9ae3eccb26a4ec5807 (patch) | |
tree | 01aa089934d1b49fe515fe86fffca01c471c69e9 /src/main.c | |
parent | e73a4c16a2269cdb2f5e7d66fb9839e4c44e14de (diff) | |
download | bdl-5ed73b695e6b463149ab0c9ae3eccb26a4ec5807.tar.gz bdl-5ed73b695e6b463149ab0c9ae3eccb26a4ec5807.zip |
Add parser for tokens->ast conversion
Diffstat (limited to 'src/main.c')
-rwxr-xr-x | src/main.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -7,6 +7,7 @@ | |||
7 | #include "string_view.c" | 7 | #include "string_view.c" |
8 | #include "errors.c" | 8 | #include "errors.c" |
9 | #include "lexer.c" | 9 | #include "lexer.c" |
10 | #include "parser.c" | ||
10 | 11 | ||
11 | void | 12 | void |
12 | init(void) { | 13 | init(void) { |
@@ -20,20 +21,32 @@ halt(void) { | |||
20 | 21 | ||
21 | void | 22 | void |
22 | process_source(const StringView *source, const char *file_name) { | 23 | process_source(const StringView *source, const char *file_name) { |
24 | Errors errors = {0}; | ||
25 | |||
23 | // Read tokens. | 26 | // Read tokens. |
24 | Tokens tokens = tokenize(source); | 27 | Token *tokens = tokenize(source, &errors); |
25 | if (tokens.errors.n != 0) { | 28 | if (errors.n != 0) { |
26 | report_errors(&tokens.errors, file_name); | 29 | report_errors(&errors, file_name); |
30 | array_free(tokens); | ||
31 | exit(EXIT_FAILURE); | ||
32 | } | ||
33 | |||
34 | // Parser. | ||
35 | Root *roots = parse(tokens, &errors); | ||
36 | if (errors.n != 0) { | ||
37 | report_errors(&errors, file_name); | ||
38 | free_roots(roots); | ||
39 | array_free(tokens); | ||
27 | exit(EXIT_FAILURE); | 40 | exit(EXIT_FAILURE); |
28 | } | 41 | } |
42 | array_free(tokens); | ||
29 | 43 | ||
30 | // TODO: Parser. | ||
31 | // TODO: Semantic analysis. | 44 | // TODO: Semantic analysis. |
32 | // TODO: Optimization. | 45 | // TODO: Optimization. |
33 | // TODO: Compilation. | 46 | // TODO: Compilation. |
34 | 47 | ||
35 | // Free resources. | 48 | // Free resources. |
36 | array_free(tokens.tokens); | 49 | free_roots(roots); |
37 | } | 50 | } |
38 | 51 | ||
39 | void | 52 | void |