diff --git a/src/error_analyzer.c b/src/error_analyzer.c index a3ac3df..0d6ea00 100644 --- a/src/error_analyzer.c +++ b/src/error_analyzer.c @@ -32,45 +32,45 @@ unsigned int check_token_errors(char tokens[][MAX_TOKEN_SIZE], shash_hashtable_t { switch (current_token_info->supports_adress_label) { - case 1: - /* Labels are not implemented yet - When they are, we need to check wether we got a label, - And if yes, we need to make sure the label exists */ - case 0: - { - // Check the adress stored at the next token - i++; - if(tokens[i][0] == ';') - { - printf("ERROR: expected adress at token %d\n", i); - error_count++; - break; - } - - - int adress = atoi(tokens[i]); - if (adress > MAX_MEMORY || adress < 1) + case 1: + /* Labels are not implemented yet + When they are, we need to check wether we got a label, + And if yes, we need to make sure the label exists */ + case 0: { - printf("ERROR: Adress %s at token %d is invalid\n", tokens[i], i); - error_count++; + // Check the adress stored at the next token + i++; + if(tokens[i][0] == ';') + { + printf("ERROR: expected adress at token %d\n", i); + error_count++; + break; + } + + + int adress = atoi(tokens[i]); + if (adress > MAX_MEMORY || adress < 1) + { + printf("ERROR: Adress %s at token %d is invalid\n", tokens[i], i); + error_count++; + } + + // Check that the next token is a ; + i++; + if (tokens[i][0] != ';') + { + printf("ERROR: Expected end of instruction at %d but found \"%s\"\n", i, tokens[i]); + error_count++; + + // Loop to the next ; + for (; tokens[i][0] != ';'; i++) + { + if (tokens[i][0] == EOF) + break; + } + } + break; } - - // Check that the next token is a ; - i++; - if (tokens[i][0] != ';') - { - printf("ERROR: Expected end of instruction at %d but found \"%s\"\n", i, tokens[i]); - error_count++; - - // Loop to the next ; - for (; tokens[i][0] != ';'; i++) - { - if (tokens[i][0] == EOF) - break; - } - } - break; - } } } else diff --git a/src/labels.c b/src/labels.c index 08953c8..c6cb3a8 100644 --- a/src/labels.c +++ b/src/labels.c @@ -1,4 +1,5 @@ #include +#include #include "../header/labels.h" void build_label_table(char label_tokens[][MAX_TOKEN_SIZE], shash_hashtable_t *label_table) @@ -16,7 +17,14 @@ void build_label_table(char label_tokens[][MAX_TOKEN_SIZE], shash_hashtable_t *l void remove_label_definition_tokens(char label_tokens[][MAX_TOKEN_SIZE], char no_label_definition_tokens[][MAX_TOKEN_SIZE]) { - + unsigned int new_index = 0; + for(unsigned int i = 0; label_tokens[i][0] != EOF; i++) + { + if(label_tokens[i][0] == '$') continue; + strncpy(no_label_definition_tokens[new_index], label_tokens[i], MAX_TOKEN_SIZE); + new_index++; + } + no_label_definition_tokens[new_index][0] = EOF; } void replace_labels_with_adresses(char no_label_definition_tokens[][MAX_TOKEN_SIZE], char tokens[][MAX_TOKEN_SIZE]) diff --git a/src/main.c b/src/main.c index 4928232..483cbef 100755 --- a/src/main.c +++ b/src/main.c @@ -122,7 +122,10 @@ int main(int argc, char **argv) FILE *assembly_file; assembly_file = fopen(arguments.input_file, "r"); if (assembly_file == NULL) - return EXIT_FAILURE; + { + printf("Error: Couldn't open input file\n"); + return EXIT_FAILURE; + } char(*label_tokens)[MAX_TOKEN_SIZE] = calloc(MAX_MEMORY, sizeof(*label_tokens)); if (label_tokens == NULL) @@ -154,7 +157,8 @@ 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(no_label_definition_tokens, instruction_informations)); - + exit(0); + // Part II of processing labels char(*tokens)[MAX_TOKEN_SIZE] = calloc(MAX_MEMORY, sizeof(*tokens)); if (tokens == NULL)