From c460a26850eca5ded047d0eb0d183b861087aa53 Mon Sep 17 00:00:00 2001 From: standenboy Date: Tue, 30 Apr 2024 14:22:45 +0100 Subject: write up update --- comp/cs-oracle | 2 +- comp/cw/code/ads/dict/Makefile | 4 - comp/cw/code/ads/dict/dict.c | 29 --- comp/cw/code/ads/dict/dict.h | 9 - comp/cw/code/ads/dict/dicttest | Bin 20536 -> 0 bytes comp/cw/code/ads/dict/dicttest.c | 10 - comp/cw/code/ads/ll/Makefile | 5 - comp/cw/code/ads/ll/ll.c | 50 ---- comp/cw/code/ads/ll/ll.h | 15 -- comp/cw/code/ads/ll/lltest | Bin 20592 -> 0 bytes comp/cw/code/ads/ll/lltest.c | 18 -- comp/cw/code/parser/Makefile | 12 - comp/cw/code/parser/parser | Bin 20880 -> 0 bytes comp/cw/code/parser/parser.c | 32 --- comp/cw/code/parser/parser.o | Bin 2256 -> 0 bytes comp/cw/code/parser/preprocessor.c | 24 -- comp/cw/code/parser/preprocessor.h | 5 - comp/cw/code/parser/preprocessor.o | Bin 1504 -> 0 bytes comp/cw/code/parser/readfile.c | 61 ----- comp/cw/code/parser/readfile.h | 1 - comp/cw/code/parser/readfile.o | Bin 2208 -> 0 bytes comp/cw/code/parser/sample.zpy | 15 -- comp/cw/code/tokenizer/ads/dict/Makefile | 4 - comp/cw/code/tokenizer/ads/dict/dict.c | 29 --- comp/cw/code/tokenizer/ads/dict/dict.h | 9 - comp/cw/code/tokenizer/ads/dict/dict.o | Bin 1768 -> 0 bytes comp/cw/code/tokenizer/ads/dict/dicttest | Bin 20536 -> 0 bytes comp/cw/code/tokenizer/ads/dict/dicttest.c | 10 - comp/cw/code/tokenizer/ads/dll/Makefile | 5 - comp/cw/code/tokenizer/ads/dll/dll.c | 62 ----- comp/cw/code/tokenizer/ads/dll/dll.h | 19 -- comp/cw/code/tokenizer/ads/dll/dll.o | Bin 2424 -> 0 bytes comp/cw/code/tokenizer/ads/dll/dlltest | Bin 20640 -> 0 bytes comp/cw/code/tokenizer/ads/dll/dlltest.c | 20 -- comp/cw/code/tokenizer/ads/ll/Makefile | 5 - comp/cw/code/tokenizer/ads/ll/ll.c | 50 ---- comp/cw/code/tokenizer/ads/ll/ll.h | 15 -- comp/cw/code/tokenizer/ads/ll/ll.o | Bin 2184 -> 0 bytes comp/cw/code/tokenizer/ads/ll/lltest | Bin 20592 -> 0 bytes comp/cw/code/tokenizer/ads/ll/lltest.c | 18 -- comp/cw/overview | 302 ---------------------- comp/lucas-standen-NEA/code/Makefile | 6 + comp/lucas-standen-NEA/code/ads/Makefile | 6 + comp/lucas-standen-NEA/code/ads/dict/Makefile | 4 + comp/lucas-standen-NEA/code/ads/dict/dict.c | 29 +++ comp/lucas-standen-NEA/code/ads/dict/dict.h | 9 + comp/lucas-standen-NEA/code/ads/dict/dicttest | Bin 0 -> 20536 bytes comp/lucas-standen-NEA/code/ads/dict/dicttest.c | 10 + comp/lucas-standen-NEA/code/ads/ll/Makefile | 5 + comp/lucas-standen-NEA/code/ads/ll/ll.c | 57 ++++ comp/lucas-standen-NEA/code/ads/ll/ll.h | 16 ++ comp/lucas-standen-NEA/code/ads/ll/lltest | Bin 0 -> 20632 bytes comp/lucas-standen-NEA/code/ads/ll/lltest.c | 19 ++ comp/lucas-standen-NEA/code/parser/Makefile | 12 + comp/lucas-standen-NEA/code/parser/parser | Bin 0 -> 20880 bytes comp/lucas-standen-NEA/code/parser/parser.c | 32 +++ comp/lucas-standen-NEA/code/parser/preprocessor.c | 24 ++ comp/lucas-standen-NEA/code/parser/preprocessor.h | 5 + comp/lucas-standen-NEA/code/parser/readfile.c | 61 +++++ comp/lucas-standen-NEA/code/parser/readfile.h | 1 + comp/lucas-standen-NEA/code/parser/sample.zpy | 15 ++ comp/lucas-standen-NEA/overview | 302 ++++++++++++++++++++++ comp/lucas-standen-NEA/writeup/coverpage.html | 131 ++++++++++ comp/lucas-standen-NEA/writeup/coverpage.ms | 46 ++++ comp/lucas-standen-NEA/writeup/coverpage.pdf | Bin 0 -> 17509 bytes comp/lucas-standen-NEA/writeup/make.sh | 2 + comp/work/31/__pycache__/bubble.cpython-312.pyc | Bin 0 -> 981 bytes comp/work/31/__pycache__/merge.cpython-312.pyc | Bin 0 -> 1641 bytes comp/work/31/bubble.py | 22 ++ comp/work/31/menu.py | 20 ++ comp/work/31/merge.py | 39 +++ 71 files changed, 874 insertions(+), 839 deletions(-) delete mode 100644 comp/cw/code/ads/dict/Makefile delete mode 100644 comp/cw/code/ads/dict/dict.c delete mode 100644 comp/cw/code/ads/dict/dict.h delete mode 100755 comp/cw/code/ads/dict/dicttest delete mode 100644 comp/cw/code/ads/dict/dicttest.c delete mode 100644 comp/cw/code/ads/ll/Makefile delete mode 100644 comp/cw/code/ads/ll/ll.c delete mode 100644 comp/cw/code/ads/ll/ll.h delete mode 100755 comp/cw/code/ads/ll/lltest delete mode 100644 comp/cw/code/ads/ll/lltest.c delete mode 100644 comp/cw/code/parser/Makefile delete mode 100755 comp/cw/code/parser/parser delete mode 100644 comp/cw/code/parser/parser.c delete mode 100644 comp/cw/code/parser/parser.o delete mode 100644 comp/cw/code/parser/preprocessor.c delete mode 100644 comp/cw/code/parser/preprocessor.h delete mode 100644 comp/cw/code/parser/preprocessor.o delete mode 100644 comp/cw/code/parser/readfile.c delete mode 100644 comp/cw/code/parser/readfile.h delete mode 100644 comp/cw/code/parser/readfile.o delete mode 100644 comp/cw/code/parser/sample.zpy delete mode 100644 comp/cw/code/tokenizer/ads/dict/Makefile delete mode 100644 comp/cw/code/tokenizer/ads/dict/dict.c delete mode 100644 comp/cw/code/tokenizer/ads/dict/dict.h delete mode 100644 comp/cw/code/tokenizer/ads/dict/dict.o delete mode 100755 comp/cw/code/tokenizer/ads/dict/dicttest delete mode 100644 comp/cw/code/tokenizer/ads/dict/dicttest.c delete mode 100644 comp/cw/code/tokenizer/ads/dll/Makefile delete mode 100644 comp/cw/code/tokenizer/ads/dll/dll.c delete mode 100644 comp/cw/code/tokenizer/ads/dll/dll.h delete mode 100644 comp/cw/code/tokenizer/ads/dll/dll.o delete mode 100755 comp/cw/code/tokenizer/ads/dll/dlltest delete mode 100644 comp/cw/code/tokenizer/ads/dll/dlltest.c delete mode 100644 comp/cw/code/tokenizer/ads/ll/Makefile delete mode 100644 comp/cw/code/tokenizer/ads/ll/ll.c delete mode 100644 comp/cw/code/tokenizer/ads/ll/ll.h delete mode 100644 comp/cw/code/tokenizer/ads/ll/ll.o delete mode 100755 comp/cw/code/tokenizer/ads/ll/lltest delete mode 100644 comp/cw/code/tokenizer/ads/ll/lltest.c delete mode 100644 comp/cw/overview create mode 100644 comp/lucas-standen-NEA/code/Makefile create mode 100644 comp/lucas-standen-NEA/code/ads/Makefile create mode 100644 comp/lucas-standen-NEA/code/ads/dict/Makefile create mode 100644 comp/lucas-standen-NEA/code/ads/dict/dict.c create mode 100644 comp/lucas-standen-NEA/code/ads/dict/dict.h create mode 100755 comp/lucas-standen-NEA/code/ads/dict/dicttest create mode 100644 comp/lucas-standen-NEA/code/ads/dict/dicttest.c create mode 100644 comp/lucas-standen-NEA/code/ads/ll/Makefile create mode 100644 comp/lucas-standen-NEA/code/ads/ll/ll.c create mode 100644 comp/lucas-standen-NEA/code/ads/ll/ll.h create mode 100755 comp/lucas-standen-NEA/code/ads/ll/lltest create mode 100644 comp/lucas-standen-NEA/code/ads/ll/lltest.c create mode 100644 comp/lucas-standen-NEA/code/parser/Makefile create mode 100755 comp/lucas-standen-NEA/code/parser/parser create mode 100644 comp/lucas-standen-NEA/code/parser/parser.c create mode 100644 comp/lucas-standen-NEA/code/parser/preprocessor.c create mode 100644 comp/lucas-standen-NEA/code/parser/preprocessor.h create mode 100644 comp/lucas-standen-NEA/code/parser/readfile.c create mode 100644 comp/lucas-standen-NEA/code/parser/readfile.h create mode 100644 comp/lucas-standen-NEA/code/parser/sample.zpy create mode 100644 comp/lucas-standen-NEA/overview create mode 100644 comp/lucas-standen-NEA/writeup/coverpage.html create mode 100644 comp/lucas-standen-NEA/writeup/coverpage.ms create mode 100644 comp/lucas-standen-NEA/writeup/coverpage.pdf create mode 100755 comp/lucas-standen-NEA/writeup/make.sh create mode 100644 comp/work/31/__pycache__/bubble.cpython-312.pyc create mode 100644 comp/work/31/__pycache__/merge.cpython-312.pyc create mode 100644 comp/work/31/bubble.py create mode 100644 comp/work/31/menu.py create mode 100644 comp/work/31/merge.py diff --git a/comp/cs-oracle b/comp/cs-oracle index da29662..57e0dfa 160000 --- a/comp/cs-oracle +++ b/comp/cs-oracle @@ -1 +1 @@ -Subproject commit da2966288031c1f5a9741a3d37b4e537b9239e01 +Subproject commit 57e0dfaed57469001aaac128fe2649a8c5056419 diff --git a/comp/cw/code/ads/dict/Makefile b/comp/cw/code/ads/dict/Makefile deleted file mode 100644 index f224267..0000000 --- a/comp/cw/code/ads/dict/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: dict.c - cc dict.c -c -o dict.o -test: all - cc dict.o dicttest.c -o dicttest diff --git a/comp/cw/code/ads/dict/dict.c b/comp/cw/code/ads/dict/dict.c deleted file mode 100644 index 551afca..0000000 --- a/comp/cw/code/ads/dict/dict.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -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/cw/code/ads/dict/dict.h b/comp/cw/code/ads/dict/dict.h deleted file mode 100644 index e6ab69d..0000000 --- a/comp/cw/code/ads/dict/dict.h +++ /dev/null @@ -1,9 +0,0 @@ -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/cw/code/ads/dict/dicttest b/comp/cw/code/ads/dict/dicttest deleted file mode 100755 index dddf2a0..0000000 Binary files a/comp/cw/code/ads/dict/dicttest and /dev/null differ diff --git a/comp/cw/code/ads/dict/dicttest.c b/comp/cw/code/ads/dict/dicttest.c deleted file mode 100644 index 4a20870..0000000 --- a/comp/cw/code/ads/dict/dicttest.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#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/cw/code/ads/ll/Makefile b/comp/cw/code/ads/ll/Makefile deleted file mode 100644 index aaf0241..0000000 --- a/comp/cw/code/ads/ll/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: ll.c - cc ll.c -c -o ll.o - -test: all - cc ll.o lltest.c -o lltest diff --git a/comp/cw/code/ads/ll/ll.c b/comp/cw/code/ads/ll/ll.c deleted file mode 100644 index c45ab0c..0000000 --- a/comp/cw/code/ads/ll/ll.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include - -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; - } - } -} - -void llfreeall(ll_t *head){ - if (head->next != NULL) - llfreeall(head->next); - free(head->data); - free(head); -} - diff --git a/comp/cw/code/ads/ll/ll.h b/comp/cw/code/ads/ll/ll.h deleted file mode 100644 index 30830b1..0000000 --- a/comp/cw/code/ads/ll/ll.h +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -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); -void llfreeall(ll_t *head); diff --git a/comp/cw/code/ads/ll/lltest b/comp/cw/code/ads/ll/lltest deleted file mode 100755 index b98c5de..0000000 Binary files a/comp/cw/code/ads/ll/lltest and /dev/null differ diff --git a/comp/cw/code/ads/ll/lltest.c b/comp/cw/code/ads/ll/lltest.c deleted file mode 100644 index 8aa6514..0000000 --- a/comp/cw/code/ads/ll/lltest.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#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)); - - llfreeall(head); -} diff --git a/comp/cw/code/parser/Makefile b/comp/cw/code/parser/Makefile deleted file mode 100644 index 9325d95..0000000 --- a/comp/cw/code/parser/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -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/cw/code/parser/parser b/comp/cw/code/parser/parser deleted file mode 100755 index 9d996a8..0000000 Binary files a/comp/cw/code/parser/parser and /dev/null differ diff --git a/comp/cw/code/parser/parser.c b/comp/cw/code/parser/parser.c deleted file mode 100644 index 3162841..0000000 --- a/comp/cw/code/parser/parser.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include - -#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/cw/code/parser/parser.o b/comp/cw/code/parser/parser.o deleted file mode 100644 index baccd37..0000000 Binary files a/comp/cw/code/parser/parser.o and /dev/null differ diff --git a/comp/cw/code/parser/preprocessor.c b/comp/cw/code/parser/preprocessor.c deleted file mode 100644 index 92c6127..0000000 --- a/comp/cw/code/parser/preprocessor.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include - -#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/cw/code/parser/preprocessor.h b/comp/cw/code/parser/preprocessor.h deleted file mode 100644 index 855240f..0000000 --- a/comp/cw/code/parser/preprocessor.h +++ /dev/null @@ -1,5 +0,0 @@ -#include -#include -#include - -char *preprocessor(int argc, char **argv); diff --git a/comp/cw/code/parser/preprocessor.o b/comp/cw/code/parser/preprocessor.o deleted file mode 100644 index fad2c87..0000000 Binary files a/comp/cw/code/parser/preprocessor.o and /dev/null differ diff --git a/comp/cw/code/parser/readfile.c b/comp/cw/code/parser/readfile.c deleted file mode 100644 index 391d5a5..0000000 --- a/comp/cw/code/parser/readfile.c +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include -#include - -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/cw/code/parser/readfile.h b/comp/cw/code/parser/readfile.h deleted file mode 100644 index 12d98ec..0000000 --- a/comp/cw/code/parser/readfile.h +++ /dev/null @@ -1 +0,0 @@ -char *readfile(char *filepath); diff --git a/comp/cw/code/parser/readfile.o b/comp/cw/code/parser/readfile.o deleted file mode 100644 index 32bc31d..0000000 Binary files a/comp/cw/code/parser/readfile.o and /dev/null differ diff --git a/comp/cw/code/parser/sample.zpy b/comp/cw/code/parser/sample.zpy deleted file mode 100644 index e289d9d..0000000 --- a/comp/cw/code/parser/sample.zpy +++ /dev/null @@ -1,15 +0,0 @@ -{ -(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!") diff --git a/comp/cw/code/tokenizer/ads/dict/Makefile b/comp/cw/code/tokenizer/ads/dict/Makefile deleted file mode 100644 index f224267..0000000 --- a/comp/cw/code/tokenizer/ads/dict/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: dict.c - cc dict.c -c -o dict.o -test: all - cc dict.o dicttest.c -o dicttest diff --git a/comp/cw/code/tokenizer/ads/dict/dict.c b/comp/cw/code/tokenizer/ads/dict/dict.c deleted file mode 100644 index 551afca..0000000 --- a/comp/cw/code/tokenizer/ads/dict/dict.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -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/cw/code/tokenizer/ads/dict/dict.h b/comp/cw/code/tokenizer/ads/dict/dict.h deleted file mode 100644 index e6ab69d..0000000 --- a/comp/cw/code/tokenizer/ads/dict/dict.h +++ /dev/null @@ -1,9 +0,0 @@ -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/cw/code/tokenizer/ads/dict/dict.o b/comp/cw/code/tokenizer/ads/dict/dict.o deleted file mode 100644 index aefd77a..0000000 Binary files a/comp/cw/code/tokenizer/ads/dict/dict.o and /dev/null differ diff --git a/comp/cw/code/tokenizer/ads/dict/dicttest b/comp/cw/code/tokenizer/ads/dict/dicttest deleted file mode 100755 index dddf2a0..0000000 Binary files a/comp/cw/code/tokenizer/ads/dict/dicttest and /dev/null differ diff --git a/comp/cw/code/tokenizer/ads/dict/dicttest.c b/comp/cw/code/tokenizer/ads/dict/dicttest.c deleted file mode 100644 index 4a20870..0000000 --- a/comp/cw/code/tokenizer/ads/dict/dicttest.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#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/cw/code/tokenizer/ads/dll/Makefile b/comp/cw/code/tokenizer/ads/dll/Makefile deleted file mode 100644 index 651681d..0000000 --- a/comp/cw/code/tokenizer/ads/dll/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: dll.c - cc dll.c -c -o dll.o - -test: all - cc dll.o dlltest.c -o dlltest diff --git a/comp/cw/code/tokenizer/ads/dll/dll.c b/comp/cw/code/tokenizer/ads/dll/dll.c deleted file mode 100644 index b24b13f..0000000 --- a/comp/cw/code/tokenizer/ads/dll/dll.c +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -#include - -typedef struct dll_t dll_t; - -typedef struct dll_t { - void *data; - dll_t *next; - dll_t *prev; -} dll_t; - -dll_t *dllalloc(){ - dll_t *output = malloc(sizeof(dll_t)); - if (output == NULL) - return NULL; - output->next = NULL; - output->prev = NULL; - return output; -} - -void dllsetdata(dll_t *node, void *data){ - node->data = malloc(sizeof(data)); - memcpy(node->data, data, sizeof(data)); -} - -void dllsetnext(dll_t *node, dll_t *next){ - if (node->next == NULL) { - node->next = next; - node->next->prev = node; - } - else - dllsetnext(node->next, next); -} -void dllsetprev(dll_t *node, dll_t *prev){ - if (node->prev == NULL) { - node->prev = prev; - node->prev->next = node; - } - else - dllsetprev(node->prev, prev); -} - -void *dllgetat(dll_t *head, int index){ - if (index == 0) - return head->data; - else { - if (head->next != NULL) { - return dllgetat(head->next, index - 1); - }else { - return NULL; - } - } -} - -void dllfreeall(dll_t *head){ - if (head->next != NULL) - dllfreeall(head->next); - free(head->data); - free(head); -} - diff --git a/comp/cw/code/tokenizer/ads/dll/dll.h b/comp/cw/code/tokenizer/ads/dll/dll.h deleted file mode 100644 index 44940ce..0000000 --- a/comp/cw/code/tokenizer/ads/dll/dll.h +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include - -typedef struct dll_t dll_t; - -typedef struct dll_t { - void *data; - dll_t *next; - dll_t *prev; -} dll_t; - -dll_t *dllalloc(); -void dllsetdata(dll_t *node, void *data); -void dllsetnext(dll_t *node, dll_t *next); -void dllsetprev(dll_t *node, dll_t *prev); -void *dllgetat(dll_t *head, int index); -void dllfreeall(dll_t *head); - diff --git a/comp/cw/code/tokenizer/ads/dll/dll.o b/comp/cw/code/tokenizer/ads/dll/dll.o deleted file mode 100644 index 2c9a145..0000000 Binary files a/comp/cw/code/tokenizer/ads/dll/dll.o and /dev/null differ diff --git a/comp/cw/code/tokenizer/ads/dll/dlltest b/comp/cw/code/tokenizer/ads/dll/dlltest deleted file mode 100755 index 83f900c..0000000 Binary files a/comp/cw/code/tokenizer/ads/dll/dlltest and /dev/null differ diff --git a/comp/cw/code/tokenizer/ads/dll/dlltest.c b/comp/cw/code/tokenizer/ads/dll/dlltest.c deleted file mode 100644 index 4544d2e..0000000 --- a/comp/cw/code/tokenizer/ads/dll/dlltest.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#include "dll.h" - -int main(){ - dll_t *head = dllalloc(); - dllsetdata(head, "hello"); - - for (int i = 0; i < 3; i++){ - dll_t *node = dllalloc(); - dllsetdata(node, "hi"); - dllsetnext(head, node); - } - - for (int i = 0; i < 4; i++) - printf("%s\n", (char *)dllgetat(head, i)); - printf("%s\n", (char *)head->prev->next->data); - - dllfreeall(head); -} diff --git a/comp/cw/code/tokenizer/ads/ll/Makefile b/comp/cw/code/tokenizer/ads/ll/Makefile deleted file mode 100644 index aaf0241..0000000 --- a/comp/cw/code/tokenizer/ads/ll/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: ll.c - cc ll.c -c -o ll.o - -test: all - cc ll.o lltest.c -o lltest diff --git a/comp/cw/code/tokenizer/ads/ll/ll.c b/comp/cw/code/tokenizer/ads/ll/ll.c deleted file mode 100644 index c45ab0c..0000000 --- a/comp/cw/code/tokenizer/ads/ll/ll.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include - -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; - } - } -} - -void llfreeall(ll_t *head){ - if (head->next != NULL) - llfreeall(head->next); - free(head->data); - free(head); -} - diff --git a/comp/cw/code/tokenizer/ads/ll/ll.h b/comp/cw/code/tokenizer/ads/ll/ll.h deleted file mode 100644 index 30830b1..0000000 --- a/comp/cw/code/tokenizer/ads/ll/ll.h +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -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); -void llfreeall(ll_t *head); diff --git a/comp/cw/code/tokenizer/ads/ll/ll.o b/comp/cw/code/tokenizer/ads/ll/ll.o deleted file mode 100644 index b033278..0000000 Binary files a/comp/cw/code/tokenizer/ads/ll/ll.o and /dev/null differ diff --git a/comp/cw/code/tokenizer/ads/ll/lltest b/comp/cw/code/tokenizer/ads/ll/lltest deleted file mode 100755 index b98c5de..0000000 Binary files a/comp/cw/code/tokenizer/ads/ll/lltest and /dev/null differ diff --git a/comp/cw/code/tokenizer/ads/ll/lltest.c b/comp/cw/code/tokenizer/ads/ll/lltest.c deleted file mode 100644 index 8aa6514..0000000 --- a/comp/cw/code/tokenizer/ads/ll/lltest.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#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)); - - llfreeall(head); -} diff --git a/comp/cw/overview b/comp/cw/overview deleted file mode 100644 index 5f7904e..0000000 --- a/comp/cw/overview +++ /dev/null @@ -1,302 +0,0 @@ -CS course work project - -zippy - a high level functional programing language - -zippy will be an interpreted language designed to replace C in higher level use -C is used largely to write most of the unix desktop, however c can be difficult -when writing larger programs, and is missing moddern features like oop or -functional patterns (higher order functions) - -requirents: - - must be human readable, even a non programmer should be able to figure - out what a program is doing - - faster than competion, other languages that have tried to slot into - this position like python are far to slow, and thus it must be faster - - low runtime overhead, the interpreter should be small, it shouldn't - force the developer to think about how the interpreter works to use it - efficently - - have moddern tools, a pkg manager and enviroment manager, making it - easy to develop for - - needs to support c libarys - -language info - -zippy will use function programming as a primary solution, however also support -simple oop, with classes (no inheritence) -its syntax will be comparable to lisp, with prolific use of "()" -it will need a stdlib, which can be taken from C's stdlib - -types: - - char - just like a c char - i32 - 32 bit signed int - f32 - 32 bit signed float - u32 - unsigned 32 bit int - i16- 16 bit signed int - u16 - 16 bit unsigned int - bool - TRUE/FALSE - - - arrays: - - arrays can be created like so - (let arr[]:char "hello there") - (let arr[]:i32 1 2 3) - - all arrays are linked lists of there data type - their size is not fixed - - you can get, or set the value of an array at a specific index using - arr[index] - - strings: - - strings are arrays of chars - a string can be defined by a litteral like so - "hello world" - this is the same as 'h' 'e' 'l'.... - because this is represented as a linked list there is no need to have a - NULL terminator like in c, the end of the string is jus the point where the - linked list has no more nodes - -comments: - - comments can be writen like so - ! this is a comment - -indentation and spacing: - - indentation and new lines arent at all necesary - any new lines will be converted to spaces, and tabs will be removed - the only place that needs spaces is when calling a function and giving its args - -scopes: - - () can be placed anywhere, and anything that is in them is in there own scope - as soon as the bracket is closed, any variables defined in the scope - will be deleted - any scope inherets all variables and functions from the scope that contains it - code writen in the main body of the file can be imagined like so - ( - ... - ... - ... - your code - ... - ... - ... - ) - however that level of indentation is not needed - - this can be helpful if you want to have two scopes with different imports - ( - (import z) - ( - (import x) - ! anything writen here has access to libary x and z - ) - ( - (import y) - ! anything writen here has access to libary y and z - ) - ! anything writen here has access to libary z - ) - -libarys: - - libarys are similar to header files in c - when imported the user can use any function contained within the file - - it would be good practice to put your libary in a struct to avoid functions with the - same names coming from 2 libarys, however its not needed - -errors: - - errors would be - -keywords: - - (defun arg1:type arg2:type returnType - ... - ... - ... - ) - defines a function, can be done anywhere in the program, all functions - must return a value, return type and arguments must be known at runtime - - returns the function that can be asigned with let - - (return VALUE) - returns VALUE from a function, VALUE must be of the same tupe as returnType - in defun - - (for x a b function) - - runs the function inside the loop, x will be increment by 1 each iteration and - it will have a starting value of a running until it reaches b (inclusive) - x cant be changed in any way other than the for loop - x, a, b are all of type i32 - - (while condtion function) - - runs all code inside the loop until the condion is not TRUE - condition must be a bool (TRUE/FALSE) - - (let name:type value) - - assign value to variable name, this will create the variable if it doesn't already - exist, and overwrite it if it does - names type must be defined by type - - (const name:type value) - - same as let but creates an imutable variable - - (import libary) - - searches the libary dir and imports the libary to the current project - libary can also be a specific path if it starts with / or ./ or ../ - - (struct name - ... - ... - ... - (defun init arg1:type type - ... - ... - ... - ) - (defun deinit arg1:type type - ... - ... - ... - ) - ) - - structs can be used as a custom data type - creates a struct/class called name, functions called init will be ran when an - object is created - when deinit is called the code init will be ran, then the object will be deleted - if deinit is not defined it can still be called to delete the instace of the class - - you can create a struct like so: - (let mystruct:name (name.init arg1 arg2)) - - you can call a method attached to an instace of a struct like this: - (mystruct.method arg1 arg2) - - and to destroy it you can just use this: - (mystruct.deinit arg1 arg2) - - structs can be recursive - eg: - (struct node - (defun init next:node - (let next:node next) - ) - ) - - a struct can have default values - eg: - (struct person - (let age:i32 50) - (let name[]:char "john doe") - ... - ... - ... - ) - - this will make the struct have default values - - overall in simple terms structs are just like c structs but they can contain - functions - - (symbol arg1:type arg2:type returntype location) - - returns a function that can be called. the function is retrieved from a .o file - which can be writen in C, the args, should be the args that the function takes in - and there types - the interpreter will try to convert data to the equal type in C, however this may need - to be done manually - the location should be a string which is is the file path to the .o file - - (if condition - ... - ... - ... - )(elif condition - ... - ... - ... - )(else - ... - ... - ... - ) - - simple if statment, if condition is TRUE run the code inside, elif runs if the condition in it - is TRUE and if the previous has not been TRUE - else will run if nothing else is TRUE - - (cast TYPE variable) - - returns a variable casted to type TYPE, if type is function, will return a function with no args - that returns the variable value in its starting type - - conditions: - (= a b) returns TRUE if a is equal to be (works with arrays) - (!= a b) returns TRUE if a is not equal to be (works with arrays) - (> a b) returns TRUE if a > b (does not work with arrays) - (< a b) returns TRUE if a < b (does not work with arrays) - (>= a b) returns TRUE if a >= b (does not work with arrays) - (<= a b) returns TRUE if a <= b (does not work with arrays) - (! a) returns TRUE if a is FALSE (only works on bools) - (| a b) returns TRUE if a or b are TRUE (only works on bools) - (& a b) returns TRUE if a and b are TRUE (only works on bools) - (^ a b) returns TRUE if a xor b is true (only works on bools) - - all these are just functions that can be used to assign values - eg: - (let mybool:bool (= a b)) - ! mybool will be TRUE if a = b - - mathmatical operations: - zippy uses reverse polish notation - (+ a b) returns a + b - (- a b) returns a - b - (* a b) returns a * b - (/ a b) returns a / b, whole number eg: (/ 7 3) = 2 - (/. a b) returns a / b, floating point number eg: (/. 7 3) = 2.5 - (% a b) returns the remander of (/ a b) - (** a b) returns a ^ b - - -sample code - (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)) - ! returns the 5th fib number - -stdlib: - (import io) - io contains a few types - they are: - (io.file) - io contains many io related functions - they are: - - (io.write "hello %s\n" name) ! this is very similar to printf in C - (let input:char[] (io.read)) - - (let file:io.file (io.open path[]:char "method")) - - (io.fwrite file:io.file "hello %s" name) - (let file[]:char (io.fread file:io.file)) - (let line[]:char (io.freadline file:io.file lineno:i32)) - 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 +#include + +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 new file mode 100755 index 0000000..dddf2a0 Binary files /dev/null and b/comp/lucas-standen-NEA/code/ads/dict/dicttest differ 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 + +#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 +#include +#include + +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 +#include + +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 new file mode 100755 index 0000000..14653f6 Binary files /dev/null and b/comp/lucas-standen-NEA/code/ads/ll/lltest differ 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 + +#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 new file mode 100755 index 0000000..9d996a8 Binary files /dev/null and b/comp/lucas-standen-NEA/code/parser/parser differ 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 +#include +#include + +#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 +#include + +#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 +#include +#include + +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 +#include +#include +#include + +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!") diff --git a/comp/lucas-standen-NEA/overview b/comp/lucas-standen-NEA/overview new file mode 100644 index 0000000..5f7904e --- /dev/null +++ b/comp/lucas-standen-NEA/overview @@ -0,0 +1,302 @@ +CS course work project + +zippy - a high level functional programing language + +zippy will be an interpreted language designed to replace C in higher level use +C is used largely to write most of the unix desktop, however c can be difficult +when writing larger programs, and is missing moddern features like oop or +functional patterns (higher order functions) + +requirents: + - must be human readable, even a non programmer should be able to figure + out what a program is doing + - faster than competion, other languages that have tried to slot into + this position like python are far to slow, and thus it must be faster + - low runtime overhead, the interpreter should be small, it shouldn't + force the developer to think about how the interpreter works to use it + efficently + - have moddern tools, a pkg manager and enviroment manager, making it + easy to develop for + - needs to support c libarys + +language info + +zippy will use function programming as a primary solution, however also support +simple oop, with classes (no inheritence) +its syntax will be comparable to lisp, with prolific use of "()" +it will need a stdlib, which can be taken from C's stdlib + +types: + + char - just like a c char + i32 - 32 bit signed int + f32 - 32 bit signed float + u32 - unsigned 32 bit int + i16- 16 bit signed int + u16 - 16 bit unsigned int + bool - TRUE/FALSE + + + arrays: + + arrays can be created like so + (let arr[]:char "hello there") + (let arr[]:i32 1 2 3) + + all arrays are linked lists of there data type + their size is not fixed + + you can get, or set the value of an array at a specific index using + arr[index] + + strings: + + strings are arrays of chars + a string can be defined by a litteral like so + "hello world" - this is the same as 'h' 'e' 'l'.... + because this is represented as a linked list there is no need to have a + NULL terminator like in c, the end of the string is jus the point where the + linked list has no more nodes + +comments: + + comments can be writen like so + ! this is a comment + +indentation and spacing: + + indentation and new lines arent at all necesary + any new lines will be converted to spaces, and tabs will be removed + the only place that needs spaces is when calling a function and giving its args + +scopes: + + () can be placed anywhere, and anything that is in them is in there own scope + as soon as the bracket is closed, any variables defined in the scope + will be deleted + any scope inherets all variables and functions from the scope that contains it + code writen in the main body of the file can be imagined like so + ( + ... + ... + ... + your code + ... + ... + ... + ) + however that level of indentation is not needed + + this can be helpful if you want to have two scopes with different imports + ( + (import z) + ( + (import x) + ! anything writen here has access to libary x and z + ) + ( + (import y) + ! anything writen here has access to libary y and z + ) + ! anything writen here has access to libary z + ) + +libarys: + + libarys are similar to header files in c + when imported the user can use any function contained within the file + + it would be good practice to put your libary in a struct to avoid functions with the + same names coming from 2 libarys, however its not needed + +errors: + + errors would be + +keywords: + + (defun arg1:type arg2:type returnType + ... + ... + ... + ) + defines a function, can be done anywhere in the program, all functions + must return a value, return type and arguments must be known at runtime + + returns the function that can be asigned with let + + (return VALUE) + returns VALUE from a function, VALUE must be of the same tupe as returnType + in defun + + (for x a b function) + + runs the function inside the loop, x will be increment by 1 each iteration and + it will have a starting value of a running until it reaches b (inclusive) + x cant be changed in any way other than the for loop + x, a, b are all of type i32 + + (while condtion function) + + runs all code inside the loop until the condion is not TRUE + condition must be a bool (TRUE/FALSE) + + (let name:type value) + + assign value to variable name, this will create the variable if it doesn't already + exist, and overwrite it if it does + names type must be defined by type + + (const name:type value) + + same as let but creates an imutable variable + + (import libary) + + searches the libary dir and imports the libary to the current project + libary can also be a specific path if it starts with / or ./ or ../ + + (struct name + ... + ... + ... + (defun init arg1:type type + ... + ... + ... + ) + (defun deinit arg1:type type + ... + ... + ... + ) + ) + + structs can be used as a custom data type + creates a struct/class called name, functions called init will be ran when an + object is created + when deinit is called the code init will be ran, then the object will be deleted + if deinit is not defined it can still be called to delete the instace of the class + + you can create a struct like so: + (let mystruct:name (name.init arg1 arg2)) + + you can call a method attached to an instace of a struct like this: + (mystruct.method arg1 arg2) + + and to destroy it you can just use this: + (mystruct.deinit arg1 arg2) + + structs can be recursive + eg: + (struct node + (defun init next:node + (let next:node next) + ) + ) + + a struct can have default values + eg: + (struct person + (let age:i32 50) + (let name[]:char "john doe") + ... + ... + ... + ) + + this will make the struct have default values + + overall in simple terms structs are just like c structs but they can contain + functions + + (symbol arg1:type arg2:type returntype location) + + returns a function that can be called. the function is retrieved from a .o file + which can be writen in C, the args, should be the args that the function takes in + and there types + the interpreter will try to convert data to the equal type in C, however this may need + to be done manually + the location should be a string which is is the file path to the .o file + + (if condition + ... + ... + ... + )(elif condition + ... + ... + ... + )(else + ... + ... + ... + ) + + simple if statment, if condition is TRUE run the code inside, elif runs if the condition in it + is TRUE and if the previous has not been TRUE + else will run if nothing else is TRUE + + (cast TYPE variable) + + returns a variable casted to type TYPE, if type is function, will return a function with no args + that returns the variable value in its starting type + + conditions: + (= a b) returns TRUE if a is equal to be (works with arrays) + (!= a b) returns TRUE if a is not equal to be (works with arrays) + (> a b) returns TRUE if a > b (does not work with arrays) + (< a b) returns TRUE if a < b (does not work with arrays) + (>= a b) returns TRUE if a >= b (does not work with arrays) + (<= a b) returns TRUE if a <= b (does not work with arrays) + (! a) returns TRUE if a is FALSE (only works on bools) + (| a b) returns TRUE if a or b are TRUE (only works on bools) + (& a b) returns TRUE if a and b are TRUE (only works on bools) + (^ a b) returns TRUE if a xor b is true (only works on bools) + + all these are just functions that can be used to assign values + eg: + (let mybool:bool (= a b)) + ! mybool will be TRUE if a = b + + mathmatical operations: + zippy uses reverse polish notation + (+ a b) returns a + b + (- a b) returns a - b + (* a b) returns a * b + (/ a b) returns a / b, whole number eg: (/ 7 3) = 2 + (/. a b) returns a / b, floating point number eg: (/. 7 3) = 2.5 + (% a b) returns the remander of (/ a b) + (** a b) returns a ^ b + + +sample code + (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)) + ! returns the 5th fib number + +stdlib: + (import io) + io contains a few types + they are: + (io.file) + io contains many io related functions + they are: + + (io.write "hello %s\n" name) ! this is very similar to printf in C + (let input:char[] (io.read)) + + (let file:io.file (io.open path[]:char "method")) + + (io.fwrite file:io.file "hello %s" name) + (let file[]:char (io.fread file:io.file)) + (let line[]:char (io.freadline file:io.file lineno:i32)) + diff --git a/comp/lucas-standen-NEA/writeup/coverpage.html b/comp/lucas-standen-NEA/writeup/coverpage.html new file mode 100644 index 0000000..a8338b4 --- /dev/null +++ b/comp/lucas-standen-NEA/writeup/coverpage.html @@ -0,0 +1,131 @@ + + + + + + + + + +NEA coverpage + + + + +

NEA coverpage

+ +1. Analysis
+1.1. Overview
+1.2. Examples of similar projects
+1.2.1. Python
+1.2.2. Lisp
+1.2.3. Perl
+2. Design
+3. Technical Solution
+4. Testing
+5. Evaluation
+ +
+ + +

Lucas standen
+7949

+ + +

ABSTRACT

+ +

1. Analysis + +

+ + +

1.1. Overview + +

+ + +

Zippy LANG

+ +

A next generation language, for +general use. Designed for keeping code simple, neet and +readable.
+Zippy will be a modern functional language. It will be +interpreted like python/perl and lisp. Its syntax should be +similar to lisp.

+ +

Some interesting features that +Zippy will have is treating everthing in functions, scopes +that allow for manual but safe memory management, and +interoperablity with C
+libarys

+ +

1.2. Examples of similar projects + +

+ + +

1.2.1. Python + +

+ + +

Python is a high level OOP +language that was designed in 1991. It was made to make +programming easy whie still being able to use some of +C’s functions.
+Although it has become standard for many usecases, it is +slow and inefficent, and very bloated.

+ +

1.2.2. Lisp + +

+ + +

Lisp is the second ever +programming language, developed at MiT, it is the first +functional language, creating many common features like +higher order functions,
+recursion, and garbage collection. It is generally not used +anymore as it feels old compared to other functional +languages, like ocaml or haskell.

+ +

1.2.3. Perl + +

+ + +

Perl is scripting lang designed +for use in linux, when bash is too slow, or not suited for +the job.
+Perl is often described as the glue of the universe (see +xkcd https://3d.xkcd.com/224/). Its syntax is quite strange +however and it is slow. Making it poorly suited for general +use.

+ +

2. Design + +

+ + +

3. Technical Solution + +

+ + +

4. Testing + +

+ + +

5. Evaluation + +

+
+ + diff --git a/comp/lucas-standen-NEA/writeup/coverpage.ms b/comp/lucas-standen-NEA/writeup/coverpage.ms new file mode 100644 index 0000000..d6ab182 --- /dev/null +++ b/comp/lucas-standen-NEA/writeup/coverpage.ms @@ -0,0 +1,46 @@ +.TL +NEA coverpage +.AU +Lucas standen +.AI +7949 +.AB +.NH 1 +Analysis +.NH 2 +Overview +.PP +.B Zippy +.B LANG +.PP +A next generation language, for general use. Designed for keeping code simple, neet and readable. + Zippy will be a modern functional language. It will be interpreted like python/perl and lisp. Its syntax should be similar to lisp. +.PP +Some interesting features that Zippy will have is treating everthing in functions, scopes that allow for manual but safe memory management, and interoperablity with C + libarys +.NH 2 +Examples of similar projects +.NH 3 +Python +.PP +Python is a high level OOP language that was designed in 1991. It was made to make programming easy whie still being able to use some of C's functions. + Although it has become standard for many usecases, it is slow and inefficent, and very bloated. +.NH 3 +Lisp +.PP +Lisp is the second ever programming language, developed at MiT, it is the first functional language, creating many common features like higher order functions, + recursion, and garbage collection. It is generally not used anymore as it feels old compared to other functional languages, like ocaml or haskell. +.NH 3 +Perl +.PP +Perl is scripting lang designed for use in linux, when bash is too slow, or not suited for the job. + Perl is often described as the glue of the universe (see xkcd https://3d.xkcd.com/224/). Its syntax is quite strange however and it is slow. Making it poorly suited for general use. +.NH 1 +Design +.NH 1 +Technical Solution +.NH 1 +Testing +.NH 1 +Evaluation +.AE diff --git a/comp/lucas-standen-NEA/writeup/coverpage.pdf b/comp/lucas-standen-NEA/writeup/coverpage.pdf new file mode 100644 index 0000000..92abc11 Binary files /dev/null and b/comp/lucas-standen-NEA/writeup/coverpage.pdf differ diff --git a/comp/lucas-standen-NEA/writeup/make.sh b/comp/lucas-standen-NEA/writeup/make.sh new file mode 100755 index 0000000..6f7c53e --- /dev/null +++ b/comp/lucas-standen-NEA/writeup/make.sh @@ -0,0 +1,2 @@ +#!/bin/bash +for i in $(ls | grep .ms); do groff -ms $i -T html > $(echo $i | cut -f1 -d".").html; done diff --git a/comp/work/31/__pycache__/bubble.cpython-312.pyc b/comp/work/31/__pycache__/bubble.cpython-312.pyc new file mode 100644 index 0000000..a91900d Binary files /dev/null and b/comp/work/31/__pycache__/bubble.cpython-312.pyc differ diff --git a/comp/work/31/__pycache__/merge.cpython-312.pyc b/comp/work/31/__pycache__/merge.cpython-312.pyc new file mode 100644 index 0000000..f390001 Binary files /dev/null and b/comp/work/31/__pycache__/merge.cpython-312.pyc differ diff --git a/comp/work/31/bubble.py b/comp/work/31/bubble.py new file mode 100644 index 0000000..c45f903 --- /dev/null +++ b/comp/work/31/bubble.py @@ -0,0 +1,22 @@ +import sys + + +def sort(list): + length = len(list) + for i in range(length - 1): + for j in range(length - i - 1): + if list[j] > list[j+1]: + tmp = list[j] + list[j] = list[j+1] + list[j+1] = tmp + return list + + +if __name__ == "__main__": + count = int(sys.argv[1]) + + num = [] + for i in range(count): + num.append(int(input(f"number {i}: "))) + + print(sort(num)) diff --git a/comp/work/31/menu.py b/comp/work/31/menu.py new file mode 100644 index 0000000..8f3c009 --- /dev/null +++ b/comp/work/31/menu.py @@ -0,0 +1,20 @@ +import merge +import bubble + + +while True: + list = [] + inp = "" + print("enter nums, then enter END") + while inp != "END": + inp = input("number: ") + if inp != "END": + list.append(inp) + + sort = int(input("1) bubble, 2) merge: ")) + + if sort == 1: + print(*merge.sort(list), sep=", ") + + else: + print(*bubble.sort(list), sep=", ") diff --git a/comp/work/31/merge.py b/comp/work/31/merge.py new file mode 100644 index 0000000..0947aa4 --- /dev/null +++ b/comp/work/31/merge.py @@ -0,0 +1,39 @@ +def sort(list): + length = len(list) + l1 = [] + l2 = [] + for i in range(length): + if i >= (length / 2): + l2.append(list[i]) + else: + l1.append(list[i]) + if length > 2: + l1 = sort(l1) + l2 = sort(l2) + return merge(l1, l2) + + +def merge(l1, l2): + i = 0 + j = 0 + output = [] + while i < len(l1) and j < len(l2): + if l1[i] < l2[j]: + output.append(l1[i]) + i += 1 + else: + output.append(l2[j]) + j += 1 + + while i < len(l1): + output.append(l1[i]) + i += 1 + while j < len(l2): + output.append(l2[j]) + j += 1 + return output + + +if __name__ == "__main__": + # call split on the list, will return a sorted one + print(sort([1, 4, 2, 4, 2, 5, 6, 2, 7])) -- cgit v1.2.3