#include enum { coin_none, coin_type, coin_loop, coin_if, coin_else, coin_case, coin_return, coin_import, coin_system, coin_function, coin_variable, coin_constant, coin_data_type, coin_string, coin_number, coin_marker, coin_label, coin_add, coin_subtract, coin_multiply, coin_divide, coin_modulus, coin_equal, coin_above, coin_below, coin_open, coin_close, coin_next, coin_stop, coin_branch, coin_and, coin_or, coin_not, coin_range, coin_enrange, coin_derange, coin_machine }; 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 coin_enum [240] = { 0 }; static int coin_data [240] = { 0 }; static char coin_text [240] [40] = { "" }; /* static char type_name [27] [40] = { "" }; static int type_size [27] = { 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 #define STRING_LIMIT (40) static char * word_list [] = { "type", "loop", "if", "else", "case", "return", "import", "system" }; static void add_coin (int type, int data, char * text) { coin_enum [coin_code] = type; coin_data [coin_code] = data; string_copy (coin_text [coin_code], text); ++coin_code; } /* static void add_type (char * name, int size) { string_copy (type_name [type_code], name); type_size [type_code] = size; ++type_code; } static void add_function (char * name, int type, char * * agrument_name, int * argument_type) { string_copy (type_name [type_code], name); type_size [type_code] = size; ++type_code; } */ int main (void) { char * buffer = null; int offset = 0; int length = 0; buffer = file_import ("./test_x.x"); 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) { data [0] = buffer [offset]; for (++offset; (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_count - 2] == coin_word) && (coin_data [coin_count - 2] == word_type)) { coin_enum [coin_count - 1] = coin_type; } 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_count - 1] = coin_type; } }*/ here: --offset; } else if (character_compare_array (buffer [offset], ",.;:=<>#&|!+*-/%()[]") == true) { char s [2] = ""; s [0] = buffer [offset]; add_coin (coin_none, 0, 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;36m%s\033[0m ", coin_text [length]); break; case coin_number: printf ("\033[1;34m%s\033[0m ", coin_text [length]); break; /*case coin_type: 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; default: printf ("\033[1;31m%s\033[0m ", coin_text [length]); break; } } printf ("\n"); /* for (length = 0; length < coin_count; ++length) { if ((coin_enum [length] == coin_word) && (coin_data [length] == word_return)) { ++length; if ((coin_enum [length] == coin_symbol) && (symbol_data [coin_data [length]] == '(')) { echo ("return (\n"); ++length; } else if ((coin_enum [length] == coin_symbol) && (symbol_data [coin_data [length]] == ';')) { echo ("; return;\nxor rax, rax\nret\n"); ++length; } else if (coin_enum [length] == coin_number && (coin_enum [length + 1] == coin_symbol) && (symbol_data [coin_data [length + 1]] == ';')) { printf ("; return {number};\nmov rax, %i\nret\n", number_data [coin_data [length]]); ++length; } else { kill ("return ?\n"); } } else if ((coin_enum [length] == coin_word) && (coin_data [length] == word_if)) { ++length; if ((coin_enum [length] == coin_symbol) && (symbol_data [coin_data [length]] == '(')) { echo ("if (\n"); ++length; } else { kill ("if ?\n"); } } else if ((coin_enum [length] == coin_word) && (coin_data [length] == word_else)) { ++length; if ((coin_enum [length] == coin_symbol) && (symbol_data [coin_data [length]] == ':')) { echo ("else :\n"); ++length; } else if ((coin_enum [length] == coin_word) && (coin_data [length] == word_if)) { echo ("else if\n"); ++length; } else { echo ("else expression\n"); } } else if ((coin_enum [length] == coin_word) && (coin_data [length] == word_type)) { ++length; if (coin_enum [length] == coin_type) { echo ("type -- "); echo (marker_name [coin_data [length]]); echo ("\n"); ++length; } else { kill ("type ?\n"); } } } */ buffer = deallocate (buffer); return (log_success); }