lexer.c fix bug when assembly file ends with newline

This commit is contained in:
XOR 2023-04-19 17:33:22 +02:00
parent e6d112e263
commit 32159f7eb3

View file

@ -31,8 +31,7 @@ void lexer(FILE *input_file, char tokens[][MAX_TOKEN_SIZE])
if (is_pos_line_start)
{
// Loop trough Spaces and Tabs, to make empty lines and Indentation work
is_pos_line_start = 0;
// Loop trough Spaces, newlines and Tabs, to make empty lines and Indentation work
while (current_char != EOF && (current_char == ASCII_SPACE || current_char == ASCII_TAB || current_char == ASCII_NEWLINE))
{
current_char = (char)fgetc(input_file);
@ -84,12 +83,17 @@ void lexer(FILE *input_file, char tokens[][MAX_TOKEN_SIZE])
}
break;
default:
is_pos_line_start = 0;
strncat(tokens[token_index], &current_char, 1);
break;
}
}
tokens[token_index + 1][0] = ';';
tokens[token_index + 2][0] = EOF;
if(!is_pos_line_start)
{
tokens[token_index + 1][0] = ';';
tokens[token_index + 2][0] = EOF;
}
else tokens[token_index][0] = EOF;
}
void print_tokens(char tokens[][MAX_TOKEN_SIZE])