lexer.c fix bug when assembly file ends with newline
This commit is contained in:
parent
e6d112e263
commit
32159f7eb3
1 changed files with 8 additions and 4 deletions
12
src/lexer.c
12
src/lexer.c
|
|
@ -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], ¤t_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])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue