From f768d9bdb84e846d89aac66a4f3433a44241c298 Mon Sep 17 00:00:00 2001 From: Galin Simeonov Date: Mon, 17 May 2021 17:29:08 +0300 Subject: parser formed --- main.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index bfc09c0..438f282 100644 --- a/main.c +++ b/main.c @@ -1,8 +1,9 @@ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include @@ -12,18 +13,18 @@ int main(int argc,char **argv) struct Source *source; struct Program *program; struct Translation_Data *translation_data; + struct AST* translation_unit; - options=parse_command_line(argv); - if(options->source==NULL) + options=parse_command_line(argc,argv); + if(options->src_name==NULL) { printf("No source file specified\n"); return 0; } - source=extract_source(strdup(options->source)); + source=extract_source(strndup(options->src_name,100)); translation_data=get_translation_data(); - - if(options->print_tokens) + if(options->target==OPTION_TARGET_TOKENS || options->target==OPTION_TARGET_AST) { lex(translation_data->tokens,source,translation_data); if(translation_data->errors->size>0) @@ -31,11 +32,26 @@ int main(int argc,char **argv) printf("There was an error!\n"); print_tokens(translation_data->tokens); return 1; - }else + }else if(options->target==OPTION_TARGET_TOKENS) { print_tokens(translation_data->tokens); + }else if(options->target==OPTION_TARGET_AST) //we check because we will probably add more options + { + translation_unit=parse_unit(translation_data); + if(has_new_errors(translation_data)) + { + print_errors(translation_data); + return 1; + }else + { + print_ast(translation_unit); + delete_ast(translation_unit); + } } + }else + { + assert(!"false"); } delete_source(source); -- cgit v1.2.3