diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/doer.c | 32 | ||||
-rw-r--r-- | src/include/doer.h | 2 | ||||
-rw-r--r-- | src/lexer.c | 6 |
3 files changed, 28 insertions, 12 deletions
@@ -47,29 +47,39 @@ void doer_destroy(doer_t* doer) { void doer_add_target(doer_t* doer, target_t* target) { // First target being added. if (!doer->targets) doer->targets = doer->ltarget = target; - else doer->ltarget->nxt = target; + else { + doer->ltarget->nxt = target; + doer->ltarget = target; + } } -/* - - :str:var = "Hello" - printl.var +tree_t* doer_find_target_from_call(target_t* targetl, tree_t* call) { + if (!targetl) { DIE("Call to missing value."); } + + char* last_target_name = targetl->tree->data.def.tag->data.tag.nxt->data.tag.val; + char* call_name = call->data.call.target; -*/ + if (!strcmp(last_target_name, call_name)) { + return targetl->tree; + } else { + return doer_find_target_from_call(targetl->nxt, call); + } +} char* doer_eval_str(doer_t* doer) { // Assume tree type is a simple call to variable. // Search through target list for matching variable. // Return its value as a string (assume it's a string). - // Assume there is only 1 target in the target list. switch (doer->tree->type) { case TREE_TYPE_CALL: - // Assume there is only 1 target in the target list. - doer->tree = doer->ltarget->tree->data.def.val; + doer->tree = doer_find_target_from_call(doer->targets, doer->tree); + return doer_eval_str(doer); + case TREE_TYPE_DEF: + doer->tree = doer->tree->data.def.val; return doer_eval_str(doer); case TREE_TYPE_LSTR: - // Already done \o/ + // Already done \o/. return doer->tree->data.lstr.val; default: DIE("Wrong type, FOOL!"); @@ -118,7 +128,7 @@ void doer_do_expr(doer_t* doer) { doer_do_def(doer); break; default: - LOG_WARF("unknown tree type: %d", doer->tree->type); + LOG_WARF("Unknown tree type: %d", doer->tree->type); } } diff --git a/src/include/doer.h b/src/include/doer.h index 00c3c19..314edc3 100644 --- a/src/include/doer.h +++ b/src/include/doer.h @@ -47,7 +47,7 @@ typedef struct BLINF { } blinf_t; void doer_add_target(doer_t* doer, target_t* target); - +tree_t* doer_find_target_from_call(target_t* targetl, tree_t* call); // Given a tree, evaluate it to a string (or type error). char* doer_eval_str(doer_t* doer); diff --git a/src/lexer.c b/src/lexer.c index aa068a9..4ad8fd6 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -7,6 +7,12 @@ #include "include/syntax.h" #include "include/token.h" +/* + + TODO: Fix bug where calls ending with numbers get interpreted as lints. + +*/ + lexer_t* lexer_init(char* src) { lexer_t* lexer; |