From 19c0d887b5f8ecb159efaffb29852ac86775d959 Mon Sep 17 00:00:00 2001 From: XOR Date: Mon, 25 Sep 2023 18:43:53 +0200 Subject: [PATCH] Added universal OS support and version bump to 0.2.1 beta --- .gitignore | 1 + header/common.h | 5 +---- src/lexer.c | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 3ad4899..c155c8d 100755 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,7 @@ dkms.conf #Code editor .vscode/* +.idea/* compile_commands.json .cache/* .#* diff --git a/header/common.h b/header/common.h index d1e641f..6a0305b 100755 --- a/header/common.h +++ b/header/common.h @@ -25,7 +25,7 @@ Here, common macros are specified #define VER_MAJOR "0" #define VER_MINOR "2" -#define VER_PATCH "0" +#define VER_PATCH "1" // alpha, beta or stable #define TAG "beta" @@ -46,9 +46,6 @@ Here, common macros are specified #define INSTR_JPU 0b1010 #define INSTR_EOJ 0b1011 -// get the character which the next fgetc() call would return -#define PREFGETC(file) *file->_IO_read_ptr - // const char *argp_program_bug_address = "eipabugs@outlook.com"; #define EIPA_BUG_ADRESS "eipabugs@outlook.com" diff --git a/src/lexer.c b/src/lexer.c index aef4249..f979418 100755 --- a/src/lexer.c +++ b/src/lexer.c @@ -10,6 +10,15 @@ This code contains the implementations of all functions related to the lexical a #include "../header/common.h" #include "../header/lexer.h" +// get the character which the next fgetc() call would return +static int prefgetc(FILE *fp) +{ + long origin = ftell(fp); + int read = fgetc(fp); + fseek(fp, origin, SEEK_SET); + return read; +} + void lexer(FILE *input_file, dynamic_buffer_t *tokens) { // Stores the current character we are examining @@ -53,7 +62,7 @@ void lexer(FILE *input_file, dynamic_buffer_t *tokens) // This is an indice of a new token begining, so we probably need to increase token_index // Loop to the characters until the next character fgetc() would read is not space or tab - while (PREFGETC(input_file) == ASCII_SPACE || PREFGETC(input_file) == ASCII_TAB) + while (prefgetc(input_file) == ASCII_SPACE || prefgetc(input_file) == ASCII_TAB) { current_char = (char)fgetc(input_file); } @@ -63,7 +72,7 @@ void lexer(FILE *input_file, dynamic_buffer_t *tokens) However, there can also be a space between the Adress and the newline. To not increase the token_index 2 times, we need to not increase it here if the next character is a \n */ - if (PREFGETC(input_file) != ';' && PREFGETC(input_file) != ASCII_NEWLINE) + if (prefgetc(input_file) != ';' && prefgetc(input_file) != ASCII_NEWLINE) { token_index++; } @@ -84,7 +93,7 @@ void lexer(FILE *input_file, dynamic_buffer_t *tokens) break; case ';': // Loop over the comment - while (PREFGETC(input_file) != ASCII_NEWLINE && PREFGETC(input_file) != '\0') + while (prefgetc(input_file) != ASCII_NEWLINE && prefgetc(input_file) != '\0') { current_char = (char)fgetc(input_file); }