From 88b19f1ca42cd71d64a658ef3ad5a81589319e37 Mon Sep 17 00:00:00 2001 From: xolatile Date: Fri, 5 Apr 2024 04:43:29 -0400 Subject: [PATCH] Working on adding variables... --- xiranda.c | 191 ++++++++++++++++---------------------------------------------- 1 file changed, 50 insertions(+), 141 deletions(-) diff --git a/xiranda.c b/xiranda.c index fda77c1..28ccbdf 100644 --- a/xiranda.c +++ b/xiranda.c @@ -1,57 +1,62 @@ #include #include -static int coin_code = 0;/* +static int coin_code = 0; static int type_code = 0; -static int function_code = 0; -static int variable_code = 0; -static int constant_code = 0;*/ +static int variable_code = 0;/* +static int constant_code = 0; +static int function_code = 0;*/ + +static int coin_data [240] = { 0 }; +static int coin_size [240] = { 0 }; +static char coin_text [240] [40] = { "" }; -static int coin_enum [240] = { 0 }; -static int coin_data [240] = { 0 }; -static int coin_size [240] = { 0 }; -static char coin_text [240] [40] = { "" }; -/* static char type_name [27] [40] = { "" }; static int type_size [27] = { 0 }; +static char variable_name [27] [40] = { "" }; +static int variable_type [27] = { 0 }; +static int variable_data [27] = { 0 }; +/* +static char constant_name [30] [40] = { "" }; +static int constant_type [30] = { 0 }; +static int constant_data [30] = { 0 }; + static char function_name [9] [40] = { "" }; static int function_type [9] = { 0 }; static char function_argument_name [9] [6] [40] = { { "" } }; static int function_argument_type [9] [6] = { { 0 } }; - -static char variable_name [27] [40] = { "" }; -static int variable_type [27] = { 0 }; -static int variable_data [27] = { 0 }; - -static char constant_name [30] [40] = { "" }; -static int constant_type [30] = { 0 }; -static int constant_data [30] = { 0 }; */ #include -/* -static char * word_list [] = { - "type", "loop", "if", "else", "case", "return", "import", "system" -}; +#include +/* static char * register_list [] = { "rax","rdi","rsi","rdx","r10","r8","r9" }; */ -static void add_coin (int type, int data, int size, char * text) { - coin_enum [coin_code] = type; +static void add_coin (int data, int size, char * text) { coin_data [coin_code] = data; coin_size [coin_code] = size; - string_copy (coin_text [coin_code], text); + string_copy_limit (coin_text [coin_code], text, size); ++coin_code; } +static void kill (char * text) { + terminal_colour (colour_red, effect_bold); + echo (text); + terminal_cancel (); + exit (log_failure); +} + int main (void) { char * buffer = null; int offset = 0; int length = 0; int select = 0; + /**/int i; + int coin_string = syntax_define (false, false, "\"", "\"", '\\', colour_red, effect_normal); int coin_type = syntax_define (false, true, "type", " \t\n", '\0', colour_yellow, effect_normal); int coin_loop = syntax_define (false, true, "loop", " \t\n(:", '\0', colour_yellow, effect_normal); @@ -71,135 +76,39 @@ int main (void) { select = syntax_select (& buffer [offset], & length); if (select < syntax_count) { terminal_colour (syntax_colour [select], syntax_effect [select]); - add_coin (select, 0, length, & buffer [offset]); + add_coin (select, length, & buffer [offset]); } else { terminal_colour (colour_red, effect_bold); if (character_compare_array (buffer [offset], " \t\n") == false) { - printf ("ERROR!\n"); - exit (1); + kill ("Illegal character...\n"); } } out (& buffer [offset], length); terminal_cancel (); } -int i; - for (i = 0; i < coin_code; ++i) printf ("--- %2i : %2i = %.*s\n", coin_enum [i], coin_size [i], coin_size [i], coin_text [i]); -/* - for (offset = 0; buffer [offset] != '\0'; ++offset) { - int size = 0; - char data [STRING_LIMIT] = ""; - if (buffer [offset] == '"') { - for (++offset; (buffer [offset] != '"') && (buffer [offset] != '\0'); ++offset) { - data [size++] = buffer [offset]; - } - data [size] = '\0'; - add_coin (coin_string, 0, data); - } else if (character_is_digit (buffer [offset]) == true) { - for (; (character_is_digit (buffer [offset]) == true) && (buffer [offset] != '\0'); ++offset) { - data [size++] = buffer [offset]; - } - add_coin (coin_number, 0, data); - data [size] = '\0'; - --offset; - } else if (character_is_alpha (buffer [offset]) == true) { - for (; ((character_is_alpha (buffer [offset]) == true) || - (character_is_digit (buffer [offset]) == true) || - (character_is_underscore (buffer [offset]) == true)) && (buffer [offset] != '\0'); ++offset) { - data [size++] = buffer [offset]; - } - data [size] = '\0'; - for (length = 0; length < (int) (sizeof (word_list) / sizeof (word_list [0])); ++length) { - if (string_compare_limit (data, word_list [length], string_length (word_list [length]) + 1) == true) { - add_coin (length, 0, data); - goto here; - } - } - add_coin (coin_marker, 0, data); - if (coin_enum [coin_code - 2] == coin_type) { - coin_enum [coin_code - 1] = coin_data; - string_copy (type_name [type_code], coin_text [coin_code - 1]); - type_size [type_code] = 8; - ++type_code; - } - for (length = 0; length < type_code; ++length) { - if (string_compare_limit (data, type_name [length], string_length (type_name [length]) + 1) == true) { - coin_enum [coin_code - 1] = coin_data; - } - } - here: - --offset; - } else if (character_compare_array (buffer [offset], ",.;:=<>#&|!+*-/%()[]") == true) { - char s [2] = ""; - s [0] = buffer [offset]; - add_coin (coin_symbol, (int) buffer [offset], s); - } else { - if (character_is_blank (buffer [offset]) == false) { - echo ("\033[1;31mCharacter set exception point: Segmentation\033[0m\n"); - printf ("%c -- %i\n", buffer [offset], (int) buffer [offset]); - exit (log_failure); - } - }*/ -/* - for (length = 0; length < coin_code; ++length) { - switch (coin_enum [length]) { - case coin_string: printf ("\033[1;32m%s\033[0m ", coin_text [length]); break; - case coin_number: printf ("\033[1;34m%s\033[0m ", coin_text [length]); break; - case coin_data: printf ("\033[1;36m%s\033[0m ", coin_text [length]); break; - case coin_marker: printf ("\033[1;37m%s\033[0m ", coin_text [length]); break; - case coin_type: - case coin_if: - case coin_else: - case coin_case: - case coin_loop: - case coin_import: - case coin_system: - case coin_return: printf ("\033[1;33m%s\033[0m ", coin_text [length]); break; - case coin_symbol: printf ("\033[1;35m%s\033[0m ", coin_text [length]); break; - default: printf ("\033[1;31m%s\033[0m ", coin_text [length]); break; + + for (offset = 0; offset < coin_code; ++offset) { + if (coin_data [offset] == coin_type) { + ++offset; + if (coin_data [offset] == coin_marker) { + string_copy (type_name [type_code], coin_text [offset]); + ++offset; + if ((coin_data [offset] == coin_symbol) && (* coin_text [offset] == '=')) { + ++offset; + if (coin_data [offset] == coin_number) { + type_size [type_code] = atoi (coin_text [offset]); + ++offset; + if ((coin_data [offset] == coin_symbol) && (* coin_text [offset] == ';')) { + ++type_code; + } else kill ("Expected semicolon symbol...\n"); + } else kill ("Expected number...\n"); + } else kill ("Expected equal symbol...\n"); + } else kill ("Expected marker...\n"); } } - printf ("\n"); + /**/for (i = 0; i < type_code; ++i) printf ("-type- %s : %i\n", type_name [i], type_size [i]); - printf ("format ELF64 executable 3\n\n"); - printf ("segment readable executable\n\n"); - printf ("entry main\n\n"); - printf ("main:\n\n"); - - for (length = 0; length < coin_code; ++length) { - if ((coin_enum [length] == coin_return) && (coin_data [length + 1] == ';')) { - printf ("; return;\nxor rax, rax\nret\n\n"); - length += 1; - } else if ((coin_enum [length] == coin_return) && (coin_enum [length + 1] == coin_number) && (coin_data [length + 2] == ';')) { - printf ("; return {number};\nmov rax, %s\nret\n\n", coin_text [length + 1]); - length += 2; - } else if ((coin_enum [length] == coin_system) && (coin_data [length + 1] == '(')) { - int use = 0; - printf ("; system ({...});\n"); - length += 2; - while (coin_data [length] != ')') { - switch (coin_enum [length]) { - case coin_symbol: if (coin_data [length] == '#') {length += 1; printf ("mov %s, %s\n", register_list [use], coin_text [length]); use++; } break; - case coin_number: printf ("mov %s, %s\n", register_list [use], coin_text [length]); use++; break; - case coin_marker: printf ("mov %s, [%s]\n", register_list [use], coin_text [length]); use++; break; - default: break; - } - length += 1; - if (coin_data [length] == ',') - length += 1; - } - length += 1; - if (coin_data [length] != ';') - echo ("EXPECTED STOP WORD ';'\n"); - printf ("syscall\n\n"); - } - } - - printf (";end\nmov rax, 60\nmov rdi, 0\nsyscall\n\n"); - printf ("segment readable writable\n\n"); - printf ("text db 'Heyo world!', 10, 0\n\n"); - printf ("size dq 12\n\n"); -*/ buffer = deallocate (buffer); return (log_success);