From fec2f4d9d1989feb0290dfcff416385ec4b97586 Mon Sep 17 00:00:00 2001 From: thing1 Date: Thu, 11 Jul 2024 13:33:42 +0100 Subject: finished vars, started work on the final zpy executable, still need to fix the parser though --- comp/lucas-standen-NEA/code/tokenizer/parser.c | 27 +++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'comp/lucas-standen-NEA/code/tokenizer/parser.c') diff --git a/comp/lucas-standen-NEA/code/tokenizer/parser.c b/comp/lucas-standen-NEA/code/tokenizer/parser.c index 7d827f9..d4fec18 100644 --- a/comp/lucas-standen-NEA/code/tokenizer/parser.c +++ b/comp/lucas-standen-NEA/code/tokenizer/parser.c @@ -1,12 +1,10 @@ #include #include +#include #include "../global/types.h" #include "../global/util.h" -char *readFile(char *fileName); // reads the file into a single var -char *parser(char *fileName); // general parser function - char *readFile(char *filename){ FILE *f = fopen(filename, "r"); if (f == NULL) @@ -58,6 +56,28 @@ FILE *preProcess(char *contents){ return tmp; } +char **getExpressions(char *file){ + int depth = 0; + char *str = CheckedMalloc(strlen(file)+1); + int pos = 0; + for (int i = 0; i < strlen(file); i++){ + str[pos] = str[i]; + pos++; + if (file[i] == '(') + depth++; + if (file[i] == ')') + depth--; + + if (depth == 0) { + str[pos] = '\0'; + printf("%s\n", str); + pos = 0; + } + } + + return NULL; +} + char *parser(char *fileName){ FILE *tmp = preProcess(readFile(fileName)); fseek(tmp, 0, SEEK_END); @@ -66,5 +86,6 @@ char *parser(char *fileName){ char *buf = CheckedMalloc(len); fgets(buf, len, tmp); fclose(tmp); + getExpressions(buf); return buf; } -- cgit v1.2.3