summaryrefslogtreecommitdiff
path: root/lexer.c
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-06-11 16:18:21 -0700
committerKai Stevenson <kai@kaistevenson.com>2023-06-11 16:18:21 -0700
commitd063e3c2c6f4b1566c28d0ea92186f356017f99f (patch)
treeaf7b093f016d16a4902a9094d120f1a33bee64b6 /lexer.c
parent2a232f8f42c0a7d5a7b648358a192c21865a55f6 (diff)
parsing propositions works now. added some debugging tools
Diffstat (limited to 'lexer.c')
-rw-r--r--lexer.c58
1 files changed, 42 insertions, 16 deletions
diff --git a/lexer.c b/lexer.c
index bff9a40..5fe9e22 100644
--- a/lexer.c
+++ b/lexer.c
@@ -9,11 +9,41 @@ token_t init_token(tokenType_t type, void* value) {
t.value = value;
return t;
}
-linkList_t* init_linklist(void* value, linkList_t* next) {
- linkList_t* ll = calloc(sizeof(linkList_t), 1);
- ll->value = value;
- ll->next = next;
- return ll;
+tokenSet_t init_tokenset(token_t* tokens, int count) {
+ tokenSet_t tokenSet;
+ tokenSet.tokens = tokens;
+ tokenSet.count = count;
+ return tokenSet;
+}
+char* tttos(tokenType_t tokenType) {
+ switch (tokenType) {
+ case ERR:
+ return "ERR";
+ case EOL:
+ return "EOL";
+ case STRING:
+ return "STRING";
+ case INT:
+ return "INT";
+ case OPEN_PAREN:
+ return "OPEN_PAREN";
+ case CLOSE_PAREN:
+ return "CLOSE_PAREN";
+ case START_COMMENT:
+ return "START_COMMENT";
+ case JUSTIFICATION:
+ return "JUSTIFICATION";
+ case PREMISE:
+ return "PREMISE";
+ case ASSUMPTION:
+ return "ASSUMPTION";
+ case CONJUNCTION:
+ return "CONJUNCTION";
+ case DISJUNCTION:
+ return "DISJUNCTION";
+ default:
+ return "???";
+ }
}
int advance_whitespace(char** linePointer) {
int64_t a = (int64_t)linePointer;
@@ -22,11 +52,12 @@ int advance_whitespace(char** linePointer) {
}
return (int)((int64_t)linePointer - a);
}
-linkList_t* lex_line(char* line) {
+tokenSet_t lex_line(char* line) {
char** p = malloc(sizeof(char*));
*p = line;
- linkList_t* root = init_linklist(NULL, NULL);
- linkList_t* ll = root;
+ int m = 50;
+ token_t* tokens = malloc(sizeof(token_t) * m);
+ int i = 0;
while (1) {
token_t t = lex_first_token(p);
if (t.type == EOL) {
@@ -36,17 +67,12 @@ linkList_t* lex_line(char* line) {
if (t.type == ERR) {
exit(1);
}
- if (ll->value != NULL) {
- ll->next = init_linklist(NULL, NULL);
- ll = ll->next;
- }
- token_t* tp = malloc(sizeof(token_t));
printf("good\n");
- *tp = t;
- ll->value = tp;
+ tokens[i] = t;
+ i++;
}
free(p);
- return root;
+ return init_tokenset(tokens, i);
}
token_t lex_first_token(char** content) {
int m = 5;