From 531dd2d1dc897cf88c83a155252bd4f83f83afe0 Mon Sep 17 00:00:00 2001 From: gpz Date: Tue, 3 Dec 2024 23:18:48 +0000 Subject: [PATCH] document the absence of operator precedence in the monitor parser, add some related comment(s) git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45388 379a1393-f5fb-40a0-bcee-ef074d9b53f7 --- vice/doc/vice.texi | 6 ++++- vice/src/monitor/mon_lex.l | 52 +++++++++++++++++++++++++----------- vice/src/monitor/mon_parse.y | 23 ++++++++++++++++ 3 files changed, 65 insertions(+), 16 deletions(-) diff --git a/vice/doc/vice.texi b/vice/doc/vice.texi index 0bc3e335ecf..d0cf9b82997 100644 --- a/vice/doc/vice.texi +++ b/vice/doc/vice.texi @@ -20718,7 +20718,11 @@ current rasterline, and CY refers to the current cycle in the line. Full expressions are also supported (+, -, *, /, &, |, &&, ||). This lets you for example check specific bits in the FL register using the bitwise -boolean operators (& and |). Parentheses are also supported in the expression. +boolean operators (& and |). + +Please note that currently expressions are evaluated strictly left to right, so +use parentheses in complex expressions to indicate the desired evaluation order. + Registers can be the registers of other devices; this is denoted by a memspace prefix (i.e., c:, 8:, 9:, 10:, 11:) Examples: A == $0, X == Y, 8:X == X diff --git a/vice/src/monitor/mon_lex.l b/vice/src/monitor/mon_lex.l index 1377e178271..9b535a56e91 100644 --- a/vice/src/monitor/mon_lex.l +++ b/vice/src/monitor/mon_lex.l @@ -456,22 +456,44 @@ if { BEGIN (COND_MODE); return IF; } iyh { yylval.i = e_IYH; return MON_REGISTER; } /* z80 */ } + /* FIXME: currently no operator precedence is implemented (so all operators */ + /* have the same precedence - ie evaluation is strictly left to right. */ + /* The table below shows the operator precedence in C, which we probably want + /* to use, should we implement this at some point. */ + + /* Category Operator Associativity */ + /* --------------------------------------------------------------------- */ + /* Postfix () [] -> . ++ - - Left to right */ + /* Unary + - ! ~ ++ - - (type)* & sizeof Right to left */ + /* Multiplicative * / % Left to right */ + /* Additive + - Left to right */ + /* Shift << >> Left to right */ + /* Relational < <= > >= Left to right */ + /* Equality == != Left to right */ + /* Bitwise AND & Left to right */ + /* Bitwise XOR ^ Left to right */ + /* Bitwise OR | Left to right */ + /* Logical AND && Left to right */ + /* Logical OR || Left to right */ + /* Conditional ?: Right to left */ + /* Assignment = += -= *= /= %= >>= <<= &= ^= |= Right to left */ + /* Comma , Left to right */ + { - == { yylval.i = e_EQU; return COND_OP; } - != { yylval.i = e_NEQ; return COND_OP; } - \<= { yylval.i = e_LTE; return COND_OP; } - \< { yylval.i = e_LT; return COND_OP; } - \> { yylval.i = e_GT; return COND_OP; } - \>= { yylval.i = e_GTE; return COND_OP; } - - \+ { yylval.i = e_ADD; return COND_OP; } - - { yylval.i = e_SUB; return COND_OP; } - \* { yylval.i = e_MUL; return COND_OP; } - \/ { yylval.i = e_DIV; return COND_OP; } - & { yylval.i = e_BINARY_AND; return COND_OP; } - \| { yylval.i = e_BINARY_OR; return COND_OP; } - && { yylval.i = e_LOGICAL_AND; return COND_OP; } - \|\| { yylval.i = e_LOGICAL_OR; return COND_OP; } + \* { yylval.i = e_MUL; return COND_OP; } /* Multiplicative */ + \/ { yylval.i = e_DIV; return COND_OP; } /* Multiplicative */ + \+ { yylval.i = e_ADD; return COND_OP; } /* Additive */ + - { yylval.i = e_SUB; return COND_OP; } /* Additive */ + \<= { yylval.i = e_LTE; return COND_OP; } /* Relational */ + \< { yylval.i = e_LT; return COND_OP; } /* Relational */ + \> { yylval.i = e_GT; return COND_OP; } /* Relational */ + \>= { yylval.i = e_GTE; return COND_OP; } /* Relational */ + == { yylval.i = e_EQU; return COND_OP; } /* Equality */ + != { yylval.i = e_NEQ; return COND_OP; } /* Equality */ + & { yylval.i = e_BINARY_AND; return COND_OP; } /* Bitwise AND */ + \| { yylval.i = e_BINARY_OR; return COND_OP; } /* Bitwise OR */ + && { yylval.i = e_LOGICAL_AND; return COND_OP; } /* Logical AND */ + \|\| { yylval.i = e_LOGICAL_OR; return COND_OP; } /* Logical OR */ A { yylval.i = e_A; return MON_REGISTER; } /* 65xx/c64dtv/658xx/6x09/z80 */ X { yylval.i = e_X; return MON_REGISTER; } /* 65xx/c64dtv/658xx/6x09 */ diff --git a/vice/src/monitor/mon_parse.y b/vice/src/monitor/mon_parse.y index ddd4c2aeaa0..77ed59f77e1 100644 --- a/vice/src/monitor/mon_parse.y +++ b/vice/src/monitor/mon_parse.y @@ -797,6 +797,29 @@ memloc: memaddr { $$ = $1; if (!CHECK_ADDR($1)) return ERR_ADDR_TOO_BIG; }; memaddr: number { $$ = $1; }; + /* FIXME: currently no operator precedence is implemented (so all operators */ + /* have the same precedence - ie evaluation is strictly left to right. */ + /* The table below shows the operator precedence in C, which we probably want + /* to use, should we implement this at some point. */ + + /* Category Operator Associativity */ + /* --------------------------------------------------------------------- */ + /* Postfix () [] -> . ++ - - Left to right */ + /* Unary + - ! ~ ++ - - (type)* & sizeof Right to left */ + /* Multiplicative * / % Left to right */ + /* Additive + - Left to right */ + /* Shift << >> Left to right */ + /* Relational < <= > >= Left to right */ + /* Equality == != Left to right */ + /* Bitwise AND & Left to right */ + /* Bitwise XOR ^ Left to right */ + /* Bitwise OR | Left to right */ + /* Logical AND && Left to right */ + /* Logical OR || Left to right */ + /* Conditional ?: Right to left */ + /* Assignment = += -= *= /= %= >>= <<= &= ^= |= Right to left */ + /* Comma , Left to right */ + expression: expression '+' expression { $$ = $1 + $3; } | expression '-' expression { $$ = $1 - $3; } | expression '*' expression { $$ = $1 * $3; }