From edf807a5b3a99d0a4147f9f541f3ad68655129ce Mon Sep 17 00:00:00 2001 From: XOR Date: Sat, 30 Sep 2023 16:49:50 +0200 Subject: [PATCH 1/3] Open eipa assembly in binary mode, to make LF files work in Windows --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index dc77423..a41e130 100755 --- a/src/main.c +++ b/src/main.c @@ -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"); From 26095748df3a4e46b45a06f48544f808373f9121 Mon Sep 17 00:00:00 2001 From: XOR Date: Sat, 30 Sep 2023 16:51:10 +0200 Subject: [PATCH 2/3] Add support for CRLF text files --- header/common.h | 1 + src/lexer.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/header/common.h b/header/common.h index 6a0305b..fb4576a 100755 --- a/header/common.h +++ b/header/common.h @@ -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 diff --git a/src/lexer.c b/src/lexer.c index f979418..ea4b382 100755 --- a/src/lexer.c +++ b/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') From 44beccfd06bc82f23ab48f12f93ed0d764342c24 Mon Sep 17 00:00:00 2001 From: XOR Date: Sat, 30 Sep 2023 16:51:47 +0200 Subject: [PATCH 3/3] mark fall through as intentional --- src/error_analyzer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/error_analyzer.c b/src/error_analyzer.c index 5c37d85..138b53d 100644 --- a/src/error_analyzer.c +++ b/src/error_analyzer.c @@ -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