xiranda/xiranda.c

116 lines
4.4 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) {
terminal_colour (colour_red, effect_bold);
echo (text);
terminal_cancel ();
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...\n");
}
}
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...\n");
} else kill ("Expected number...\n");
} else kill ("Expected equal symbol...\n");
} else kill ("Expected marker...\n");
}
}
/**/for (i = 0; i < type_code; ++i) printf ("-type- %s : %i\n", type_name [i], type_size [i]);
buffer = deallocate (buffer);
return (log_success);
}