feat(sdb): support sdb
This commit is contained in:
parent
8500df8a6e
commit
e828e140cd
22 changed files with 985 additions and 44 deletions
58
npc/utils/sdb/addrexp.y
Normal file
58
npc/utils/sdb/addrexp.y
Normal file
|
@ -0,0 +1,58 @@
|
|||
%code requires {
|
||||
#include <types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
extern int yylex(void);
|
||||
}
|
||||
%{
|
||||
#include <types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
void yyerror(word_t *result, const char *err) {
|
||||
fprintf(stderr, "%s", err);
|
||||
}
|
||||
int pmem_read(int raddr);
|
||||
%}
|
||||
|
||||
%token NUMBER HEX_NUMBER
|
||||
%token REGISTER
|
||||
%locations
|
||||
%start input
|
||||
%define api.value.type { word_t }
|
||||
%parse-param { uint32_t *result }
|
||||
%left '-' '+'
|
||||
%left '*' '/'
|
||||
|
||||
%%
|
||||
input
|
||||
: expression { *result = $1; }
|
||||
;
|
||||
|
||||
expression
|
||||
: number { $$ = $1; }
|
||||
| expression '>' '=' expression { $$ = ($1 >= $4); }
|
||||
| expression '<' '=' expression { $$ = ($1 <= $4); }
|
||||
| expression '=' '=' expression { $$ = ($1 == $4); }
|
||||
| expression '!' '=' expression { $$ = ($1 == $4); }
|
||||
| expression '>' expression { $$ = ($1 > $3); }
|
||||
| expression '<' expression { $$ = ($1 < $3); }
|
||||
| expression '+' expression { $$ = $1 + $3; }
|
||||
| expression '-' expression { $$ = $1 - $3; }
|
||||
| expression '*' expression { $$ = $1 * $3; }
|
||||
| expression '/' expression {
|
||||
if($3 == 0) {
|
||||
fprintf(stderr, "Error: divide by zero at" FMT_WORD " / " FMT_WORD "\n", $1, $3);
|
||||
YYABORT;
|
||||
};
|
||||
$$ = $1 / $3;
|
||||
}
|
||||
| '-' number { $$ = -$2; }
|
||||
| '*' expression { $$ = pmem_read($2); }
|
||||
| '(' expression ')' { $$ = $2; }
|
||||
|
||||
number
|
||||
: REGISTER
|
||||
| NUMBER
|
||||
| HEX_NUMBER
|
||||
|
||||
%%
|
Loading…
Add table
Add a link
Reference in a new issue