diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2023-06-13 04:10:21 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2023-06-13 04:10:21 -0700 |
| commit | f32a19fee2a3016b6393272dc2c054ff02e63b7f (patch) | |
| tree | 57569371835e6ecf2c0e110da2405484b1e27ec3 /parse.c | |
| parent | 2f7ac38cca2ebab41b8adb76b69e0949eeae488d (diff) | |
added scoping; probably doesn't work
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 36 |
1 files changed, 33 insertions, 3 deletions
@@ -4,9 +4,19 @@ #include "lexer.h" #include "stdio.h" -line_t init_line(int aLevel, prop_t proposition, just_t justification) { +scope_t lastScope; +int scopes; + +scope_t init_scope(int id, int depth, scope_t* parent) { + scope_t scope; + scope.id = id; + scope.depth = depth; + scope.parent = parent; + return scope; +} +line_t init_line(scope_t scope, prop_t proposition, just_t justification) { line_t line; - line.aLevel = aLevel; + line.scope = scope; line.proposition = proposition; line.justification = justification; return line; @@ -50,11 +60,31 @@ line_t parse_line(char* content) { } c++; } + /* determine the ID of the scope we are working on */ + scope_t thisScope; + if (indent > lastScope.depth) { + scopes++; + scope_t* lsp = malloc(sizeof(scope_t)); + *lsp = lastScope; + thisScope = init_scope(scopes, indent, lsp); + } + else if (indent < lastScope.depth) { + scope_t li = lastScope; + for (int i = 0; i < lastScope.depth - indent; i++) { + li = *li.parent; + } + thisScope = li; + } + else { + thisScope = lastScope; + } + lastScope = thisScope; + /* find the proposition and justification */ int* seek = calloc(sizeof(int), 1); prop_t prop = parse_proposition(init_tokenset(ts.tokens + indent, c - indent), seek, 0); just_t just = parse_justification(init_tokenset(ts.tokens + c + 1, ts.count - (c + 1))); free(seek); - return init_line(indent, prop, just); + return init_line(thisScope, prop, just); } prop_t parse_proposition(tokenSet_t tokenSet, int* seek, char isNegative) { prop_t prop; |
