summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-01-14 11:52:26 -0500
committerpommicket <pommicket@gmail.com>2022-01-14 11:52:26 -0500
commitdf8c5700d68cdae7fe674fb63a0b3aab5ced70a8 (patch)
tree09349cb44b6cd9eef1974c73975b3b4bc1a4f082
parent39b51014901ce769f2df4d66b5d13652a3daba89 (diff)
fix unary ops
-rw-r--r--05/main.c2
-rw-r--r--05/parse.b34
2 files changed, 30 insertions, 6 deletions
diff --git a/05/main.c b/05/main.c
index 523c8b1..5406e3f 100644
--- a/05/main.c
+++ b/05/main.c
@@ -1 +1 @@
-5 + *7
+5+*7**8--
diff --git a/05/parse.b b/05/parse.b
index 69978cc..76f82a4 100644
--- a/05/parse.b
+++ b/05/parse.b
@@ -67,7 +67,8 @@ function parse_expression
if c == SYMBOL_RSQUARE goto expr_findop_decdepth
if depth > 0 goto expr_find_operator_loop
if depth < 0 goto expr_too_many_closing_brackets
- a = operator_precedence(c, b)
+ n = p - 16
+ a = operator_precedence(n, b)
n = a
n -= operator_right_associative(c) ; ensure that the leftmost += / -= / etc. is processed first
if n > best_precedence goto expr_find_operator_loop
@@ -240,11 +241,23 @@ function parse_expression
:return_type_double
return TYPE_DOUBLE
-; return precedence of given operator, or 0xffff if not an operator
+; return precedence of given operator token, or 0xffff if not an operator
function operator_precedence
- argument op
- argument is_unary_prefix
- if is_unary_prefix != 0 goto operator_precedence_unary
+ argument token
+ argument is_first
+ local op
+
+ if is_first != 0 goto operator_precedence_unary
+
+ ; if an operator is preceded by another, it must be a unary operator, e.g.
+ ; in 5 + *x, * is a unary operator
+ op = token - 16
+ op = *1op
+ op = is_operator(op)
+ if op != 0 goto operator_precedence_unary
+
+ op = *1token
+
; see "C OPERATOR PRECEDENCE" in constants.b
if op == SYMBOL_COMMA goto return_0x10
@@ -288,6 +301,8 @@ function operator_precedence
return 0xffff
:operator_precedence_unary
+ op = *1token
+
if op == KEYWORD_SIZEOF goto return_0xe0
if op == SYMBOL_PLUS_PLUS goto return_0xe0
if op == SYMBOL_MINUS_MINUS goto return_0xe0
@@ -421,6 +436,15 @@ function binop_symbol_to_expression_type
p += 1
return *1p
+function is_operator
+ argument symbol
+ local b
+ b = binop_symbol_to_expression_type(symbol)
+ if b != 0 goto return_1
+ b = unary_op_to_expression_type(symbol)
+ if b != 0 goto return_1
+ goto return_0
+
function binop_expression_type_to_symbol
argument exprtype
local p