From 7ef4ddf0f3e45445b701d0fd56627e20eb686238 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 14 Aug 2022 12:34:00 +0200 Subject: [PATCH] fixed operator precedence: bitwise must come before comparisons --- docs/source/todo.rst | 1 - examples/starfield.p8 | 2 +- examples/test.p8 | 19 +++++++++---------- parser/antlr/Prog8ANTLR.g4 | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 4eeb9dd8f..1559ea733 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- fix operator precedence: if rasterCount ^ $80 >= 230 EOR should precede >= - @(ptr) |= 3 -> asm peephole optimize remove the second ldy if the instruction before doesn't modify y ldy #0 lda (starfieldPtr2),y diff --git a/examples/starfield.p8 b/examples/starfield.p8 index cc4436148..2336f09d3 100644 --- a/examples/starfield.p8 +++ b/examples/starfield.p8 @@ -87,7 +87,7 @@ main { @(staticStar1) = 0 else @(staticStar1) = 192 - if (rasterCount ^ $80) >= 230 + if rasterCount ^ $80 >= 230 @(staticStar2) = 0 else @(staticStar2) = 192 diff --git a/examples/test.p8 b/examples/test.p8 index dfa3312aa..7774bc7ac 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,17 +5,16 @@ main { sub start() { - uword @zp flags_ptr = memory("flags", 200, 0) - txt.print("calculating...\n") - txt.print_uwhex(flags_ptr, true) - txt.nl() + ubyte rasterCount = 231 - repeat 10 { - txt.print("new iter\n") - txt.print_ub(@($06)) - sys.memset(flags_ptr, 200, 0) - } + if rasterCount >= 230 + txt.print("y1") + + if rasterCount ^ $80 >= 230 + txt.print("y2") + + if (rasterCount ^ $80) >= 230 + txt.print("y3") - txt.print("done\n") } } diff --git a/parser/antlr/Prog8ANTLR.g4 b/parser/antlr/Prog8ANTLR.g4 index 0fb196c32..8a858f599 100644 --- a/parser/antlr/Prog8ANTLR.g4 +++ b/parser/antlr/Prog8ANTLR.g4 @@ -161,10 +161,10 @@ expression : | left = expression EOL? bop = ('*' | '/' | '%' ) EOL? right = expression | left = expression EOL? bop = ('+' | '-' ) EOL? right = expression | left = expression EOL? bop = ('<<' | '>>' ) EOL? right = expression - | left = expression EOL? bop = ('<' | '>' | '<=' | '>=') EOL? right = expression | left = expression EOL? bop = '&' EOL? right = expression | left = expression EOL? bop = '^' EOL? right = expression | left = expression EOL? bop = '|' EOL? right = expression + | left = expression EOL? bop = ('<' | '>' | '<=' | '>=') EOL? right = expression | left = expression EOL? bop = ('==' | '!=') EOL? right = expression | rangefrom = expression rto = ('to'|'downto') rangeto = expression ('step' rangestep = expression)? // can't create separate rule due to mutual left-recursion | left = expression EOL? bop = 'in' EOL? right = expression