diff options
author | Marvin Borner | 2023-04-11 20:56:14 +0200 |
---|---|---|
committer | Marvin Borner | 2023-04-11 20:56:14 +0200 |
commit | 5c8f9487ec11035cbd1accfb67f1a4943a2b8db1 (patch) | |
tree | 8a294e7efe801986b6e7f9e19a5ed962aa816c4f /src/print.c | |
parent | 4b40b490d3948a2ccf736bcf94b95abf44955a38 (diff) |
Bootstrapping
Diffstat (limited to 'src/print.c')
-rw-r--r-- | src/print.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/print.c b/src/print.c new file mode 100644 index 0000000..425aedb --- /dev/null +++ b/src/print.c @@ -0,0 +1,54 @@ +// Copyright (c) 2023, Marvin Borner <dev@marvinborner.de> +// SPDX-License-Identifier: MIT + +#include <stdio.h> + +#include <print.h> + +void print_bruijn(struct term *term) +{ + switch (term->type) { + case ABS: + printf("["); + print_bruijn(term->u.abs.term); + printf("]"); + break; + case APP: + printf("("); + print_bruijn(term->u.app.lhs); + printf(" "); + print_bruijn(term->u.app.rhs); + printf(")"); + break; + case VAR: + printf("%d", term->u.var.index); + break; + case REF: + printf("<%ld>", term->u.ref.index); + break; + default: + fprintf(stderr, "Invalid type %d\n", term->type); + } +} + +void print_blc(struct term *term) +{ + switch (term->type) { + case ABS: + printf("00"); + print_blc(term->u.abs.term); + break; + case APP: + printf("01"); + print_blc(term->u.app.lhs); + print_blc(term->u.app.rhs); + break; + case VAR: + for (int i = 0; i <= term->u.var.index; i++) + printf("1"); + printf("0"); + break; + default: + fprintf(stderr, "Invalid type %d\n", term->type); + } +} |