From 5ed73b695e6b463149ab0c9ae3eccb26a4ec5807 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 29 Oct 2021 19:11:40 +0200 Subject: Add parser for tokens->ast conversion --- src/main.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/main.c') 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 @@ #include "string_view.c" #include "errors.c" #include "lexer.c" +#include "parser.c" void init(void) { @@ -20,20 +21,32 @@ halt(void) { void process_source(const StringView *source, const char *file_name) { + Errors errors = {0}; + // Read tokens. - Tokens tokens = tokenize(source); - if (tokens.errors.n != 0) { - report_errors(&tokens.errors, file_name); + Token *tokens = tokenize(source, &errors); + if (errors.n != 0) { + report_errors(&errors, file_name); + array_free(tokens); + exit(EXIT_FAILURE); + } + + // Parser. + Root *roots = parse(tokens, &errors); + if (errors.n != 0) { + report_errors(&errors, file_name); + free_roots(roots); + array_free(tokens); exit(EXIT_FAILURE); } + array_free(tokens); - // TODO: Parser. // TODO: Semantic analysis. // TODO: Optimization. // TODO: Compilation. // Free resources. - array_free(tokens.tokens); + free_roots(roots); } void -- cgit v1.2.1