summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-01-14 14:02:34 -0500
committerpommicket <pommicket@gmail.com>2022-01-14 14:02:34 -0500
commitb79c3e0f5a3dfbe9ef48e9cd242e5f1a9687bb8b (patch)
tree7ed293139eb265797545bc525379ffcdee650304
parente3547b76b13000542c7c7bf63d5e8d508e6b2002 (diff)
parsing fixes
-rw-r--r--05/main.b2
-rw-r--r--05/main.c2
-rw-r--r--05/parse.b17
-rw-r--r--05/tokenize.b2
4 files changed, 18 insertions, 5 deletions
diff --git a/05/main.b b/05/main.b
index 32c6144..a85818b 100644
--- a/05/main.b
+++ b/05/main.b
@@ -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)
diff --git a/05/main.c b/05/main.c
index f74e65b..99be5cd 100644
--- a/05/main.c
+++ b/05/main.c
@@ -1 +1 @@
-"hi"[33]
+"hi"[33] << 8
diff --git a/05/parse.b b/05/parse.b
index 0f128a4..49bbacb 100644
--- a/05/parse.b
+++ b/05/parse.b
@@ -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