Work in progress...

This commit is contained in:
Ognjen Milan Robovic 2024-04-03 05:03:46 -04:00
parent f2cfd30291
commit 832b4e9cb3
2 changed files with 38 additions and 26 deletions

5
test.x
View File

@ -1,5 +1,3 @@
--- Heyo
type boolean (false, true) type boolean (false, true)
type character = -128 .. 127; type character = -128 .. 127;
@ -35,12 +33,9 @@ echo (character text []):
system (linux_write_system_call, standard_output, text, string_length (text)); system (linux_write_system_call, standard_output, text, string_length (text));
return;; return;;
--- entry point
my_main () > integer: my_main () > integer:
x: integer = 1; x: integer = 1;
s: structure = (-1, true, 1); s: structure = (-1, true, 1);
---
heyo (); heyo ();
loop (x++ < 17): loop (x++ < 17):
if ((x % 3 = 0) && (x % 5 = 0)) if ((x % 3 = 0) && (x % 5 = 0))

View File

@ -1,17 +1,26 @@
#include <xolatile/xtandard.c> #include <xolatile/xtandard.c>
enum { enum {
word_type, word_loop, word_if, word_else, word_case, word_return, word_import, word_system, coin_none,
function, variable, constant, type, string, number, marker, label, coin_type, coin_loop, coin_if, coin_else, coin_case, coin_return, coin_import, coin_system,
add, subtract, multiply, divide, modulus, equal, above, below, coin_function, coin_variable, coin_constant, coin_data_type, coin_string, coin_number, coin_marker, coin_label,
open, close, next, stop, branch, and, or, not, coin_add, coin_subtract, coin_multiply, coin_divide, coin_modulus, coin_equal, coin_above, coin_below,
range, enrange, derange, comment 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 function_code = 0;
static int variable_code = 0; static int variable_code = 0;
static int constant_code = 0; static int constant_code = 0;
static int coin_type [240] = { 0 };
static int coin_data [240] = { 0 };
static char type_name [27] [40] = { "" };
static int type_size [27] = { 0 };
static char function_name [9] [40] = { "" }; static char function_name [9] [40] = { "" };
static int function_type [9] = { 0 }; static int function_type [9] = { 0 };
static char function_argument_name [9] [6] [40] = { { "" } }; static char function_argument_name [9] [6] [40] = { { "" } };
@ -31,18 +40,26 @@ static char * word_list [] = {
"type", "loop", "if", "else", "case", "return", "import", "system" "type", "loop", "if", "else", "case", "return", "import", "system"
}; };
static void add_token (int type, int data) { static void add_coin (int type, int data) {
token_data = reallocate (token_data, (token_count + 1) * (int) sizeof (* token_data)); coin_type [coin_code] = type;
token_type = reallocate (token_type, (token_count + 1) * (int) sizeof (* token_type)); coin_data [coin_code] = data;
token_data [token_count] = data; ++coin_code;
token_type [token_count] = type; }
++token_count;
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;
} }
static void kill (char * data) { static void kill (char * data) {
terminal_colour (colour_red, effect_bold);
echo (data); echo (data);
terminal_cancel ();
exit (log_failure); exit (log_failure);
} }
@ -54,16 +71,14 @@ int main (void) {
buffer = file_import ("./test.x"); buffer = file_import ("./test.x");
for (offset = 0; buffer [offset] != '\0'; ++offset) { for (offset = 0; buffer [offset] != '\0'; ++offset) {
if ((buffer [offset] == '-') && (buffer [offset + 1] == '-') && (buffer [offset + 2] == '-') && (buffer [offset + 1] != '\0') && (buffer [offset + 2] != '\0')) { if (buffer [offset] == '"') {
for (; buffer [offset] != '\n'; ++offset);
} else if (buffer [offset] == '"') {
int size = 0; int size = 0;
char data [STRING_LIMIT] = ""; char data [STRING_LIMIT] = "";
for (++offset; (buffer [offset] != '"') && (buffer [offset] != '\0'); ++offset) { for (++offset; (buffer [offset] != '"') && (buffer [offset] != '\0'); ++offset) {
data [size++] = buffer [offset]; data [size++] = buffer [offset];
} }
data [size] = '\0'; data [size] = '\0';
add_token (core_string, string_code); add_coin (core_string, string_code);
add_string (data, size); add_string (data, size);
} else if (character_is_digit (buffer [offset]) == true) { } else if (character_is_digit (buffer [offset]) == true) {
int data = buffer [offset] - '0'; int data = buffer [offset] - '0';
@ -71,7 +86,7 @@ int main (void) {
data *= 10; data *= 10;
data += (buffer [offset] - '0'); data += (buffer [offset] - '0');
} }
add_token (core_number, number_code); add_coin (core_number, number_code);
add_number (data); add_number (data);
--offset; --offset;
} else if (character_is_alpha (buffer [offset]) == true) { } else if (character_is_alpha (buffer [offset]) == true) {
@ -85,11 +100,11 @@ int main (void) {
name [size] = '\0'; name [size] = '\0';
for (length = 0; length < (int) (sizeof (word_list) / sizeof (word_list [0])); ++length) { for (length = 0; length < (int) (sizeof (word_list) / sizeof (word_list [0])); ++length) {
if (string_compare_limit (name, word_list [length], string_length (word_list [length]) + 1) == true) { if (string_compare_limit (name, word_list [length], string_length (word_list [length]) + 1) == true) {
add_token (core_word, length); add_coin (core_word, length);
goto here; goto here;
} }
} }
add_token (core_marker, marker_code); add_coin (core_marker, marker_code);
add_marker (name, token_type [token_count - 1]); add_marker (name, token_type [token_count - 1]);
if ((token_type [token_count - 2] == core_word) && (token_data [token_count - 2] == word_type)) { if ((token_type [token_count - 2] == core_word) && (token_data [token_count - 2] == word_type)) {
token_type [token_count - 1] = core_type; token_type [token_count - 1] = core_type;
@ -103,7 +118,7 @@ int main (void) {
here: here:
--offset; --offset;
} else if (character_compare_array (buffer [offset], ",.;:=<>&|!+-*/%()[]") == true) { } else if (character_compare_array (buffer [offset], ",.;:=<>&|!+-*/%()[]") == true) {
add_token (core_symbol, symbol_code); add_coin (core_symbol, symbol_code);
add_symbol (buffer [offset]); add_symbol (buffer [offset]);
} else { } else {
if (character_is_blank (buffer [offset]) == false) { if (character_is_blank (buffer [offset]) == false) {
@ -114,6 +129,8 @@ int main (void) {
} }
} }
end:
for (length = 0; length < token_count; ++length) { for (length = 0; length < token_count; ++length) {
switch (token_type [length]) { switch (token_type [length]) {
case core_symbol: printf ("\033[1;34m%c\033[0m ", symbol_data [token_data [length]]); break; case core_symbol: printf ("\033[1;34m%c\033[0m ", symbol_data [token_data [length]]); break;