summaryrefslogtreecommitdiff
path: root/src/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/parse.c b/src/parse.c
index c7f5e5b..b84a3f6 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -13,9 +13,19 @@ sym_t* init_sym(prov_t province, litType_t litType, void* name) {
symbol->argCount = 0;
return symbol;
}
+sym_t* init_sym_int(int value) {
+ int* vp = malloc(sizeof(int));
+ *vp = value;
+ return init_sym(LITERAL, INT, vp);
+}
+sym_t* init_sym_str(char* value) {
+ return init_sym(LITERAL, STRING, value);
+}
void destroy_sym(sym_t* symbol) {
free(symbol->name);
- free(symbol->args);
+ if (symbol->argCount > 0) {
+ free(symbol->args);
+ }
free(symbol);
}
int symtoi(sym_t* symbol) {
@@ -73,17 +83,16 @@ symset_t* parse_symbols(char** str) {
sym_t* symbol;
/* TODO: float */
/* string */
+ /* TODO: more frees in here */
if (isalpha(symbolName[0])) {
- //symbolName = realloc(symbolName, i * sizeof(char));
- symbol = init_sym(LITERAL, STRING, symbolName);
+ //TODO: realloc this
+ symbol = init_sym_str(symbolName);
}
/* int */
else {
int v = atoi(symbolName);
- int* vp = malloc(sizeof(int));
- *vp = v;
+ symbol = init_sym_int(v);
free(symbolName);
- symbol = init_sym(LITERAL, INT, vp);
}
symset_add_symbol(symbolSet, symbol);
break;