From 3bd120957d570756d396db8a112113f2ffb8f33b Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Tue, 13 Jun 2023 00:56:14 -0700 Subject: added negation --- parse.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index d26cfe8..6bea4af 100644 --- a/parse.c +++ b/parse.c @@ -44,19 +44,23 @@ line_t parse_line(char* content) { i++; } int* seek = calloc(sizeof(int), 1); - prop_t prop = parse_proposition(init_tokenset(ts.tokens, i), seek); + prop_t prop = parse_proposition(init_tokenset(ts.tokens, i), seek, 0); just_t just = parse_justification(init_tokenset(ts.tokens + i + 1, ts.count - (i + 1))); return init_line(prop, just); } -prop_t parse_proposition(tokenSet_t tokenSet, int* seek) { +prop_t parse_proposition(tokenSet_t tokenSet, int* seek, char isNegative) { prop_t prop; /* recurse to parse the parenthetical as its own proposition */ if (tokenSet.tokens[*seek].type == OPEN_PAREN) { (*seek)++; - prop = parse_proposition(tokenSet, seek); + prop = parse_proposition(tokenSet, seek, 0); + } + else if (tokenSet.tokens[*seek].type == NEGATION) { + (*seek)++; + prop = parse_proposition(tokenSet, seek, 1); } else { - prop = init_simple_prop(tokenSet.tokens[*seek].value); + prop = init_simple_prop(isNegative, tokenSet.tokens[*seek].value); (*seek)++; } /* check if we were reading a simple prop, or if there is a relation */ @@ -70,8 +74,8 @@ prop_t parse_proposition(tokenSet_t tokenSet, int* seek) { prop_t* prop1p = malloc(sizeof(prop_t)); *prop1p = prop; prop_t* prop2p = malloc(sizeof(prop_t)); - *prop2p = parse_proposition(tokenSet, seek); - prop_t metaProp = init_prop(prop1p, prop2p, rel); + *prop2p = parse_proposition(tokenSet, seek, 0); + prop_t metaProp = init_prop(0, prop1p, prop2p, rel); return metaProp; } } -- cgit v1.3.1