diff options
-rw-r--r-- | 05/main.b | 2 | ||||
-rw-r--r-- | 05/main.c | 2 | ||||
-rw-r--r-- | 05/parse.b | 17 | ||||
-rw-r--r-- | 05/tokenize.b | 2 |
4 files changed, 18 insertions, 5 deletions
@@ -167,7 +167,7 @@ function main tokens = malloc(16000000) p = tokenize(pptokens, tokens, input_filename, 1) - print_tokens(tokens) + print_tokens(tokens, p) ; NOTE: do NOT free pptokens as identifiers still reference them. ast = malloc(56000000) @@ -1 +1 @@ -"hi"[33] +"hi"[33] << 8 @@ -16,6 +16,8 @@ function parse_expression local value :parse_expression_top + ;print_tokens(tokens, tokens_end) + type = out + 4 if tokens == tokens_end goto empty_expression @@ -64,7 +66,7 @@ function parse_expression if p >= tokens_end goto expr_find_operator_loop_end c = *1p p += 16 - if depth > 0 goto expr_find_operator_loop + if depth > 0 goto expr_findop_not_new_best if depth < 0 goto expr_too_many_closing_brackets n = p - 16 a = operator_precedence(n, b) @@ -74,7 +76,6 @@ function parse_expression ; new best! best = p - 16 best_precedence = a - goto expr_find_operator_loop :expr_findop_not_new_best if c == SYMBOL_LPAREN goto expr_findop_incdepth if c == SYMBOL_RPAREN goto expr_findop_decdepth @@ -117,6 +118,12 @@ function parse_expression if c == SYMBOL_LSHIFT goto type_binary_left_promote if c == SYMBOL_RSHIFT goto type_binary_left_promote if c == SYMBOL_LSQUARE goto type_subscript + if c == SYMBOL_EQ_EQ goto type_binary_comparison + if c == SYMBOL_NOT_EQ goto type_binary_comparison + if c == SYMBOL_LT_EQ goto type_binary_comparison + if c == SYMBOL_GT_EQ goto type_binary_comparison + if c == SYMBOL_LT goto type_binary_comparison + if c == SYMBOL_GT goto type_binary_comparison if c < SYMBOL_EQ goto type_binary_usual if c > SYMBOL_OR_EQ goto type_binary_usual goto type_binary_left @@ -139,6 +146,9 @@ function parse_expression :type_binary_usual *4type = expr_binary_type_usual_conversions(tokens, *4a, *4b) return out + :type_binary_comparison + *4type = TYPE_INT + return out :type_binary_left *4type = *4a return out @@ -355,7 +365,8 @@ function expr_binary_type_usual_conversions function type_promotion argument type - if type < TYPE_INT goto return_type_int + type = types + type + if *1type < TYPE_INT goto return_type_int return type ; return precedence of given operator token, or 0xffff if not an operator diff --git a/05/tokenize.b b/05/tokenize.b index 2fc4bc1..7475def 100644 --- a/05/tokenize.b +++ b/05/tokenize.b @@ -588,10 +588,12 @@ function read_number_suffix function print_tokens argument tokens + argument tokens_end local p local s p = tokens :print_tokens_loop + if p ]= tokens_end goto print_tokens_loop_end if *1p == 0 goto print_tokens_loop_end if *1p > 20 goto print_token_keyword if *1p == TOKEN_CONSTANT_INT goto print_token_int |