diff options
author | Marvin Borner | 2023-05-30 13:10:00 +0200 |
---|---|---|
committer | Marvin Borner | 2023-05-30 13:10:00 +0200 |
commit | 75c40090e9302e11fc32863270360ef597a93933 (patch) | |
tree | d2ec6a5539c1f77852a5ae7bc452bf4eef35b5b1 /src/parse.c |
Initial bootstrapping
Diffstat (limited to 'src/parse.c')
-rw-r--r-- | src/parse.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/parse.c b/src/parse.c new file mode 100644 index 0000000..18dfffe --- /dev/null +++ b/src/parse.c @@ -0,0 +1,37 @@ +// Copyright (c) 2023, Marvin Borner <dev@marvinborner.de> +// SPDX-License-Identifier: MIT + +#include <stdlib.h> + +#include <parse.h> +#include <log.h> + +struct term *parse_blc(char **term) +{ + if (!**term) { + fatal("invalid parsing state!\n"); + } else if (**term == '0' && *(*term + 1) == '0') { + (*term) += 2; + struct term *new = term_new(ABS); + new->u.abs.term = parse_blc(term); + return new; + } else if (**term == '0' && *(*term + 1) == '1') { + (*term) += 2; + struct term *new = term_new(APP); + new->u.app.lhs = parse_blc(term); + new->u.app.rhs = parse_blc(term); + return new; + } else if (**term == '1') { + const char *cur = *term; + while (**term == '1') + (*term)++; + int index = *term - cur - 1; + (*term)++; + struct term *new = term_new(VAR); + new->u.var.index = index; + return new; + } else { + (*term)++; + return parse_blc(term); + } +} |