Compare commits
3 commits
38d14eec25
...
44beccfd06
| Author | SHA1 | Date | |
|---|---|---|---|
| 44beccfd06 | |||
| 26095748df | |||
| edf807a5b3 |
4 changed files with 28 additions and 1 deletions
|
|
@ -33,6 +33,7 @@ Here, common macros are specified
|
|||
#define ASCII_TAB 9
|
||||
#define ASCII_SPACE 32
|
||||
#define ASCII_NEWLINE 10
|
||||
#define ASCII_CARRIAGE_RETURN 13
|
||||
|
||||
#define INSTR_INP 0b0001
|
||||
#define INSTR_OUT 0b0010
|
||||
|
|
|
|||
|
|
@ -60,10 +60,12 @@ unsigned int check_token_errors(char tokens[][MAX_TOKEN_SIZE], shash_hashtable_t
|
|||
break;
|
||||
}
|
||||
}
|
||||
// Do not fall through
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
// fall through
|
||||
case 0:
|
||||
{
|
||||
// Check the adress stored at the next token
|
||||
|
|
|
|||
24
src/lexer.c
24
src/lexer.c
|
|
@ -91,6 +91,30 @@ void lexer(FILE *input_file, dynamic_buffer_t *tokens)
|
|||
|
||||
is_pos_line_start = 1;
|
||||
break;
|
||||
case ASCII_CARRIAGE_RETURN:
|
||||
// Some operating systems use \r\n or just \r for newlines in texts.
|
||||
|
||||
// This is a indice of a new token -> increase token_index
|
||||
token_index++;
|
||||
|
||||
// This also is a indice of a new instruction beginning
|
||||
// in the tokens array, instructions are seperated by semicolons
|
||||
((char (*)[MAX_TOKEN_SIZE]) tokens->buffer)[token_index][0] = ';';
|
||||
tokens->used += MAX_TOKEN_SIZE;
|
||||
|
||||
// Since the Instruction seperator (';') is also a token, we need to increase token_index again
|
||||
token_index++;
|
||||
|
||||
// Check for \r\n
|
||||
if((char) prefgetc(input_file) == ASCII_NEWLINE)
|
||||
{
|
||||
// Skip over this \n
|
||||
current_char = fgetc(input_file);
|
||||
}
|
||||
|
||||
is_pos_line_start = 1;
|
||||
break;
|
||||
|
||||
case ';':
|
||||
// Loop over the comment
|
||||
while (prefgetc(input_file) != ASCII_NEWLINE && prefgetc(input_file) != '\0')
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ int main(int argc, char **argv)
|
|||
|
||||
// Tokenize the EIPA Assembly
|
||||
FILE *assembly_file;
|
||||
assembly_file = fopen(arguments.input_file, "r");
|
||||
assembly_file = fopen(arguments.input_file, "rb");
|
||||
if (assembly_file == NULL)
|
||||
{
|
||||
printf("Error: Couldn't open input file\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue