47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include "syntax.h"
|
||
|
|
||
|
void compile_enter_tag(char** string) {
|
||
|
int len = strlen(*string);
|
||
|
*string = realloc(*string, len + 3 * sizeof(char));
|
||
|
string[0][len + 0] = '{';
|
||
|
string[0][len + 1] = '%';
|
||
|
string[0][len + 2] = '\0';
|
||
|
}
|
||
|
|
||
|
void compile_exit_tag(char** string) {
|
||
|
int len = strlen(*string);
|
||
|
*string = realloc(*string, len + 3 * sizeof(char));
|
||
|
string[0][len + 0] = '%';
|
||
|
string[0][len + 1] = '}';
|
||
|
string[0][len + 2] = '\0';
|
||
|
}
|
||
|
|
||
|
void string_append(char** string, char* append) {
|
||
|
int len = strlen(*string);
|
||
|
*string = realloc(*string, len + strlen(append) + sizeof(char));
|
||
|
strcpy(*string + len, append);
|
||
|
}
|
||
|
|
||
|
char* compile(tSyntaxElement* syntaxtree) {
|
||
|
char* result = calloc(1,sizeof(char));
|
||
|
if (se_istraversable(syntaxtree)) {
|
||
|
if (syntaxtree->content.syntax->type == TOKEN) {
|
||
|
tSyntaxElement* token = syntaxtree->content.syntax;
|
||
|
if (strcmp(token->content.string, "def") == 0) {
|
||
|
} else
|
||
|
if (strcmp(token->content.string, "set") == 0) {
|
||
|
compile_enter_tag(&result);
|
||
|
string_append(&result, "set ");
|
||
|
string_append(&result,token->next->content.string);
|
||
|
string_append(&result,"=");
|
||
|
string_append(&result,token->next->next->content.string);
|
||
|
compile_exit_tag(&result);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return result;
|
||
|
}
|