diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-18 19:54:56 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-18 19:54:56 +0200 |
commit | 3d88e46dd0d1b54bc0a414b5db42ed76ddc08363 (patch) | |
tree | 5eed2d95bdc017ef28d603ff1f49b96640929013 /src | |
parent | f9d0fe5ad641e453724dabc2b17634a44e198ce0 (diff) | |
download | bdl-3d88e46dd0d1b54bc0a414b5db42ed76ddc08363.tar.gz bdl-3d88e46dd0d1b54bc0a414b5db42ed76ddc08363.zip |
Add `cond` conditionals
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -641,6 +641,28 @@ parse_keyword(Parser *parser) { | |||
641 | array_push(node->struct_field, field, parser->storage); | 641 | array_push(node->struct_field, field, parser->storage); |
642 | } | 642 | } |
643 | } break; | 643 | } break; |
644 | case TOK_COND: { | ||
645 | node = node_alloc(parser, NODE_COND, prev); | ||
646 | if (!node) return; | ||
647 | parse_consume(parser, TOK_LCURLY, | ||
648 | cstr("expected '{' on cond expression")); | ||
649 | while (!parse_match(parser, TOK_RCURLY) && !parser->panic) { | ||
650 | Node *tmp = node_alloc(parser, NODE_CASE, parser->previous); | ||
651 | if (!tmp) return; | ||
652 | // Are we on the default case. | ||
653 | if (!parse_match(parser, TOK_ELSE)) { | ||
654 | parse_consume(parser, TOK_CASE, | ||
655 | cstr("expected case statement")); | ||
656 | parse_expr(parser, PREC_LOW); | ||
657 | tmp->case_value = array_pop(parser->nodes); | ||
658 | } | ||
659 | parse_consume(parser, TOK_ASSIGN, | ||
660 | cstr("malformed case statement")); | ||
661 | parse_expr(parser, PREC_LOW); | ||
662 | tmp->case_expr = array_pop(parser->nodes); | ||
663 | array_push(node->match_cases, tmp, parser->storage); | ||
664 | } | ||
665 | } break; | ||
644 | default: return; // Unreachable. | 666 | default: return; // Unreachable. |
645 | } | 667 | } |
646 | array_push(parser->nodes, node, parser->storage); | 668 | array_push(parser->nodes, node, parser->storage); |
@@ -847,6 +869,7 @@ graph_node(Node *node) { | |||
847 | println("\"];"); | 869 | println("\"];"); |
848 | 870 | ||
849 | switch (node->kind) { | 871 | switch (node->kind) { |
872 | case NODE_COND: | ||
850 | case NODE_MATCH: { | 873 | case NODE_MATCH: { |
851 | if (node->match_expr) { | 874 | if (node->match_expr) { |
852 | println("%d:e->%d:w;", node->id, node->match_expr->id); | 875 | println("%d:e->%d:w;", node->id, node->match_expr->id); |