Work in progress x2...

This commit is contained in:
Ognjen Milan Robovic 2024-04-03 06:10:35 -04:00
parent 832b4e9cb3
commit 8ff08ce5cf
2 changed files with 99 additions and 119 deletions

View File

@ -1,15 +1,9 @@
--- Heyo type integer = 4;
type natural = 4;
type boolean (false, true) type boolean (
false,
type character = -128 .. 127; true)
type integer = -2000000000 .. 2000000000;
type natural % 2000000000;
type structure (
a: integer = 0;
b: boolean = false;
c: natural = 0)
type system_call ( type system_call (
linux_read_system_call = 0, linux_read_system_call = 0,
@ -19,36 +13,37 @@ type system_call (
linux_exit_system_call = 60) linux_exit_system_call = 60)
type file_descriptor ( type file_descriptor (
standard_input = 0, standard_input,
standard_output = 1) standard_output)
main () > integer: string_length (string):
x: integer = 1;
s: structure = (-1, true, 1);
loop (x++ < 101):
if ((x % 3 = 0) && (x % 5 = 0))
echo ("fizzbuzz");
else if (x % 3 = 0):
echo ("fizz\n");
echo ("and again fizz");;
else if (x % 5 = 0)
echo ("buzz\n");
else:
echo ("fuck formatting...");
echo ("fuck formatting twice...");;
echo ("\n");;
return (0);;
heyo () echo ("Heyo!");
cyaa () echo ("Heyo!");
name () > characer [] return ("Ognjen");
string_length (character string []) > natural:
length: natural = 0; length: natural = 0;
loop (! string [length]) loop (! string [length])
length++; length++;
return (length);; return (length);;
echo (character text []): echo (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;;
heyo () echo ("Heyo!");
cyaa () echo ("Cyaa!");
global: integer = 666;
uberglobal = 666;
my_main ():
heyo ();
loop (x = 1 .. 17):
if ((x % 3 = 0) & (x % 5 = 0))
echo ("fizz+buzz");
else if (x % 3 = 0)
echo ("fizz");
else if (x % 5 = 0)
echo ("buzz");
else
echo ("<>");
echo ("\n");;
cyaa ();
return 60;;

147
xiranda.c
View File

@ -9,15 +9,16 @@ enum {
coin_range, coin_enrange, coin_derange, coin_machine coin_range, coin_enrange, coin_derange, coin_machine
}; };
static int coin_code = 0; static int coin_code = 0;/*
static int type_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_enum [240] = { 0 };
static int coin_data [240] = { 0 }; static int coin_data [240] = { 0 };
static char coin_text [240] [40] = { "" };
/*
static char type_name [27] [40] = { "" }; static char type_name [27] [40] = { "" };
static int type_size [27] = { 0 }; static int type_size [27] = { 0 };
@ -33,19 +34,22 @@ static int variable_data [27] = { 0 };
static char constant_name [30] [40] = { "" }; static char constant_name [30] [40] = { "" };
static int constant_type [30] = { 0 }; static int constant_type [30] = { 0 };
static int constant_data [30] = { 0 }; static int constant_data [30] = { 0 };
*/
#include <stdio.h> #include <stdio.h>
#define STRING_LIMIT (40)
static char * word_list [] = { static char * word_list [] = {
"type", "loop", "if", "else", "case", "return", "import", "system" "type", "loop", "if", "else", "case", "return", "import", "system"
}; };
static void add_coin (int type, int data) { static void add_coin (int type, int data, char * text) {
coin_type [coin_code] = type; coin_enum [coin_code] = type;
coin_data [coin_code] = data; coin_data [coin_code] = data;
string_copy (coin_text [coin_code], text);
++coin_code; ++coin_code;
} }
/*
static void add_type (char * name, int size) { static void add_type (char * name, int size) {
string_copy (type_name [type_code], name); string_copy (type_name [type_code], name);
type_size [type_code] = size; type_size [type_code] = size;
@ -57,69 +61,59 @@ static void add_function (char * name, int type, char * * agrument_name, int * a
type_size [type_code] = size; type_size [type_code] = size;
++type_code; ++type_code;
} }
*/
static void kill (char * data) {
echo (data);
exit (log_failure);
}
int main (void) { int main (void) {
char * buffer = null; char * buffer = null;
int offset = 0; int offset = 0;
int length = 0; int length = 0;
buffer = file_import ("./test.x"); buffer = file_import ("./test_x.x");
for (offset = 0; buffer [offset] != '\0'; ++offset) { for (offset = 0; buffer [offset] != '\0'; ++offset) {
if (buffer [offset] == '"') {
int size = 0; int size = 0;
char data [STRING_LIMIT] = ""; char data [STRING_LIMIT] = "";
if (buffer [offset] == '"') {
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_coin (core_string, string_code); add_coin (coin_string, 0, data);
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'; data [0] = buffer [offset];
for (++offset; (character_is_digit (buffer [offset]) == true) && (buffer [offset] != '\0'); ++offset) { for (++offset; (character_is_digit (buffer [offset]) == true) && (buffer [offset] != '\0'); ++offset) {
data *= 10; data [size++] = buffer [offset];
data += (buffer [offset] - '0');
} }
add_coin (core_number, number_code); add_coin (coin_number, 0, data);
add_number (data); data [size] = '\0';
--offset; --offset;
} else if (character_is_alpha (buffer [offset]) == true) { } else if (character_is_alpha (buffer [offset]) == true) {
int size = 0;
char name [NAME_LIMIT] = "";
for (; ((character_is_alpha (buffer [offset]) == true) || for (; ((character_is_alpha (buffer [offset]) == true) ||
(character_is_digit (buffer [offset]) == true) || (character_is_digit (buffer [offset]) == true) ||
(character_is_underscore (buffer [offset]) == true)) && (buffer [offset] != '\0'); ++offset) { (character_is_underscore (buffer [offset]) == true)) && (buffer [offset] != '\0'); ++offset) {
name [size++] = buffer [offset]; data [size++] = buffer [offset];
} }
name [size] = '\0'; data [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 (data, word_list [length], string_length (word_list [length]) + 1) == true) {
add_coin (core_word, length); add_coin (length, 0, data);
goto here; goto here;
} }
} }
add_coin (core_marker, marker_code); add_coin (coin_marker, 0, data);
add_marker (name, token_type [token_count - 1]); /*if ((coin_enum [coin_count - 2] == coin_word) && (coin_data [coin_count - 2] == word_type)) {
if ((token_type [token_count - 2] == core_word) && (token_data [token_count - 2] == word_type)) { coin_enum [coin_count - 1] = coin_type;
token_type [token_count - 1] = core_type;
add_type (name);
} }
for (length = 0; length < type_code; ++length) { for (length = 0; length < type_code; ++length) {
if (string_compare_limit (name, type_name [length], string_length (type_name [length]) + 1) == true) { if (string_compare_limit (data, type_name [length], string_length (type_name [length]) + 1) == true) {
token_type [token_count - 1] = core_type; coin_enum [coin_count - 1] = coin_type;
}
} }
}*/
here: here:
--offset; --offset;
} else if (character_compare_array (buffer [offset], ",.;:=<>&|!+-*/%()[]") == true) { } else if (character_compare_array (buffer [offset], ",.;:=<>#&|!+*-/%()[]") == true) {
add_coin (core_symbol, symbol_code); char s [2] = "";
add_symbol (buffer [offset]); s [0] = buffer [offset];
add_coin (coin_none, 0, s);
} else { } else {
if (character_is_blank (buffer [offset]) == false) { if (character_is_blank (buffer [offset]) == false) {
echo ("\033[1;31mCharacter set exception point: Segmentation\033[0m\n"); echo ("\033[1;31mCharacter set exception point: Segmentation\033[0m\n");
@ -129,61 +123,66 @@ int main (void) {
} }
} }
end: for (length = 0; length < coin_code; ++length) {
switch (coin_enum [length]) {
for (length = 0; length < token_count; ++length) { case coin_string: printf ("\033[1;36m%s\033[0m ", coin_text [length]); break;
switch (token_type [length]) { case coin_number: printf ("\033[1;34m%s\033[0m ", coin_text [length]); break;
case core_symbol: printf ("\033[1;34m%c\033[0m ", symbol_data [token_data [length]]); break; /*case coin_type: printf ("\033[1;36m%s\033[0m ", coin_text [length]); break;*/
case core_string: printf ("\033[1;31m%s\033[0m ", string_data [token_data [length]]); break; case coin_marker: printf ("\033[1;37m%s\033[0m ", coin_text [length]); break;
case core_number: printf ("\033[1;32m%i\033[0m ", number_data [token_data [length]]); break; case coin_type:
case core_type: printf ("\033[1;36m%s\033[0m ", marker_name [token_data [length]]); break; case coin_if:
case core_marker: printf ("\033[1;33m%s\033[0m ", marker_name [token_data [length]]); break; case coin_else:
case core_word: printf ("\033[1;35m%s\033[0m ", word_list [token_data [length]]); break; case coin_case:
default: break; 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"); printf ("\n");
/*
for (length = 0; length < token_count; ++length) { for (length = 0; length < coin_count; ++length) {
if ((token_type [length] == core_word) && (token_data [length] == word_return)) { if ((coin_enum [length] == coin_word) && (coin_data [length] == word_return)) {
++length; ++length;
if ((token_type [length] == core_symbol) && (symbol_data [token_data [length]] == '(')) { if ((coin_enum [length] == coin_symbol) && (symbol_data [coin_data [length]] == '(')) {
echo ("return (\n"); echo ("return (\n");
++length; ++length;
} else if ((token_type [length] == core_symbol) && (symbol_data [token_data [length]] == ';')) { } else if ((coin_enum [length] == coin_symbol) && (symbol_data [coin_data [length]] == ';')) {
echo ("; return;\nxor rax, rax\nret\n"); echo ("; return;\nxor rax, rax\nret\n");
++length; ++length;
} else if (token_type [length] == core_number && (token_type [length + 1] == core_symbol) && (symbol_data [token_data [length + 1]] == ';')) { } 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 [token_data [length]]); printf ("; return {number};\nmov rax, %i\nret\n", number_data [coin_data [length]]);
++length; ++length;
} else { } else {
kill ("return ?\n"); kill ("return ?\n");
} }
} else if ((token_type [length] == core_word) && (token_data [length] == word_if)) { } else if ((coin_enum [length] == coin_word) && (coin_data [length] == word_if)) {
++length; ++length;
if ((token_type [length] == core_symbol) && (symbol_data [token_data [length]] == '(')) { if ((coin_enum [length] == coin_symbol) && (symbol_data [coin_data [length]] == '(')) {
echo ("if (\n"); echo ("if (\n");
++length; ++length;
} else { } else {
kill ("if ?\n"); kill ("if ?\n");
} }
} else if ((token_type [length] == core_word) && (token_data [length] == word_else)) { } else if ((coin_enum [length] == coin_word) && (coin_data [length] == word_else)) {
++length; ++length;
if ((token_type [length] == core_symbol) && (symbol_data [token_data [length]] == ':')) { if ((coin_enum [length] == coin_symbol) && (symbol_data [coin_data [length]] == ':')) {
echo ("else :\n"); echo ("else :\n");
++length; ++length;
} else if ((token_type [length] == core_word) && (token_data [length] == word_if)) { } else if ((coin_enum [length] == coin_word) && (coin_data [length] == word_if)) {
echo ("else if\n"); echo ("else if\n");
++length; ++length;
} else { } else {
echo ("else expression\n"); echo ("else expression\n");
} }
} else if ((token_type [length] == core_word) && (token_data [length] == word_type)) { } else if ((coin_enum [length] == coin_word) && (coin_data [length] == word_type)) {
++length; ++length;
if (token_type [length] == core_type) { if (coin_enum [length] == coin_type) {
echo ("type <name> -- "); echo ("type <name> -- ");
echo (marker_name [token_data [length]]); echo (marker_name [coin_data [length]]);
echo ("\n"); echo ("\n");
++length; ++length;
} else { } else {
@ -191,21 +190,7 @@ int main (void) {
} }
} }
} }
*/
for (length = 0; length < string_code; ++length) { string_data [length] = deallocate (string_data [length]); }
for (length = 0; length < marker_code; ++length) { marker_name [length] = deallocate (marker_name [length]); }
for (length = 0; length < type_code; ++length) { type_name [length] = deallocate (type_name [length]); }
string_data = deallocate (string_data);
string_size = deallocate (string_size);
marker_name = deallocate (marker_name);
marker_type = deallocate (marker_type);
type_name = deallocate (type_name);
symbol_data = deallocate (symbol_data);
number_data = deallocate (number_data);
token_data = deallocate (token_data);
token_type = deallocate (token_type);
buffer = deallocate (buffer); buffer = deallocate (buffer);
return (log_success); return (log_success);