I am going insane
This commit is contained in:
parent
9e80de017f
commit
07f9a6abd8
@ -63,12 +63,52 @@ bool compile_isop(char* string) {
|
||||
|
||||
}
|
||||
|
||||
char* compile_bracket_wrap(char* string) {
|
||||
char* new = malloc(sizeof(char));
|
||||
new[0] = '\0';
|
||||
string_append(&new,"(");
|
||||
string_append(&new,string);
|
||||
string_append(&new,")");
|
||||
free(string);
|
||||
return new;
|
||||
}
|
||||
|
||||
char* compile_expression(tSyntaxElement* syntaxelement);
|
||||
|
||||
char* compile_expression_wrapped(tSyntaxElement* syntaxelement) {
|
||||
return compile_bracket_wrap(compile_expression(syntaxelement));
|
||||
}
|
||||
|
||||
void compile_genexec(char** result, tSyntaxElement* se){
|
||||
|
||||
tSyntaxElement* token = se;
|
||||
|
||||
string_append(result,"(");
|
||||
|
||||
token = token->next;
|
||||
|
||||
while (1) {
|
||||
|
||||
if (token != NULL) {
|
||||
|
||||
string_append(result,token->content.string);
|
||||
|
||||
if (token->next != NULL)
|
||||
string_append(result,",");
|
||||
|
||||
token = token->next;
|
||||
|
||||
} else break;
|
||||
|
||||
}
|
||||
|
||||
string_append(result,")");
|
||||
}
|
||||
|
||||
char* compile_expression(tSyntaxElement* syntaxelement) {
|
||||
|
||||
char* result = calloc(1,sizeof(char));
|
||||
|
||||
string_append(&result, "(");
|
||||
|
||||
switch (syntaxelement->type) {
|
||||
|
||||
case TOKEN:
|
||||
@ -88,7 +128,9 @@ char* compile_expression(tSyntaxElement* syntaxelement) {
|
||||
|
||||
if (se_istraversable(syntaxelement)) {
|
||||
|
||||
if (syntaxelement->content.syntax->type == TOKEN) {
|
||||
switch (syntaxelement->content.syntax->type) {
|
||||
|
||||
case TOKEN: {
|
||||
|
||||
tSyntaxElement* token = syntaxelement->content.syntax;
|
||||
|
||||
@ -100,7 +142,10 @@ char* compile_expression(tSyntaxElement* syntaxelement) {
|
||||
|
||||
if (token->next != NULL) {
|
||||
|
||||
if (token->next->type == TOKEN)
|
||||
string_append(&result,token->next->content.string);
|
||||
else
|
||||
string_append(&result,compile_expression_wrapped(token->next));
|
||||
|
||||
if (token->next->next != NULL)
|
||||
string_append(&result,operator);
|
||||
@ -111,8 +156,26 @@ char* compile_expression(tSyntaxElement* syntaxelement) {
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
string_append(&result,token->content.string);
|
||||
compile_genexec(&result, token);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TREE: {
|
||||
tSyntaxElement* token = syntaxelement->content.syntax;
|
||||
string_append(&result, compile_expression(syntaxelement->content.syntax));
|
||||
compile_genexec(&result, token);
|
||||
break;
|
||||
}
|
||||
|
||||
case STRING:
|
||||
case NONE:
|
||||
case NEWTREE:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
@ -126,7 +189,6 @@ char* compile_expression(tSyntaxElement* syntaxelement) {
|
||||
|
||||
}
|
||||
|
||||
string_append(&result, ")");
|
||||
return result;
|
||||
|
||||
}
|
||||
@ -153,7 +215,31 @@ char* compile(tSyntaxElement* syntaxtree) {
|
||||
string_append(&result, "set ");
|
||||
string_append(&result,token->next->content.string);
|
||||
string_append(&result,"=");
|
||||
string_append(&result,compile_expression(token->next->next));
|
||||
string_append(&result,compile_expression_wrapped(token->next->next));
|
||||
|
||||
compile_exit_tag(&result);
|
||||
|
||||
} else
|
||||
|
||||
if (strcmp(token->content.string, "global") == 0) {
|
||||
|
||||
compile_enter_tag(&result);
|
||||
|
||||
string_append(&result, "global ");
|
||||
string_append(&result,token->next->content.string);
|
||||
string_append(&result,"=");
|
||||
string_append(&result,compile_expression_wrapped(token->next->next));
|
||||
|
||||
compile_exit_tag(&result);
|
||||
|
||||
} else
|
||||
|
||||
if (strcmp(token->content.string, "do") == 0) {
|
||||
|
||||
compile_enter_tag(&result);
|
||||
|
||||
string_append(&result, "do ");
|
||||
string_append(&result,compile_expression(token->next));
|
||||
|
||||
compile_exit_tag(&result);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user