diff options
author | standenboy <standenboy@seacrossedlovers.xyz> | 2024-04-30 14:22:45 +0100 |
---|---|---|
committer | standenboy <standenboy@seacrossedlovers.xyz> | 2024-04-30 14:22:45 +0100 |
commit | c460a26850eca5ded047d0eb0d183b861087aa53 (patch) | |
tree | 000c4a117746de71870fbee820809f7df49bcfcf /comp/lucas-standen-NEA/code | |
parent | 2e239a4ed2265f7c7dc2aabedfdb7d7b011704cb (diff) |
write up update
Diffstat (limited to 'comp/lucas-standen-NEA/code')
20 files changed, 311 insertions, 0 deletions
diff --git a/comp/lucas-standen-NEA/code/Makefile b/comp/lucas-standen-NEA/code/Makefile new file mode 100644 index 0000000..a30526c --- /dev/null +++ b/comp/lucas-standen-NEA/code/Makefile @@ -0,0 +1,6 @@ +all: + cd ads; make + cd parser; make + +tests: all + cd ads; make tests diff --git a/comp/lucas-standen-NEA/code/ads/Makefile b/comp/lucas-standen-NEA/code/ads/Makefile new file mode 100644 index 0000000..d6332cb --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/Makefile @@ -0,0 +1,6 @@ +all: + cd dict; make + cd ll; make +tests: all + cd dict; make test + cd ll; make test diff --git a/comp/lucas-standen-NEA/code/ads/dict/Makefile b/comp/lucas-standen-NEA/code/ads/dict/Makefile new file mode 100644 index 0000000..f224267 --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/dict/Makefile @@ -0,0 +1,4 @@ +all: dict.c + cc dict.c -c -o dict.o +test: all + cc dict.o dicttest.c -o dicttest diff --git a/comp/lucas-standen-NEA/code/ads/dict/dict.c b/comp/lucas-standen-NEA/code/ads/dict/dict.c new file mode 100644 index 0000000..551afca --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/dict/dict.c @@ -0,0 +1,29 @@ +#include <stdlib.h> +#include <string.h> + +typedef struct dict_t { + int id; + void *data; +}dict_t; + +dict_t *dictalloc(){ + dict_t *output = malloc(sizeof(dict_t)); + return output; +} + +int dictset(dict_t *dict, int id, void *data){ + dict->id = id; + + dict->data = malloc(sizeof(data)); + if (dict->data == NULL) + return 1; + memcpy(dict->data, data, sizeof(data)); + + return 0; +} + +void dictfree(dict_t *dict){ + free(dict->data); + free(dict); +} + diff --git a/comp/lucas-standen-NEA/code/ads/dict/dict.h b/comp/lucas-standen-NEA/code/ads/dict/dict.h new file mode 100644 index 0000000..e6ab69d --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/dict/dict.h @@ -0,0 +1,9 @@ +typedef struct dict_t { + int id; + void *data; +}dict_t; + +dict_t *dictalloc(); +int dictset(dict_t *dict, int id, void *data); +void dictfree(dict_t *dict); + diff --git a/comp/lucas-standen-NEA/code/ads/dict/dicttest b/comp/lucas-standen-NEA/code/ads/dict/dicttest Binary files differnew file mode 100755 index 0000000..dddf2a0 --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/dict/dicttest diff --git a/comp/lucas-standen-NEA/code/ads/dict/dicttest.c b/comp/lucas-standen-NEA/code/ads/dict/dicttest.c new file mode 100644 index 0000000..4a20870 --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/dict/dicttest.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +#include "dict.h" + +int main(){ + dict_t *dict = dictalloc(); + dictset(dict, 1, "hello"); + printf("%d:%s\n", dict->id, (char *)dict->data); + dictfree(dict); +} diff --git a/comp/lucas-standen-NEA/code/ads/ll/Makefile b/comp/lucas-standen-NEA/code/ads/ll/Makefile new file mode 100644 index 0000000..aaf0241 --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/ll/Makefile @@ -0,0 +1,5 @@ +all: ll.c + cc ll.c -c -o ll.o + +test: all + cc ll.o lltest.c -o lltest diff --git a/comp/lucas-standen-NEA/code/ads/ll/ll.c b/comp/lucas-standen-NEA/code/ads/ll/ll.c new file mode 100644 index 0000000..ba0a0df --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/ll/ll.c @@ -0,0 +1,57 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +typedef struct ll_t ll_t; + +typedef struct ll_t { + void *data; + ll_t *next; +} ll_t; + +ll_t *llalloc(){ + ll_t *output = malloc(sizeof(ll_t)); + if (output == NULL) + return NULL; + output->next = NULL; + return output; +} + +void llsetdata(ll_t *node, void *data){ + node->data = malloc(sizeof(data)); + memcpy(node->data, data, sizeof(data)); +} + +void llsetnext(ll_t *node, ll_t *next){ + if (node->next == NULL) + node->next = next; + else + llsetnext(node->next, next); +} + +void *llgetat(ll_t *head, int index){ + if (index == 0) + return head->data; + else { + if (head->next != NULL) { + return llgetat(head->next, index - 1); + }else { + return NULL; + } + } +} + +ll_t *llgetendnode(ll_t *head){ + if (head->next == NULL) + return head; + else + return llgetendnode(head->next); +} + +void llfreeall(ll_t *head){ + if (head->next != NULL) + llfreeall(head->next); + free(head->data); + free(head); +} + diff --git a/comp/lucas-standen-NEA/code/ads/ll/ll.h b/comp/lucas-standen-NEA/code/ads/ll/ll.h new file mode 100644 index 0000000..33b4d57 --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/ll/ll.h @@ -0,0 +1,16 @@ +#include <stdlib.h> +#include <string.h> + +typedef struct ll_t ll_t; + +typedef struct ll_t { + void *data; + ll_t *next; +} ll_t; + +ll_t *llalloc(); +void llsetdata(ll_t *node, void *data); +void llsetnext(ll_t *node, ll_t *next); +void *llgetat(ll_t *head, int index); +ll_t *llgetendnode(ll_t *head); +void llfreeall(ll_t *head); diff --git a/comp/lucas-standen-NEA/code/ads/ll/lltest b/comp/lucas-standen-NEA/code/ads/ll/lltest Binary files differnew file mode 100755 index 0000000..14653f6 --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/ll/lltest diff --git a/comp/lucas-standen-NEA/code/ads/ll/lltest.c b/comp/lucas-standen-NEA/code/ads/ll/lltest.c new file mode 100644 index 0000000..454acdf --- /dev/null +++ b/comp/lucas-standen-NEA/code/ads/ll/lltest.c @@ -0,0 +1,19 @@ +#include <stdio.h> + +#include "ll.h" + +int main(){ + ll_t *head = llalloc(); + llsetdata(head, "hello"); + + for (int i = 0; i < 3; i++){ + ll_t *node = llalloc(); + llsetdata(node, "hi"); + llsetnext(head, node); + } + for (int i = 0; i < 4; i++) + printf("%s\n", (char *)llgetat(head, i)); + printf("%s\n", llgetendnode(head)->data); + + llfreeall(head); +} diff --git a/comp/lucas-standen-NEA/code/parser/Makefile b/comp/lucas-standen-NEA/code/parser/Makefile new file mode 100644 index 0000000..9325d95 --- /dev/null +++ b/comp/lucas-standen-NEA/code/parser/Makefile @@ -0,0 +1,12 @@ +all: readfile preprocesor parser + cc readfile.o preprocessor.o parser.o -o parser + +readfile: + cc -c readfile.c -o readfile.o +preprocesor: + cc -c preprocessor.c -o preprocessor.o +parser: parser.c + cc -c parser.c -o parser.o + +clean: + rm -rf *.o parser diff --git a/comp/lucas-standen-NEA/code/parser/parser b/comp/lucas-standen-NEA/code/parser/parser Binary files differnew file mode 100755 index 0000000..9d996a8 --- /dev/null +++ b/comp/lucas-standen-NEA/code/parser/parser diff --git a/comp/lucas-standen-NEA/code/parser/parser.c b/comp/lucas-standen-NEA/code/parser/parser.c new file mode 100644 index 0000000..3162841 --- /dev/null +++ b/comp/lucas-standen-NEA/code/parser/parser.c @@ -0,0 +1,32 @@ +#include <string.h> +#include <stdio.h> +#include <stdbool.h> + +#include "preprocessor.h" + +int main(int argc, char **argv){ + if (argc <= 1){ + printf("no args given!\n"); + return 1; + } + char *code = preprocessor(argc, argv); + if (code == NULL){ + printf("falled to open file\n"); + return 1; + } + for (int i = 0; i < strlen(code); i++){ + if (code[i] == '{'){ + printf("\nopen-scope\n"); + } else if (code[i] == '}'){ + printf("\nclose-scope\n"); + }else { + if (code[i] == '(') + printf("\n"); + else if (code[i] != ')') + printf("%c", code[i]); + } + } + printf("\n"); + free(code); + return 0; +} diff --git a/comp/lucas-standen-NEA/code/parser/preprocessor.c b/comp/lucas-standen-NEA/code/parser/preprocessor.c new file mode 100644 index 0000000..92c6127 --- /dev/null +++ b/comp/lucas-standen-NEA/code/parser/preprocessor.c @@ -0,0 +1,24 @@ +#include <stdbool.h> +#include <string.h> + +#include "readfile.h" + +char *preprocessor(int argc, char **argv){ + char *buf = readfile(argv[1]); + if (buf == NULL) + return NULL; + + int i = 0; + + while (buf[i] != '\0'){ + if (buf[i] == '\n'){ + buf[i] = ' '; + } + if (buf[i] == '\t'){ + buf[i] = ' '; + } + i++; + } + + return buf; +} diff --git a/comp/lucas-standen-NEA/code/parser/preprocessor.h b/comp/lucas-standen-NEA/code/parser/preprocessor.h new file mode 100644 index 0000000..855240f --- /dev/null +++ b/comp/lucas-standen-NEA/code/parser/preprocessor.h @@ -0,0 +1,5 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +char *preprocessor(int argc, char **argv); diff --git a/comp/lucas-standen-NEA/code/parser/readfile.c b/comp/lucas-standen-NEA/code/parser/readfile.c new file mode 100644 index 0000000..391d5a5 --- /dev/null +++ b/comp/lucas-standen-NEA/code/parser/readfile.c @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdbool.h> + +bool instring = false; + +char *readfile(char *filepath){ + FILE *fptr; + fptr = fopen(filepath, "r"); + + if (fptr == NULL) + return NULL; + int size = 10; + char *buf = malloc(size); + char c; + + int i = 0; + + buf = buf+i; + buf[0] = '{'; + buf = buf-i; + + i++; + + while ((c = getc(fptr)) != EOF){ + if (i > size + 1){ + size = size + 10; + buf = realloc(buf, size); + } + if (c == '"'){ + if (instring == false) + instring = true; + else + instring = false; + } + + if (c == '!' && instring == false){ + while ((c = getc(fptr)) != EOF && c != '\n'){} + } + buf = buf+i; + buf[0] = c; + buf = buf-i; + i++; + + } + + buf = buf+i; + buf[0] = '}'; + buf = buf-i; + + i++; + + buf = buf+i; + buf[0] = '\0'; + buf = buf-i; + + fclose(fptr); + + return buf; +} diff --git a/comp/lucas-standen-NEA/code/parser/readfile.h b/comp/lucas-standen-NEA/code/parser/readfile.h new file mode 100644 index 0000000..12d98ec --- /dev/null +++ b/comp/lucas-standen-NEA/code/parser/readfile.h @@ -0,0 +1 @@ +char *readfile(char *filepath); diff --git a/comp/lucas-standen-NEA/code/parser/sample.zpy b/comp/lucas-standen-NEA/code/parser/sample.zpy new file mode 100644 index 0000000..e289d9d --- /dev/null +++ b/comp/lucas-standen-NEA/code/parser/sample.zpy @@ -0,0 +1,15 @@ +{ +(let fib:function +(defun num:i32 i32 + (if (< num 2) + (return num) + ) + (else + (return (+ (fib (- num 1)) (fib (- num 2)) )) + ) +)) +} +(let a:i32 (fib 5)) +(const str[]:char "hello!") +! returns the 5th fib number +(const str[]:char "hello!") |