xiranda/xiranda.c

159 lines
6.3 KiB
C

#include <xolatile/xtandard.c>
#include <xolatile/xyntax.c>
static int coin_code = 0;
static int type_code = 0;
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] = { "" };
static char type_name [27] [40] = { "" };
static int type_size [27] = { 0 };
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 };
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 } };
*/
#include <stdio.h>
#include <stdlib.h>
/*
static char * register_list [] = {
"rax","rdi","rsi","rdx","r10","r8","r9"
};
*/
static void add_coin (int data, int size, char * text) {
coin_data [coin_code] = data;
coin_size [coin_code] = size;
string_copy_limit (coin_text [coin_code], text, size);
++coin_code;
}
static void kill (char * text, int offset) {
terminal_colour (colour_red, effect_bold);
echo (text);
terminal_cancel ();
echo (coin_text [offset]);
echo ("\n");
/*exit (log_failure);*/
}
int main (void) {
char * buffer = null;
int offset = 0;
int length = 0;
int select = 0;
/**/int i;
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);
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);
int coin_import = syntax_define (false, true, "import", " \t\n", '\0', colour_yellow, effect_normal);
int coin_system = syntax_define (false, true, "system", " \t\n(", '\0', colour_yellow, effect_normal);
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);
buffer = record ();
for (offset = 0; buffer [offset] != '\0'; offset += length) {
select = syntax_select (& buffer [offset], & length);
if (select < syntax_count) {
terminal_colour (syntax_colour [select], syntax_effect [select]);
add_coin (select, length, & buffer [offset]);
} else {
terminal_colour (colour_red, effect_bold);
if (character_compare_array (buffer [offset], " \t\n") == false) {
kill ("Illegal character: ", offset);
}
}
out (& buffer [offset], length);
terminal_cancel ();
}
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;
} 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);
}
}
/**/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]);
buffer = deallocate (buffer);
return (log_success);
}