commit 4db750bbf03c9d7c18291fc63b7cf23cf966d6c8 parent 3dad2f4c5ce7fd44015cbd921318b3512c36326e Author: thing1 <thing1@seacrossedlovers.xyz> Date: Mon, 8 Jul 2024 11:36:32 +0100 i forgot to commit last time i think Diffstat:
18 files changed, 48 insertions(+), 21 deletions(-)
diff --git a/comp/lucas-standen-NEA/code/TODO b/comp/lucas-standen-NEA/code/TODO @@ -1,3 +1 @@ -finish the pre processor, it should read through a given input and convert all string litterals to arrays - -make it possible to index arrays +add variables diff --git a/comp/lucas-standen-NEA/code/proto/Makefile b/comp/lucas-standen-NEA/code/proto/AST/Makefile diff --git a/comp/lucas-standen-NEA/code/proto/AST/ast b/comp/lucas-standen-NEA/code/proto/AST/ast Binary files differ. diff --git a/comp/lucas-standen-NEA/code/proto/ast.c b/comp/lucas-standen-NEA/code/proto/AST/ast.c diff --git a/comp/lucas-standen-NEA/code/proto/astg.c b/comp/lucas-standen-NEA/code/proto/AST/astg.c diff --git a/comp/lucas-standen-NEA/code/proto/astg.h b/comp/lucas-standen-NEA/code/proto/AST/astg.h diff --git a/comp/lucas-standen-NEA/code/proto/left b/comp/lucas-standen-NEA/code/proto/AST/left diff --git a/comp/lucas-standen-NEA/code/proto/right b/comp/lucas-standen-NEA/code/proto/AST/right diff --git a/comp/lucas-standen-NEA/code/proto/Makefile b/comp/lucas-standen-NEA/code/proto/Makefile @@ -1,4 +1,3 @@ -all: astg ast.c - cc -ggdb ast.c astg.o -o ast -astg: astg.c - cc -ggdb astg.c -c -o astg.o +all: + cd AST; make + cd parser; make diff --git a/comp/lucas-standen-NEA/code/proto/ast b/comp/lucas-standen-NEA/code/proto/ast Binary files differ. diff --git a/comp/lucas-standen-NEA/code/proto/parser/Makefile b/comp/lucas-standen-NEA/code/proto/parser/Makefile @@ -0,0 +1,2 @@ +all: + cc test.c ../../global/util.o ../../tokenizer/parser.o -o test diff --git a/comp/lucas-standen-NEA/code/proto/parser/sample.zpy b/comp/lucas-standen-NEA/code/proto/parser/sample.zpy @@ -0,0 +1 @@ +(write "hello!") diff --git a/comp/lucas-standen-NEA/code/proto/parser/test b/comp/lucas-standen-NEA/code/proto/parser/test Binary files differ. diff --git a/comp/lucas-standen-NEA/code/proto/parser/test.c b/comp/lucas-standen-NEA/code/proto/parser/test.c @@ -0,0 +1,7 @@ +#include <stdio.h> +#include "../../tokenizer/parser.h" + +int main(){ + char *buf = parser("sample.zpy"); + printf("%s", buf); +} diff --git a/comp/lucas-standen-NEA/code/tokenizer/parser.c b/comp/lucas-standen-NEA/code/tokenizer/parser.c @@ -5,7 +5,7 @@ #include "../global/util.h" char *readFile(char *fileName); // reads the file into a single var -char *parse(char *fileName); // general parser function +char *parser(char *fileName); // general parser function char *readFile(char *filename){ FILE *f = fopen(filename, "r"); @@ -32,13 +32,39 @@ char *readFile(char *filename){ return out; } -char *preProcess(char *contents){ - char *out = CheckedMalloc(strlen(contents)+1); +FILE *preProcess(char *contents){ + int currentSize = strlen(contents)+1; + char *out = CheckedMalloc(currentSize); + + FILE *tmp = fopen("/tmp/zpy.tmp", "w+"); + for (char c = contents[0]; c != '\0'; c = (contents += 1)[0]){ - printf("%c", c); + if (c == '"'){ + fprintf(tmp, "["); + c = (contents += 1)[0]; + do { + fprintf(tmp, "'%c'", c); + if ((contents+1)[0] != '"') { + fprintf(tmp, ","); + } + c = (contents += 1)[0]; + } while (c != '"'); + c = (contents += 1)[0]; + fprintf(tmp, "]"); + } + fprintf(tmp, "%c", c); } + fprintf(tmp, "\n"); + return tmp; } char *parser(char *fileName){ - return readFile(fileName); + FILE *tmp = preProcess(readFile(fileName)); + fseek(tmp, 0, SEEK_END); + int len = ftell(tmp); + rewind(tmp); + char *buf = CheckedMalloc(len); + fgets(buf, len, tmp); + fclose(tmp); + return buf; } diff --git a/comp/lucas-standen-NEA/code/tokenizer/parser.h b/comp/lucas-standen-NEA/code/tokenizer/parser.h @@ -1,3 +1,3 @@ -char *Parse(char *fileName); // general parser function -char *ReadFile(char *fileName); // reads the file into a single var -char *preProcess(char *contents); +char *parser(char *fileName); // general parser function +char *readFile(char *fileName); // reads the file into a single var +FILE *preProcess(char *contents); diff --git a/comp/lucas-standen-NEA/code/tokenizer/test b/comp/lucas-standen-NEA/code/tokenizer/test Binary files differ. diff --git a/comp/lucas-standen-NEA/code/tokenizer/test.c b/comp/lucas-standen-NEA/code/tokenizer/test.c @@ -1,6 +0,0 @@ -#include "parser.h" - -int main(){ - char *sample = "(write \"hello\")"; - preProcess(sample); -}