Fix some indenting and proceed with label processing
This commit is contained in:
parent
84a26a7189
commit
7ea187efc6
3 changed files with 52 additions and 40 deletions
|
@ -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
|
||||
|
|
10
src/labels.c
10
src/labels.c
|
@ -1,4 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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])
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue