diff options
author | thing1 <thing1@seacrossedlovers.xyz> | 2024-07-08 11:36:32 +0100 |
---|---|---|
committer | thing1 <thing1@seacrossedlovers.xyz> | 2024-07-08 11:36:32 +0100 |
commit | 4db750bbf03c9d7c18291fc63b7cf23cf966d6c8 (patch) | |
tree | 5abe611dc75cf50160ba29506076f3b5368e9e26 /comp/lucas-standen-NEA/code | |
parent | 3dad2f4c5ce7fd44015cbd921318b3512c36326e (diff) |
i forgot to commit last time i think
Diffstat (limited to 'comp/lucas-standen-NEA/code')
17 files changed, 52 insertions, 21 deletions
diff --git a/comp/lucas-standen-NEA/code/TODO b/comp/lucas-standen-NEA/code/TODO index 25766b5..0ec1882 100644 --- 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/AST/Makefile b/comp/lucas-standen-NEA/code/proto/AST/Makefile new file mode 100644 index 0000000..6074b00 --- /dev/null +++ b/comp/lucas-standen-NEA/code/proto/AST/Makefile @@ -0,0 +1,4 @@ +all: astg ast.c + cc -ggdb ast.c astg.o -o ast +astg: astg.c + cc -ggdb astg.c -c -o astg.o diff --git a/comp/lucas-standen-NEA/code/proto/ast b/comp/lucas-standen-NEA/code/proto/AST/ast Binary files differindex f922f0d..69ccc93 100755 --- a/comp/lucas-standen-NEA/code/proto/ast +++ b/comp/lucas-standen-NEA/code/proto/AST/ast diff --git a/comp/lucas-standen-NEA/code/proto/ast.c b/comp/lucas-standen-NEA/code/proto/AST/ast.c index d76107b..d76107b 100644 --- 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 index e96b771..e96b771 100644 --- 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 index 16250b2..16250b2 100644 --- 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 index e69de29..e69de29 100644 --- 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 index e69de29..e69de29 100644 --- 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 index 6074b00..adb84a1 100644 --- 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/parser/Makefile b/comp/lucas-standen-NEA/code/proto/parser/Makefile new file mode 100644 index 0000000..e8ab981 --- /dev/null +++ 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 new file mode 100644 index 0000000..fb998be --- /dev/null +++ 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 differnew file mode 100755 index 0000000..bc47f65 --- /dev/null +++ b/comp/lucas-standen-NEA/code/proto/parser/test diff --git a/comp/lucas-standen-NEA/code/proto/parser/test.c b/comp/lucas-standen-NEA/code/proto/parser/test.c new file mode 100644 index 0000000..fcc8f3c --- /dev/null +++ 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 index 4bb9c3a..7d827f9 100644 --- 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 index f90b777..993d257 100644 --- 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 differdeleted file mode 100755 index 797a447..0000000 --- a/comp/lucas-standen-NEA/code/tokenizer/test +++ /dev/null diff --git a/comp/lucas-standen-NEA/code/tokenizer/test.c b/comp/lucas-standen-NEA/code/tokenizer/test.c deleted file mode 100644 index 49d6160..0000000 --- a/comp/lucas-standen-NEA/code/tokenizer/test.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "parser.h" - -int main(){ - char *sample = "(write \"hello\")"; - preProcess(sample); -} |