From d063e3c2c6f4b1566c28d0ea92186f356017f99f Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 11 Jun 2023 16:18:21 -0700 Subject: parsing propositions works now. added some debugging tools --- lexer.c | 58 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'lexer.c') 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; -- cgit v1.3.1