Skip to content

Commit

Permalink
document the absence of operator precedence in the monitor parser, ad…
Browse files Browse the repository at this point in the history
…d some related comment(s)

git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45388 379a1393-f5fb-40a0-bcee-ef074d9b53f7
  • Loading branch information
mrdudz committed Dec 3, 2024
1 parent f476e25 commit 531dd2d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
6 changes: 5 additions & 1 deletion vice/doc/vice.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 37 additions & 15 deletions vice/src/monitor/mon_lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

<COND_MODE>{
== { 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 */
Expand Down
23 changes: 23 additions & 0 deletions vice/src/monitor/mon_parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 531dd2d

Please sign in to comment.