Author | Jakob Wakeling <[email protected]> |
Date | 2022-04-11 08:53:32 |
Commit | 8dbbe4a51fe9415c9224e43c1688141bbfdaad95 |
Parent | fa7200b9385feb91e66087aa94a8df1d0fe8322b |
Handle parenthesis when parsing expressions
Diffstat
M | src/parse.c | | | 13 | +++++++++++++ |
M | src/symbol.c | | | 4 | ++++ |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/parse.c b/src/parse.c index 90990cf..6ca074e 100644 --- a/src/parse.c +++ b/src/parse.c @@ -227,8 +227,19 @@ static ast *parse_expr(lex *l, syt *st) { } break; case TK_INT: { ast_a_push(&as, parse_int(l, st)); } break; case TK_LPAREN: { tok_a_push(&ts, lex_next(l)); } break; - case TK_RPAREN: { /* TODO */ error(1, "RPAREN: TODO"); } break; - default: { + case TK_RPAREN: { + for (tok t = tok_a_pop(&ts);; t = tok_a_pop(&ts)) { + if (t.k == TK_NULL) { error(1, "todo: error: expected left parenthesis"); } + if (t.k == TK_LPAREN) { break; } + + shunt(&as, t, ops_lookup(t.k)); + } + + /* TODO handle procedure calls */ + + lex_next(l); + } break; + default: /* Handle operators */ { op o1; if ((o1 = ops_lookup(T.k)).tk == TK_NULL) { goto eox; } for (op o2 = ops_lookup(tok_a_peek(&ts).k);; o2 = ops_lookup(tok_a_peek(&ts).k)) { diff --git a/src/symbol.c b/src/symbol.c index e4ff063..f90c977 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -160,7 +160,10 @@ sym syt_search_h(syt *st, u64 h, char *k) { /* Print a basic representation of a map to stdout. */ void syt_print(syt *st) { for (UINT i = 0; i < st->ac; i += 1) if (st->a[i].h != 0) { - printf("%s -> %s\n", st->a[i].k, st->a[i].v.a->c.a[0]->t->s); + if (st->a[i].v.a->c.a[0]->t) { + printf("%s -> %s\n", st->a[i].k, st->a[i].v.a->c.a[0]->t->s); + } + else { printf("%s -> unknown type\n", st->a[i].k); } } }