diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2023-06-13 14:50:00 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2023-06-13 14:50:00 -0700 |
| commit | 1d3bbec4660dfe4e2117826ceef9b32758b40345 (patch) | |
| tree | 7c33cdf17774a122af89f3ae7743771f047942a7 /src/operetta.c | |
| parent | caa9d17ea794a0b4823170551545498d458e1fc2 (diff) | |
restructured project
Diffstat (limited to 'src/operetta.c')
| -rw-r--r-- | src/operetta.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/operetta.c b/src/operetta.c new file mode 100644 index 0000000..f754895 --- /dev/null +++ b/src/operetta.c @@ -0,0 +1,64 @@ +#include <stdlib.h> +#include <stdio.h> +#include "operetta.h" +#include "lexer.h" +#include "parse.h" +#include "proposition.h" +#include "eval.h" + +int main(int argc, char** argv) { + /* read file */ + char* path = argv[1]; + char* content = read_file(path); + int lineCount = count_lines(content); + lineSet_t lines = parse_lines(content, lineCount); + for (int i = 0; i < lines.count; i++) { + line_t line = lines.lines[i]; + printf("%d. ", i + 1); + for (int j = 0; j < line.scope.depth; j++) { + printf(" > "); + } + write_prop(line.proposition); + printf(" BECAUSE: "); + write_just(line.justification); + printf(just_is_sound(line, lines) ? " <SOUND>" : " <UNSOUND>"); + printf(" [%d]", line.scope.id); + printf("\n"); + } + free(content); +} +void write_prop(prop_t prop) { + if (prop.isNegative) { + printf("%s", "!"); + } + if (prop.isSimple) { + printf("%s", prop.name); + } + else { + printf("("); + write_prop(*(prop.propA)); + printf(" %s ", tttos(prop.relation)); + write_prop(*(prop.propB)); + printf(")"); + } +} +void write_just(just_t just) { + printf("%s", jrtos(just.rule)); + for (int i = 0; i < just.referencesCount; i++) { + printf(" %d", just.references[i]); + } +} +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; +} |
