aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-29 19:11:40 +0200
committerBad Diode <bd@badd10de.dev>2021-10-29 19:11:40 +0200
commit5ed73b695e6b463149ab0c9ae3eccb26a4ec5807 (patch)
tree01aa089934d1b49fe515fe86fffca01c471c69e9 /src/main.c
parente73a4c16a2269cdb2f5e7d66fb9839e4c44e14de (diff)
downloadbdl-5ed73b695e6b463149ab0c9ae3eccb26a4ec5807.tar.gz
bdl-5ed73b695e6b463149ab0c9ae3eccb26a4ec5807.zip
Add parser for tokens->ast conversion
Diffstat (limited to 'src/main.c')
-rwxr-xr-xsrc/main.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 90860e8..c734916 100755
--- a/src/main.c
+++ b/src/main.c
@@ -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
11void 12void
12init(void) { 13init(void) {
@@ -20,20 +21,32 @@ halt(void) {
20 21
21void 22void
22process_source(const StringView *source, const char *file_name) { 23process_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
39void 52void