From b6cf209e65721c9b749124e6c5866b9359fc6583 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 9 Jul 2024 15:40:55 +0100 Subject: made alot work with vars --- comp/lucas-standen-NEA/code/global/types.h | 6 ++++++ comp/lucas-standen-NEA/code/global/util.c | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'comp/lucas-standen-NEA/code/global') diff --git a/comp/lucas-standen-NEA/code/global/types.h b/comp/lucas-standen-NEA/code/global/types.h index 67c4a58..885c780 100644 --- a/comp/lucas-standen-NEA/code/global/types.h +++ b/comp/lucas-standen-NEA/code/global/types.h @@ -60,6 +60,12 @@ typedef union literal { Vdef *vdef; } literal; +typedef struct var { + literal *value; + types type; + char *id; +} var; + // built in functions typedef enum builtInFuncs { // general diff --git a/comp/lucas-standen-NEA/code/global/util.c b/comp/lucas-standen-NEA/code/global/util.c index a29bbbc..5f41dbc 100644 --- a/comp/lucas-standen-NEA/code/global/util.c +++ b/comp/lucas-standen-NEA/code/global/util.c @@ -17,8 +17,8 @@ literal *giveType(char *tok); void Die(){ - perror("zpy parser"); - exit(errno); + fprintf(stderr, "error occured, bringing down the program\n"); + exit(1); } void *CheckedMalloc(long size){ @@ -103,7 +103,10 @@ Vdef *isVdef(char *str){ if (strchr(str, ':') != NULL){ Vdef *out = CheckedMalloc(sizeof(Vdef)); char *type; - type = strtok(str, ":"); + + out->id = strtok(str, ":"); + + type = strtok(NULL, ":"); if (strcmp(type, "i64") == 0) out->type = TI64; else if (strcmp(type, "i32") == 0) out->type = TI32; else if (strcmp(type, "u64") == 0) out->type = TU64; @@ -117,7 +120,6 @@ Vdef *isVdef(char *str){ Die(); } - out->id = strtok(NULL, ":"); return out; } return NULL; @@ -143,7 +145,6 @@ literal *giveType(char *tok){ out->vdef = vdef; } else { fprintf(stderr, "data %s could not be typed\n", tok); - errno = 22; Die(); } return out; -- cgit v1.2.3