aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 3454587..83477d8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -254,6 +254,7 @@ ParseRule parse_rules[] = {
254 // Literals. 254 // Literals.
255 [TOK_STRING] = {parse_string, NULL, PREC_NONE}, 255 [TOK_STRING] = {parse_string, NULL, PREC_NONE},
256 [TOK_SYMBOL] = {parse_symbol, NULL, PREC_NONE}, 256 [TOK_SYMBOL] = {parse_symbol, NULL, PREC_NONE},
257 [TOK_CHAR] = {parse_number, NULL, PREC_NONE},
257 [TOK_NUM_INT] = {parse_number, NULL, PREC_NONE}, 258 [TOK_NUM_INT] = {parse_number, NULL, PREC_NONE},
258 [TOK_NUM_FLOAT] = {parse_number, NULL, PREC_NONE}, 259 [TOK_NUM_FLOAT] = {parse_number, NULL, PREC_NONE},
259 [TOK_TRUE] = {parse_literal, NULL, PREC_NONE}, 260 [TOK_TRUE] = {parse_literal, NULL, PREC_NONE},
@@ -602,6 +603,11 @@ parse_number(Parser *parser) {
602 if (!node) return; 603 if (!node) return;
603 node->value.d = str_to_float(prev.val); 604 node->value.d = str_to_float(prev.val);
604 } break; 605 } break;
606 case TOK_CHAR: {
607 node = node_alloc(parser, NODE_NUM_INT, prev);
608 if (!node) return;
609 node->value.i = prev.val.mem[1];
610 } break;
605 default: break; 611 default: break;
606 } 612 }
607 array_push(parser->nodes, node, parser->storage); 613 array_push(parser->nodes, node, parser->storage);
@@ -700,10 +706,10 @@ graph_node(Node *node) {
700 case NODE_NUM_UINT: print("| Value: %x", node->value.u); break; 706 case NODE_NUM_UINT: print("| Value: %x", node->value.u); break;
701 case NODE_NUM_FLOAT: print("| Value: %f{2}", node->value.d); break; 707 case NODE_NUM_FLOAT: print("| Value: %f{2}", node->value.d); break;
702 case NODE_STRING: print("| Value: %s", node->value.str); break; 708 case NODE_STRING: print("| Value: %s", node->value.str); break;
703 case NODE_SYMBOL_IDX: 709 case NODE_SYMBOL_IDX:
704 case NODE_STRUCT: 710 case NODE_STRUCT:
705 case NODE_STRUCT_LIT: print("| Name: %s", node->value.sym); break; 711 case NODE_STRUCT_LIT: print("| Name: %s", node->value.sym); break;
706 case NODE_SYMBOL: 712 case NODE_SYMBOL:
707 case NODE_TYPE: { 713 case NODE_TYPE: {
708 if (node->is_ptr) { 714 if (node->is_ptr) {
709 print("| Name: @%s", node->value.sym); 715 print("| Name: @%s", node->value.sym);
@@ -803,11 +809,14 @@ process_file(Str path) {
803 } 809 }
804 array_push(tokens, tok, &lexer_arena); 810 array_push(tokens, tok, &lexer_arena);
805 } 811 }
806
807 // Only proceed if there are no errors. 812 // Only proceed if there are no errors.
808 if (errors) { 813 if (errors) {
809 goto stop; 814 goto stop;
810 } 815 }
816 if (mode == PRINT_LEX) {
817 print_tokens(path, tokens);
818 goto stop;
819 }
811 820
812 // Parser. 821 // Parser.
813 Parser parser = { 822 Parser parser = {
@@ -841,7 +850,6 @@ process_file(Str path) {
841 (void)root; 850 (void)root;
842 } 851 }
843 parse_consume(&parser, TOK_EOF, cstr("expected end of file")); 852 parse_consume(&parser, TOK_EOF, cstr("expected end of file"));
844 // print_tokens(path, tokens); // DEBUG
845 853
846stop: 854stop:
847 // Free up resources. 855 // Free up resources.