// resolve a symbol until an actual literal token (str, int) is found
// returns NULL if the symbol cannot be resolved
-struct ulas_tok *ulas_symbolresolve(const char *name);
+// and sets rc to -1 if eunresolve is 1
+// if eunresolve is 0 rc will be set to 1 if the symbol is not resolved
+struct ulas_tok *ulas_symbolresolve(const char *name, int eunresolve, int *rc);
// tokenisze according to pre-defined rules
// returns the amount of bytes of line that were
*/
// convert literal to its int value
-int ulas_valint(struct ulas_tok *lit, int *rc);
+// retunrs -1 on error, 0 on success and 1 if there is an unresolved symbol
+int ulas_valint(struct ulas_tok *lit, int eunresolve, int *rc);
// convert literal to its char value
-char *ulas_valstr(struct ulas_tok *lit, int *rc);
+char *ulas_valstr(struct ulas_tok *lit, int eunresolve, int *rc);
struct ulas_tokbuf ulas_tokbuf(void);
return 1;
}
-struct ulas_tok *ulas_symbolresolve(const char *name) {
+struct ulas_tok *ulas_symbolresolve(const char *name, int eunresolve, int *rc) {
// TODO: implement
return NULL;
}
* Literals, tokens and expressions
*/
-int ulas_valint(struct ulas_tok *lit, int *rc) {
+int ulas_valint(struct ulas_tok *lit, int eunresolve, int *rc) {
+ if (lit->type == ULAS_SYMBOL) {
+ struct ulas_tok *stok = ulas_symbolresolve(lit->val.strv, eunresolve, rc);
+ return ulas_valint(stok, eunresolve, rc);
+ }
+
if (!lit || lit->type != ULAS_INT) {
ULASERR("Expected int\n");
*rc = -1;
return lit->val.intv;
}
-char *ulas_valstr(struct ulas_tok *lit, int *rc) {
+char *ulas_valstr(struct ulas_tok *lit, int eunresolve, int *rc) {
if (!lit || lit->type != ULAS_STR) {
ULASERR("Expected str\n");
*rc = -1;
}
case ULAS_EXPPRIM: {
struct ulas_tok *t = ulas_tokbufget(&ulas.toks, e->val.prim.tok);
- return ulas_valint(t, rc);
+ return ulas_valint(t, 0, rc);
}
}