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

View File

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