2024-03-31 22:58:48 -04:00
|
|
|
#include <xolatile/xtandard.c>
|
2024-04-04 16:06:02 -04:00
|
|
|
#include <xolatile/xyntax.c>
|
2024-03-31 22:58:48 -04:00
|
|
|
|
2024-04-05 04:43:29 -04:00
|
|
|
static int coin_code = 0;
|
2024-04-05 02:52:26 -04:00
|
|
|
static int type_code = 0;
|
2024-04-05 04:43:29 -04:00
|
|
|
static int variable_code = 0;/*
|
|
|
|
static int constant_code = 0;
|
|
|
|
static int function_code = 0;*/
|
|
|
|
|
|
|
|
static int coin_data [240] = { 0 };
|
|
|
|
static int coin_size [240] = { 0 };
|
|
|
|
static char coin_text [240] [40] = { "" };
|
|
|
|
|
2024-04-03 05:03:46 -04:00
|
|
|
static char type_name [27] [40] = { "" };
|
|
|
|
static int type_size [27] = { 0 };
|
2024-04-05 02:52:26 -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 };
|
2024-04-05 04:43:29 -04:00
|
|
|
/*
|
2024-04-03 04:31:51 -04:00
|
|
|
static char constant_name [30] [40] = { "" };
|
|
|
|
static int constant_type [30] = { 0 };
|
|
|
|
static int constant_data [30] = { 0 };
|
2024-04-05 04:43:29 -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-04-03 06:10:35 -04:00
|
|
|
*/
|
2024-03-31 22:58:48 -04:00
|
|
|
#include <stdio.h>
|
2024-04-05 04:43:29 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
/*
|
2024-04-03 14:22:03 -04:00
|
|
|
static char * register_list [] = {
|
|
|
|
"rax","rdi","rsi","rdx","r10","r8","r9"
|
|
|
|
};
|
2024-04-05 02:52:26 -04:00
|
|
|
*/
|
2024-04-05 04:43:29 -04:00
|
|
|
static void add_coin (int data, int size, char * text) {
|
2024-04-03 05:03:46 -04:00
|
|
|
coin_data [coin_code] = data;
|
2024-04-05 02:52:26 -04:00
|
|
|
coin_size [coin_code] = size;
|
2024-04-05 04:43:29 -04:00
|
|
|
string_copy_limit (coin_text [coin_code], text, size);
|
2024-04-03 05:03:46 -04:00
|
|
|
++coin_code;
|
|
|
|
}
|
2024-04-05 02:52:26 -04:00
|
|
|
|
2024-04-05 06:27:35 -04:00
|
|
|
static void kill (char * text, int offset) {
|
2024-04-05 04:43:29 -04:00
|
|
|
terminal_colour (colour_red, effect_bold);
|
|
|
|
echo (text);
|
|
|
|
terminal_cancel ();
|
2024-04-05 06:27:35 -04:00
|
|
|
echo (coin_text [offset]);
|
|
|
|
echo ("\n");
|
|
|
|
/*exit (log_failure);*/
|
2024-04-05 04:43:29 -04:00
|
|
|
}
|
|
|
|
|
2024-03-31 22:58:48 -04:00
|
|
|
int main (void) {
|
|
|
|
char * buffer = null;
|
|
|
|
int offset = 0;
|
|
|
|
int length = 0;
|
2024-04-04 16:31:37 -04:00
|
|
|
int select = 0;
|
|
|
|
|
2024-04-05 04:43:29 -04:00
|
|
|
/**/int i;
|
|
|
|
|
2024-04-04 16:31:37 -04:00
|
|
|
int coin_string = syntax_define (false, false, "\"", "\"", '\\', colour_red, effect_normal);
|
|
|
|
int coin_type = syntax_define (false, true, "type", " \t\n", '\0', colour_yellow, effect_normal);
|
2024-04-04 16:45:26 -04:00
|
|
|
int coin_loop = syntax_define (false, true, "loop", " \t\n(:", '\0', colour_yellow, effect_normal);
|
|
|
|
int coin_if = syntax_define (false, true, "if", " \t\n(", '\0', colour_yellow, effect_normal);
|
|
|
|
int coin_else = syntax_define (false, true, "else", " \t\n:", '\0', colour_yellow, effect_normal);
|
|
|
|
int coin_case = syntax_define (false, true, "case", " \t\n(", '\0', colour_yellow, effect_normal);
|
|
|
|
int coin_return = syntax_define (false, true, "return", " \t\n(;", '\0', colour_yellow, effect_normal);
|
2024-04-04 16:31:37 -04:00
|
|
|
int coin_import = syntax_define (false, true, "import", " \t\n", '\0', colour_yellow, effect_normal);
|
2024-04-04 16:45:26 -04:00
|
|
|
int coin_system = syntax_define (false, true, "system", " \t\n(", '\0', colour_yellow, effect_normal);
|
2024-04-04 16:31:37 -04:00
|
|
|
int coin_number = syntax_define (true, true, "0123456789", " \t\n,.;:()[]#", '\0', colour_blue, effect_normal);
|
|
|
|
int coin_marker = syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz_", " \t\n,.;:()[]#", '\0', colour_white, effect_normal);
|
|
|
|
int coin_symbol = syntax_define (true, false, ",.;:=#[]()+-*/%&|!", "", '\0', colour_cyan, effect_normal);
|
2024-04-04 16:06:02 -04:00
|
|
|
|
2024-04-03 12:29:54 -04:00
|
|
|
buffer = record ();
|
2024-03-31 22:58:48 -04:00
|
|
|
|
2024-04-04 16:31:37 -04:00
|
|
|
for (offset = 0; buffer [offset] != '\0'; offset += length) {
|
|
|
|
select = syntax_select (& buffer [offset], & length);
|
2024-04-05 02:52:26 -04:00
|
|
|
if (select < syntax_count) {
|
2024-04-04 16:31:37 -04:00
|
|
|
terminal_colour (syntax_colour [select], syntax_effect [select]);
|
2024-04-05 04:43:29 -04:00
|
|
|
add_coin (select, length, & buffer [offset]);
|
2024-04-05 02:52:26 -04:00
|
|
|
} else {
|
|
|
|
terminal_colour (colour_red, effect_bold);
|
|
|
|
if (character_compare_array (buffer [offset], " \t\n") == false) {
|
2024-04-05 06:27:35 -04:00
|
|
|
kill ("Illegal character: ", offset);
|
2024-04-05 02:52:26 -04:00
|
|
|
}
|
2024-04-04 16:31:37 -04:00
|
|
|
}
|
|
|
|
out (& buffer [offset], length);
|
|
|
|
terminal_cancel ();
|
|
|
|
}
|
2024-04-03 16:02:43 -04:00
|
|
|
|
2024-04-05 04:43:29 -04:00
|
|
|
for (offset = 0; offset < coin_code; ++offset) {
|
|
|
|
if (coin_data [offset] == coin_type) {
|
|
|
|
++offset;
|
|
|
|
if (coin_data [offset] == coin_marker) {
|
|
|
|
string_copy (type_name [type_code], coin_text [offset]);
|
|
|
|
++offset;
|
|
|
|
if ((coin_data [offset] == coin_symbol) && (* coin_text [offset] == '=')) {
|
|
|
|
++offset;
|
|
|
|
if (coin_data [offset] == coin_number) {
|
|
|
|
type_size [type_code] = atoi (coin_text [offset]);
|
|
|
|
++offset;
|
|
|
|
if ((coin_data [offset] == coin_symbol) && (* coin_text [offset] == ';')) {
|
|
|
|
++type_code;
|
2024-04-05 06:27:35 -04:00
|
|
|
} else kill ("Expected semicolon symbol: ", offset);
|
|
|
|
} else kill ("Expected number: ", offset);
|
|
|
|
} else kill ("Expected equal symbol: ", offset);
|
|
|
|
} else kill ("Expected marker: ", offset);
|
|
|
|
} else if (coin_data [offset] == coin_marker) {
|
|
|
|
++offset;
|
|
|
|
if ((coin_data [offset] == coin_symbol) && (* coin_text [offset] == ':')) {
|
|
|
|
string_copy (variable_name [variable_code], coin_text [offset - 1]);
|
|
|
|
++offset;
|
|
|
|
if (coin_data [offset] == coin_marker) {
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < type_code; ++j) {
|
|
|
|
if (string_compare (coin_text [offset], type_name [j]) == true) {
|
|
|
|
variable_type [variable_code] = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j == type_code) {
|
|
|
|
kill ("Unknown type: ", offset);
|
|
|
|
}
|
|
|
|
++offset;
|
|
|
|
if ((coin_data [offset] == coin_symbol) && (* coin_text [offset] == '=')) {
|
|
|
|
++offset;
|
|
|
|
if (coin_data [offset] == coin_number) {
|
|
|
|
variable_data [variable_code] = atoi (coin_text [offset]);
|
|
|
|
++offset;
|
|
|
|
if ((coin_data [offset] == coin_symbol) && (* coin_text [offset] == ';')) {
|
|
|
|
++variable_code;
|
|
|
|
} else kill ("Expected semicolon symbol: ", offset);
|
|
|
|
} else if (coin_data [offset] == coin_string) {
|
|
|
|
variable_data [variable_code] = 33;
|
|
|
|
++offset;
|
|
|
|
if ((coin_data [offset] == coin_symbol) && (* coin_text [offset] == ';')) {
|
|
|
|
++variable_code;
|
|
|
|
} else kill ("Expected semicolon symbol: ", offset);
|
|
|
|
} else if (coin_data [offset] == coin_marker) {
|
|
|
|
variable_data [variable_code] = 66;
|
|
|
|
++offset;
|
|
|
|
if ((coin_data [offset] == coin_symbol) && (* coin_text [offset] == ';')) {
|
|
|
|
++variable_code;
|
|
|
|
} else kill ("Expected semicolon symbol: ", offset);
|
|
|
|
} else kill ("Expected marker, number or string: ", offset);
|
|
|
|
} else kill ("Expected equal symbol: ", offset);
|
|
|
|
} else kill ("Expected type: ", offset);
|
|
|
|
} else kill ("Expected colon symbol: ", offset);
|
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-04-05 06:27:35 -04:00
|
|
|
/**/for (i = 0; i < type_code; ++i) printf ("-type- %s = %i;\n", type_name [i], type_size [i]);
|
|
|
|
/**/for (i = 0; i < variable_code; ++i) printf ("-variable- %s : %s = %i;\n", variable_name [i], type_name [variable_type [i]], variable_data [i]);
|
2024-04-05 04:43:29 -04:00
|
|
|
|
2024-03-31 22:58:48 -04:00
|
|
|
buffer = deallocate (buffer);
|
|
|
|
|
|
|
|
return (log_success);
|
|
|
|
}
|