2024-03-31 22:58:48 -04:00
|
|
|
#include <xolatile/xtandard.c>
|
|
|
|
|
|
|
|
enum {
|
2024-04-03 05:03:46 -04:00
|
|
|
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
|
2024-03-31 22:58:48 -04:00
|
|
|
};
|
|
|
|
|
2024-04-03 07:39:59 -04:00
|
|
|
static int coin_code = 0;
|
|
|
|
static int type_code = 0;/*
|
2024-04-03 04:31:51 -04:00
|
|
|
static int function_code = 0;
|
|
|
|
static int variable_code = 0;
|
2024-04-03 06:10:35 -04:00
|
|
|
static int constant_code = 0;*/
|
2024-04-03 05:03:46 -04:00
|
|
|
|
2024-04-03 06:10:35 -04:00
|
|
|
static int coin_enum [240] = { 0 };
|
|
|
|
static int coin_data [240] = { 0 };
|
|
|
|
static char coin_text [240] [40] = { "" };
|
2024-04-03 07:39:59 -04:00
|
|
|
|
2024-04-03 05:03:46 -04:00
|
|
|
static char type_name [27] [40] = { "" };
|
|
|
|
static int type_size [27] = { 0 };
|
2024-04-03 07:39:59 -04:00
|
|
|
/*
|
2024-04-03 04:31:51 -04:00
|
|
|
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 } };
|
2024-03-31 22:58:48 -04:00
|
|
|
|
2024-04-03 04:31:51 -04:00
|
|
|
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 };
|
2024-04-03 06:10:35 -04:00
|
|
|
*/
|
2024-03-31 22:58:48 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2024-04-03 06:10:35 -04:00
|
|
|
#define STRING_LIMIT (40)
|
|
|
|
|
2024-03-31 22:58:48 -04:00
|
|
|
static char * word_list [] = {
|
2024-04-02 11:36:20 -04:00
|
|
|
"type", "loop", "if", "else", "case", "return", "import", "system"
|
2024-03-31 22:58:48 -04:00
|
|
|
};
|
|
|
|
|
2024-04-03 06:10:35 -04:00
|
|
|
static void add_coin (int type, int data, char * text) {
|
|
|
|
coin_enum [coin_code] = type;
|
2024-04-03 05:03:46 -04:00
|
|
|
coin_data [coin_code] = data;
|
2024-04-03 06:10:35 -04:00
|
|
|
string_copy (coin_text [coin_code], text);
|
2024-04-03 05:03:46 -04:00
|
|
|
++coin_code;
|
|
|
|
}
|
|
|
|
|
2024-03-31 22:58:48 -04:00
|
|
|
int main (void) {
|
|
|
|
char * buffer = null;
|
|
|
|
int offset = 0;
|
|
|
|
int length = 0;
|
|
|
|
|
2024-04-03 12:29:54 -04:00
|
|
|
buffer = record ();
|
2024-03-31 22:58:48 -04:00
|
|
|
|
|
|
|
for (offset = 0; buffer [offset] != '\0'; ++offset) {
|
2024-04-03 06:10:35 -04:00
|
|
|
int size = 0;
|
|
|
|
char data [STRING_LIMIT] = "";
|
2024-04-03 05:03:46 -04:00
|
|
|
if (buffer [offset] == '"') {
|
2024-03-31 22:58:48 -04:00
|
|
|
for (++offset; (buffer [offset] != '"') && (buffer [offset] != '\0'); ++offset) {
|
|
|
|
data [size++] = buffer [offset];
|
|
|
|
}
|
|
|
|
data [size] = '\0';
|
2024-04-03 06:10:35 -04:00
|
|
|
add_coin (coin_string, 0, data);
|
2024-03-31 22:58:48 -04:00
|
|
|
} else if (character_is_digit (buffer [offset]) == true) {
|
2024-04-03 07:39:59 -04:00
|
|
|
for (; (character_is_digit (buffer [offset]) == true) && (buffer [offset] != '\0'); ++offset) {
|
2024-04-03 06:10:35 -04:00
|
|
|
data [size++] = buffer [offset];
|
2024-03-31 22:58:48 -04:00
|
|
|
}
|
2024-04-03 06:10:35 -04:00
|
|
|
add_coin (coin_number, 0, data);
|
|
|
|
data [size] = '\0';
|
2024-03-31 22:58:48 -04:00
|
|
|
--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) {
|
2024-04-03 06:10:35 -04:00
|
|
|
data [size++] = buffer [offset];
|
2024-03-31 22:58:48 -04:00
|
|
|
}
|
2024-04-03 06:10:35 -04:00
|
|
|
data [size] = '\0';
|
2024-04-02 11:36:20 -04:00
|
|
|
for (length = 0; length < (int) (sizeof (word_list) / sizeof (word_list [0])); ++length) {
|
2024-04-03 06:10:35 -04:00
|
|
|
if (string_compare_limit (data, word_list [length], string_length (word_list [length]) + 1) == true) {
|
|
|
|
add_coin (length, 0, data);
|
2024-03-31 22:58:48 -04:00
|
|
|
goto here;
|
|
|
|
}
|
|
|
|
}
|
2024-04-03 06:10:35 -04:00
|
|
|
add_coin (coin_marker, 0, data);
|
2024-04-03 07:39:59 -04:00
|
|
|
if (coin_enum [coin_code - 2] == coin_type) {
|
|
|
|
coin_enum [coin_code - 1] = coin_data_type;
|
|
|
|
string_copy (type_name [type_code], coin_text [coin_code - 1]);
|
|
|
|
type_size [type_code] = 8;
|
|
|
|
++type_code;
|
2024-04-01 07:23:49 -04:00
|
|
|
}
|
|
|
|
for (length = 0; length < type_code; ++length) {
|
2024-04-03 06:10:35 -04:00
|
|
|
if (string_compare_limit (data, type_name [length], string_length (type_name [length]) + 1) == true) {
|
2024-04-03 07:39:59 -04:00
|
|
|
coin_enum [coin_code - 1] = coin_data_type;
|
2024-04-01 07:23:49 -04:00
|
|
|
}
|
2024-04-03 07:39:59 -04:00
|
|
|
}
|
2024-04-01 07:23:49 -04:00
|
|
|
here:
|
2024-03-31 22:58:48 -04:00
|
|
|
--offset;
|
2024-04-03 06:10:35 -04:00
|
|
|
} else if (character_compare_array (buffer [offset], ",.;:=<>#&|!+*-/%()[]") == true) {
|
|
|
|
char s [2] = "";
|
2024-04-03 11:05:36 -04:00
|
|
|
int kind = 0;
|
2024-04-03 06:10:35 -04:00
|
|
|
s [0] = buffer [offset];
|
2024-04-03 11:05:36 -04:00
|
|
|
switch (buffer [offset]) {
|
|
|
|
case '+': kind = coin_add; break;
|
|
|
|
case '-': kind = coin_subtract; break;
|
|
|
|
case '*': kind = coin_multiply; break;
|
|
|
|
case '/': kind = coin_divide; break;
|
|
|
|
case '%': kind = coin_modulus; break;
|
|
|
|
case '=': kind = coin_equal; break;
|
|
|
|
case '>': kind = coin_above; break;
|
|
|
|
case '<': kind = coin_below; break;
|
|
|
|
case '(': kind = coin_open; break;
|
|
|
|
case ')': kind = coin_close; break;
|
|
|
|
case ',': kind = coin_next; break;
|
|
|
|
case ';': kind = coin_stop; break;
|
|
|
|
case ':': kind = coin_branch; break;
|
|
|
|
case '&': kind = coin_and; break;
|
|
|
|
case '|': kind = coin_or; break;
|
|
|
|
case '!': kind = coin_not; break;
|
|
|
|
case '.': kind = coin_range; break;
|
|
|
|
case '[': kind = coin_enrange; break;
|
|
|
|
case ']': kind = coin_derange; break;
|
|
|
|
case '#': kind = coin_machine; break;
|
|
|
|
}
|
|
|
|
add_coin (kind, (int) buffer [offset], s);
|
2024-03-31 22:58:48 -04:00
|
|
|
} else {
|
|
|
|
if (character_is_blank (buffer [offset]) == false) {
|
2024-04-01 07:23:49 -04:00
|
|
|
echo ("\033[1;31mCharacter set exception point: Segmentation\033[0m\n");
|
2024-03-31 22:58:48 -04:00
|
|
|
printf ("%c -- %i\n", buffer [offset], (int) buffer [offset]);
|
|
|
|
exit (log_failure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-03 06:10:35 -04:00
|
|
|
for (length = 0; length < coin_code; ++length) {
|
|
|
|
switch (coin_enum [length]) {
|
2024-04-03 07:39:59 -04:00
|
|
|
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_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;
|
2024-04-03 06:10:35 -04:00
|
|
|
case coin_type:
|
|
|
|
case coin_if:
|
|
|
|
case coin_else:
|
|
|
|
case coin_case:
|
|
|
|
case coin_loop:
|
|
|
|
case coin_import:
|
|
|
|
case coin_system:
|
2024-04-03 12:29:54 -04:00
|
|
|
case coin_return: printf ("\033[1;33m%s\033[0m ", coin_text [length]); break;
|
2024-04-03 06:10:35 -04:00
|
|
|
default: printf ("\033[1;31m%s\033[0m ", coin_text [length]); break;
|
2024-03-31 22:58:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("\n");
|
2024-04-03 07:39:59 -04:00
|
|
|
|
2024-04-03 11:05:36 -04:00
|
|
|
for (length = 0; length < coin_code; ++length) {
|
|
|
|
if ((coin_enum [length] == coin_return) && (coin_enum [length + 1] == coin_stop)) {
|
|
|
|
printf ("; return;\nxor rax, rax\nret\n\n");
|
2024-04-03 12:29:54 -04:00
|
|
|
} else if ((coin_enum [length] == coin_return) && (coin_enum [length + 1] == coin_number) && (coin_enum [length + 2] == coin_stop)) {
|
|
|
|
printf ("; return {number};\nmov rax, %s\nret\n\n", coin_text [length + 1]);
|
2024-04-03 11:05:36 -04:00
|
|
|
}
|
2024-04-03 07:39:59 -04:00
|
|
|
}
|
2024-04-03 12:29:54 -04:00
|
|
|
|
2024-03-31 22:58:48 -04:00
|
|
|
buffer = deallocate (buffer);
|
|
|
|
|
|
|
|
return (log_success);
|
|
|
|
}
|