summaryrefslogtreecommitdiff
path: root/operetta.c
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-06-10 23:45:25 -0700
committerKai Stevenson <kai@kaistevenson.com>2023-06-10 23:45:25 -0700
commit2a232f8f42c0a7d5a7b648358a192c21865a55f6 (patch)
tree81e5e768f75c5bd6da27235c723666f4cc4c2b1a /operetta.c
lexing works
Diffstat (limited to 'operetta.c')
-rw-r--r--operetta.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/operetta.c b/operetta.c
new file mode 100644
index 0000000..5d71c0b
--- /dev/null
+++ b/operetta.c
@@ -0,0 +1,37 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "operetta.h"
+#include "lexer.h"
+#include "parse.h"
+#include "proposition.h"
+
+int main(int argc, char** argv) {
+ /* read file */
+ char* path = argv[1];
+ char* content = read_file(path);
+ linkList_t* ll = lex_line(content);
+ linkList_t* l1 = ll;
+ while (1) {
+ token_t* t = (token_t*)l1->value;
+ printf("%d \n", t->type);
+ if (l1->next == NULL) {
+ break;
+ }
+ l1 = l1->next;
+ }
+ free(content);
+}
+char* read_file(char* path) {
+ FILE* file = fopen(path, "r");
+ if (file == NULL) {
+ printf("file %s does not exist\n", path);
+ }
+ fseek(file, 0, SEEK_END);
+ unsigned long int length = ftell(file);
+ fseek(file, 0, SEEK_SET);
+ char* out = malloc((length + 1) * sizeof(char));
+ fread(out, length, 1, file);
+ fclose(file);
+ out[length] = '\0';
+ return out;
+}