From 12f70b1a88c2e0f8590748c0d607c94fc9d89044 Mon Sep 17 00:00:00 2001 From: XOR Date: Sat, 30 Sep 2023 18:17:17 +0200 Subject: [PATCH] Exit the program if there were errors found --- src/error_analyzer.c | 3 ++- src/main.c | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/error_analyzer.c b/src/error_analyzer.c index 138b53d..53a6317 100644 --- a/src/error_analyzer.c +++ b/src/error_analyzer.c @@ -43,7 +43,8 @@ unsigned int check_token_errors(char tokens[][MAX_TOKEN_SIZE], shash_hashtable_t unsigned int *label_addr = shash_get(tokens[i], strlen(tokens[i]), &label_table); if(label_addr == NULL) { - printf("ERROR: Label %s has not been defined (Used at token %d)\n", tokens[i], i); + printf("ERROR: Label %s has not been defined (Used at token %d)\n", tokens[i], i); + error_count++; } // Check that the next token is a ; diff --git a/src/main.c b/src/main.c index a41e130..41debb8 100755 --- a/src/main.c +++ b/src/main.c @@ -163,8 +163,13 @@ int main(int argc, char **argv) // Check if the EIPA Assembly contains errors with the no_label_definition_tokens array shash_hashtable_t instruction_informations = create_instruction_information_hastable(); - printf("Found %d errors\n", check_token_errors((char (*)[MAX_TOKEN_SIZE]) no_label_definition_tokens.buffer, instruction_informations, label_table)); - + unsigned int error_c = check_token_errors((char (*)[MAX_TOKEN_SIZE]) no_label_definition_tokens.buffer, instruction_informations, label_table); + printf("Found %d errors\n", error_c); + if(error_c > 0) + { + return EXIT_FAILURE; + } + // Part II of processing labels dynamic_buffer_t tokens; init_dynamic_buffer(&tokens, TABLE_INIT_SIZE * MAX_TOKEN_SIZE, TABLE_GROW_SIZE * MAX_TOKEN_SIZE);