#define ULAS_PATHMAX 4096
#define ULAS_LINEMAX 4096
+#define ULAS_MACROPARAMMAX 9
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
// any token before 256 is just the literal char value
// primitive data types
-enum ulas_type {
-
- ULAS_SYMBOL = 256,
- ULAS_INT,
- ULAS_STR
-};
+enum ulas_type { ULAS_SYMBOL = 256, ULAS_INT, ULAS_STR };
// data type value
union ulas_val {
int undef;
};
-#define ULAS_MACROPARAMMAX 9
-
struct ulas_preproc {
struct ulas_ppdef *defs;
unsigned long defslen;
char *ulas_strndup(const char *src, unsigned long n);
+// 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);
+
// tokenisze according to pre-defined rules
// returns the amount of bytes of line that were
// consumed or -1 on error
int rc = 0; \
struct ulas_tok tok = ulas_totok((token), strlen(token), &rc); \
assert((expected_rc) == rc); \
- assert(tok.type == ULAS_INT); \
- assert(tok.val.intv == (expected_val)); \
+ assert(tok.type == ULAS_INT); \
+ assert(tok.val.intv == (expected_val)); \
}
#define ASSERT_STR_TOTOK(expected_val, expected_rc, token) \
int rc = 0; \
struct ulas_tok tok = ulas_totok((token), strlen(token), &rc); \
assert((expected_rc) == rc); \
- assert(tok.type == ULAS_STR); \
- assert(strcmp((expected_val), tok.val.strv) == 0); \
- free(tok.val.strv); \
+ assert(tok.type == ULAS_STR); \
+ assert(strcmp((expected_val), tok.val.strv) == 0); \
+ free(tok.val.strv); \
}
#define ASSERT_SYMBOL_TOTOK(expected_val, expected_rc, token) \
int rc = 0; \
struct ulas_tok tok = ulas_totok((token), strlen(token), &rc); \
assert((expected_rc) == rc); \
- assert(tok.type == ULAS_SYMBOL); \
- assert(strcmp((expected_val), tok.val.strv) == 0); \
- free(tok.val.strv); \
+ assert(tok.type == ULAS_SYMBOL); \
+ assert(strcmp((expected_val), tok.val.strv) == 0); \
+ free(tok.val.strv); \
}
#define ASSERT_UNEXPECTED_TOTOK(expected_rc, token) \
return 1;
}
+struct ulas_tok *ulas_symbolresolve(const char *name) {
+ // TODO: implement
+ return NULL;
+}
+
#define WELD_TOKISTERM write
#define WELD_TOKCOND (i < n && write < n && line[i])
void ulas_tokbufclear(struct ulas_tokbuf *tb) {
for (long i = 0; i < tb->len; i++) {
struct ulas_tok *t = &tb->buf[i];
- if (t->type == ULAS_SYMBOL ||
- t->type == ULAS_STR) {
+ if (t->type == ULAS_SYMBOL || t->type == ULAS_STR) {
free(t->val.strv);
}
}