From e712a347b856c6be7784739f035e7ab85764565d Mon Sep 17 00:00:00 2001 From: XOR Date: Sat, 24 Dec 2022 01:02:09 +0100 Subject: [PATCH] Add Versioning and finish Parser --- main.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 42cad92..126900e 100644 --- a/main.c +++ b/main.c @@ -3,10 +3,32 @@ #include #define MAX_MEMORY 1000000 +#define INSTRUCTION_OPERATION 0 +#define INSTRUCTION_ADRESS 1 +//#define INSTRUCTION_COMMENT 2 -// 0 = Operation | 1 = Adress | 2 = Comment -int instruction_part=0; +#define ALPHA 0 +#define BETA 1 +#define STABLE 2 +#define VER_MAJOR 0 +#define VER_MINOR 1 +#define VER_PATCH 0 +#define TAG ALPHA + +int saveinstructionpart(unsigned short int part, char content[]) +{ + strcat(content,"\0"); //REMOVE + if(part==INSTRUCTION_OPERATION) + { + printf("Operation: %s\n",content); + } + else + { + printf("Adress: %s\n",content); + } + return 0; +} int main(int argc, char const *argv[]) { @@ -22,12 +44,42 @@ int main(int argc, char const *argv[]) int *instructions = malloc(MAX_MEMORY*sizeof(int8_t)); char current_char = fgetc(assembly_file); char instruction_part_string[10]; + int instruction_part=0; // 0 = Operation | 1 = Adress | 2 = Comment REMOVE COMMENT while(current_char!=EOF) { - printf("%c",current_char); + //printf("%c",current_char); + if(current_char=='\n') + { + saveinstructionpart(instruction_part,instruction_part_string); + instruction_part = 0; + strcpy(instruction_part_string,""); + } + else if(current_char==';') + { + saveinstructionpart(instruction_part,instruction_part_string); + instruction_part=0; + strcpy(instruction_part_string,""); + while(current_char!='\n' && current_char!=EOF) + { + current_char = fgetc(assembly_file); + } + } + + else if(current_char==' ') + { + saveinstructionpart(instruction_part,instruction_part_string); + instruction_part++; + strcpy(instruction_part_string,""); + } + else + { + strncat(instruction_part_string,¤t_char,1); + } + current_char = fgetc(assembly_file); } + saveinstructionpart(instruction_part,instruction_part_string); fclose(assembly_file); return 0; } \ No newline at end of file