diff options
Diffstat (limited to 'comp')
-rwxr-xr-x | comp/lucas-standen-NEA/code/execution/exec | bin | 42120 -> 37792 bytes | |||
-rwxr-xr-x | comp/lucas-standen-NEA/code/proto/AST/ast | bin | 24200 -> 19888 bytes | |||
-rwxr-xr-x | comp/lucas-standen-NEA/code/proto/parser/test | bin | 29728 -> 25464 bytes | |||
-rw-r--r-- | comp/lucas-standen-NEA/code/tokenizer/parser.c | 5 | ||||
-rwxr-xr-x | comp/lucas-standen-NEA/code/zpy/zpy | bin | 30432 -> 30272 bytes | |||
-rw-r--r-- | comp/lucas-standen-NEA/code2/Makefile | 16 | ||||
-rw-r--r-- | comp/lucas-standen-NEA/code2/TODO | 2 | ||||
-rw-r--r-- | comp/lucas-standen-NEA/code2/parser.c | 51 | ||||
-rw-r--r-- | comp/lucas-standen-NEA/code2/parser.h | 3 | ||||
-rw-r--r-- | comp/lucas-standen-NEA/code2/sample.zpy | 1 | ||||
-rw-r--r-- | comp/lucas-standen-NEA/code2/tokenizer.c | 42 | ||||
-rw-r--r-- | comp/lucas-standen-NEA/code2/tokenizer.h | 7 | ||||
-rw-r--r-- | comp/lucas-standen-NEA/code2/util.c | 9 | ||||
-rw-r--r-- | comp/lucas-standen-NEA/code2/util.h | 1 | ||||
-rw-r--r-- | comp/lucas-standen-NEA/code2/zpy.c | 23 |
15 files changed, 158 insertions, 2 deletions
diff --git a/comp/lucas-standen-NEA/code/execution/exec b/comp/lucas-standen-NEA/code/execution/exec Binary files differindex de1cd68..d69d951 100755 --- a/comp/lucas-standen-NEA/code/execution/exec +++ b/comp/lucas-standen-NEA/code/execution/exec diff --git a/comp/lucas-standen-NEA/code/proto/AST/ast b/comp/lucas-standen-NEA/code/proto/AST/ast Binary files differindex 69ccc93..be44ef5 100755 --- a/comp/lucas-standen-NEA/code/proto/AST/ast +++ b/comp/lucas-standen-NEA/code/proto/AST/ast diff --git a/comp/lucas-standen-NEA/code/proto/parser/test b/comp/lucas-standen-NEA/code/proto/parser/test Binary files differindex 6989562..6945399 100755 --- a/comp/lucas-standen-NEA/code/proto/parser/test +++ b/comp/lucas-standen-NEA/code/proto/parser/test diff --git a/comp/lucas-standen-NEA/code/tokenizer/parser.c b/comp/lucas-standen-NEA/code/tokenizer/parser.c index 78ba919..b2c3657 100644 --- a/comp/lucas-standen-NEA/code/tokenizer/parser.c +++ b/comp/lucas-standen-NEA/code/tokenizer/parser.c @@ -57,7 +57,7 @@ FILE *preProcess(char *contents){ } char **getExpressions(char *file){ // this doesn't work because str gets overwritten which changes the data stored at it's pointer, memcpy should be used - char **code = CheckedMalloc((strlen(file)/2)*sizeof(char *)); + char **code = CheckedMalloc(strlen(file)/4); int counter = 0; int depth = 0; char *str = CheckedMalloc(strlen(file)+1); @@ -73,7 +73,8 @@ char **getExpressions(char *file){ // this doesn't work because str gets overwri if (depth == 0) { str[pos] = '\0'; printf("%s\n", str); - code[counter] = str; + code[counter] = malloc(strlen(str)+1); + memcpy(code[counter], str, strlen((str)+1)); counter++; pos = 0; } diff --git a/comp/lucas-standen-NEA/code/zpy/zpy b/comp/lucas-standen-NEA/code/zpy/zpy Binary files differindex f3a466f..53c09ad 100755 --- a/comp/lucas-standen-NEA/code/zpy/zpy +++ b/comp/lucas-standen-NEA/code/zpy/zpy diff --git a/comp/lucas-standen-NEA/code2/Makefile b/comp/lucas-standen-NEA/code2/Makefile new file mode 100644 index 0000000..2b37de2 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/Makefile @@ -0,0 +1,16 @@ +CFLAGS= -O0 -ggdb + +all: _zpy _parser _tokenizer _util + cc zpy.o parser.o tokenizer.o util.o -o zpy ${CFLAGS} + +_zpy: zpy.c + cc zpy.c -c -o zpy.o ${CFLAGS} +_parser: parser.c + cc parser.c -c -o parser.o ${CFLAGS} +_tokenizer: tokenizer.c + cc tokenizer.c -c -o tokenizer.o ${CFLAGS} +_util: util.c + cc util.c -c -o util.o ${CFLAGS} + +clean: + rm -rf zpy *.o diff --git a/comp/lucas-standen-NEA/code2/TODO b/comp/lucas-standen-NEA/code2/TODO new file mode 100644 index 0000000..34deccd --- /dev/null +++ b/comp/lucas-standen-NEA/code2/TODO @@ -0,0 +1,2 @@ +make the tokenizer work, it needs to call recursively whenever it see's a '(' execept the first +expression, perhaps cut them off before the call diff --git a/comp/lucas-standen-NEA/code2/parser.c b/comp/lucas-standen-NEA/code2/parser.c new file mode 100644 index 0000000..ebf8e47 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/parser.c @@ -0,0 +1,51 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "util.h" + +int countChars(char *s, char c){ + int count = 0; + for (int i = 0; i < strlen(s); i++){ + if (s[i] == c) count++; + } + return count; +} + +char **parse(FILE *f){ + fseek(f, 0, SEEK_END); + int len = ftell(f); + rewind(f); + + char *contents = malloc(len); + + if (fread(contents, 1, len, f) == 0){ + die("failed to read file, is it formated properly"); + } + + char **tokens = malloc(countChars(contents, '\n')); + + int tokCount = 0; + int charCount = 0; + char *line = malloc(strlen(contents)); + for (int i = 0; i < len; i++){ + line[charCount] = contents[i]; + charCount++; + + if (contents[i] == '\n'){ + charCount--; + line[charCount] = '\0'; + tokens[tokCount] = malloc(strlen(line)+1); + + memcpy(tokens[tokCount], line, strlen(line)+1); + charCount = 0; + tokCount++; + } + } + + free(line); + free(contents); + + return tokens; +} diff --git a/comp/lucas-standen-NEA/code2/parser.h b/comp/lucas-standen-NEA/code2/parser.h new file mode 100644 index 0000000..94b5859 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/parser.h @@ -0,0 +1,3 @@ +#include <stdio.h> + +char **parse(FILE *f); diff --git a/comp/lucas-standen-NEA/code2/sample.zpy b/comp/lucas-standen-NEA/code2/sample.zpy new file mode 100644 index 0000000..7ffc605 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/sample.zpy @@ -0,0 +1 @@ +(let a:i64 (+ 2 3)) diff --git a/comp/lucas-standen-NEA/code2/tokenizer.c b/comp/lucas-standen-NEA/code2/tokenizer.c new file mode 100644 index 0000000..3b7e394 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/tokenizer.c @@ -0,0 +1,42 @@ +#include <stdlib.h> +#include <stdio.h> +#include<string.h> + +#include "util.h" + +typedef struct astNode { + char *funcName; + char *args[8]; + struct astNode *children[8]; +} astNode; + +astNode *tokenize(char *line){ + astNode *head = malloc(sizeof(astNode)); + + int depth = 0; + int charCount = 0; + int argCount = 0; + + + for (int i = 0; i < strlen(line); i++){ + switch (line[i]){ + case ' ': + argCount++; + charCount = 0; + break; + case '(': + 1 + default: + if (argCount >= 1){ + head->args[argCount][charCount] = line[i]; + charCount++; + } + else { + head->funcName[charCount] = line[i]; + charCount++; + } + } + } + + return NULL; +} diff --git a/comp/lucas-standen-NEA/code2/tokenizer.h b/comp/lucas-standen-NEA/code2/tokenizer.h new file mode 100644 index 0000000..eebfbc5 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/tokenizer.h @@ -0,0 +1,7 @@ +typedef struct astNode { + char *funcName; + char *args[8]; + struct astNode *children[8]; +} astNode; + +astNode *tokenize(char *line); diff --git a/comp/lucas-standen-NEA/code2/util.c b/comp/lucas-standen-NEA/code2/util.c new file mode 100644 index 0000000..5cda33e --- /dev/null +++ b/comp/lucas-standen-NEA/code2/util.c @@ -0,0 +1,9 @@ +#include <stdlib.h> +#include <stdio.h> + +void die(char *msg){ + fprintf(stderr, "zpy: %s\n", msg); + exit(1); + +} + diff --git a/comp/lucas-standen-NEA/code2/util.h b/comp/lucas-standen-NEA/code2/util.h new file mode 100644 index 0000000..d244c93 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/util.h @@ -0,0 +1 @@ +void die(char *msg); diff --git a/comp/lucas-standen-NEA/code2/zpy.c b/comp/lucas-standen-NEA/code2/zpy.c new file mode 100644 index 0000000..3ec448a --- /dev/null +++ b/comp/lucas-standen-NEA/code2/zpy.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "util.h" +#include "parser.h" +#include "tokenizer.h" + +int main(int argc, char **argv){ + if (argc < 2) + die("no input files!"); + + FILE *f = fopen(argv[1], "r"); + if (f == NULL) + die("no such file or directory"); + + char **stringTokens = parse(f); + + if (stringTokens == NULL) + die("couldn't parse file, is it formated properly?"); + + tokenize(stringTokens[0]); + +} |