2 #if defined(i386_unknown_nt4_0)
7 #include "BPatch_thread.h"
8 #include "BPatch_image.h"
9 #include "BPatch_type.h"
10 #include "BPatch_snippet.h"
11 #include "breakpoint.h"
14 void yyerror(char *s);
18 extern BPatch_thread *appThread;
19 extern BPatch_image *appImage;
23 BPatch_snippet *parse_result;
31 BPatch_snippet *snippet;
32 BPatch_boolExpr *boolExpr;
33 BPatch_Vector<BPatch_snippet *> *snippetList;
34 BPatch_funcCallExpr *funcCall;
38 %token <sval> IDENTIFIER STRING
41 %token PLUSPLUS MINUSMINUS
46 %left EQ NOT_EQ LESS_EQ GREATER_EQ
52 %left START_BLOCK END_BLOCK
54 %type <boolExpr> bool_expression
55 %type <snippet> arith_expression variable_expr statement inc_decr_expr
56 %type <snippet> param block
57 %type <snippetList> param_list statement_list
58 %type <funcCall> func_call
64 '(' bool_expression ')'
66 parse_result = (BPatch_snippet *) $2;
67 parse_type = parsed_bool;
72 parse_result = new BPatch_sequence(*$1);
73 parse_type = parsed_statement;
81 $$ = new BPatch_Vector<BPatch_snippet *>;
84 | statement_list statement
96 | IF '(' bool_expression ')' block
98 $$ = new BPatch_ifExpr(*$3, *$5);
102 | IF '(' bool_expression ')' block ELSE block
104 $$ = new BPatch_ifExpr(*$3, *$5, *$7);
112 | START_BLOCK statement_list END_BLOCK
114 $$ = new BPatch_sequence(*$2);
119 func_call: IDENTIFIER '(' param_list ')'
121 BPatch_Vector<BPatch_function *>bpfv;
122 if (NULL == appImage->findFunction($1, bpfv) || !bpfv.size()) {
123 printf("unable to find function %s\n", $1);
127 if (bpfv.size() > 1) {
128 printf("found %d references to %s\n", bpfv.size(), $1);
131 BPatch_function *func = bpfv[0];
134 printf("unable to find function %s\n", $1);
140 $$ = new BPatch_funcCallExpr(*func, *$3);
146 //No parameters, return an empty vector
147 $$ = new BPatch_Vector<BPatch_snippet *>;
151 $$ = new BPatch_Vector<BPatch_snippet *>;
154 | param_list COMMA param
161 param: arith_expression
164 $$ = new BPatch_constExpr($1);
169 bool_expression: arith_expression '<' arith_expression {
170 $$ = new BPatch_boolExpr(BPatch_lt, *$1, *$3);
174 | arith_expression '>' arith_expression {
175 $$ = new BPatch_boolExpr(BPatch_gt, *$1, *$3);
179 | arith_expression EQ arith_expression {
180 $$ = new BPatch_boolExpr(BPatch_eq, *$1, *$3);
184 | arith_expression LESS_EQ arith_expression {
185 $$ = new BPatch_boolExpr(BPatch_le, *$1, *$3);
189 | arith_expression GREATER_EQ arith_expression {
190 $$ = new BPatch_boolExpr(BPatch_ge, *$1, *$3);
194 | arith_expression NOT_EQ arith_expression {
195 $$ = new BPatch_boolExpr(BPatch_ne, *$1, *$3);
199 | bool_expression AND bool_expression {
200 $$ = new BPatch_boolExpr(BPatch_and, *$1, *$3);
204 | bool_expression OR bool_expression {
205 $$ = new BPatch_boolExpr(BPatch_or, *$1, *$3);
213 BPatch_variableExpr *var = findVariable($1);
215 fprintf(stderr, "Cannot find variable: %s\n", $1);
224 IDENTIFIER DOT IDENTIFIER {
225 bool foundField = false;
227 BPatch_variableExpr *var = findVariable($1);
229 fprintf(stderr, "Cannot find variable: %s\n", $1);
234 BPatch_Vector<BPatch_variableExpr *> *vars = var->getComponents();
236 fprintf(stderr, "is not an aggregate type: %s\n", $1);
240 for (unsigned int i=0; i < vars->size(); i++) {
241 if (!strcmp($3, (*vars)[i]->getName())) {
248 fprintf(stderr, "%s is not a field of %s\n", $3, $1);
256 if (($2 < 0) || ($2 >= 8)) {
257 printf("parameter %d is not valid\n", $2);
260 $$ = new BPatch_paramExpr($2);
266 | NUMBER { $$ = new BPatch_constExpr($1); }
267 | arith_expression '*' arith_expression {
268 $$ = new BPatch_arithExpr(BPatch_times, *$1, *$3);
273 func_call { $$ = $1; }
275 variable_expr ASSIGN arith_expression {
276 $$ = new BPatch_arithExpr(BPatch_assign, *$1, *$3);
281 | arith_expression '/' arith_expression {
282 $$ = new BPatch_arithExpr(BPatch_divide, *$1, *$3);
286 | arith_expression '+' arith_expression {
287 $$ = new BPatch_arithExpr(BPatch_plus, *$1, *$3);
291 | arith_expression '-' arith_expression {
292 $$ = new BPatch_arithExpr(BPatch_minus, *$1, *$3);
296 | '(' arith_expression ')' {
305 variable_expr PLUSPLUS {
306 $$ = new BPatch_arithExpr(BPatch_assign, *$1, BPatch_arithExpr(BPatch_plus,
307 *$1, BPatch_constExpr(1)));
309 | PLUSPLUS variable_expr {
310 $$ = new BPatch_arithExpr(BPatch_assign, *$2, BPatch_arithExpr(BPatch_plus,
311 *$2, BPatch_constExpr(1)));
313 | variable_expr MINUSMINUS {
314 $$ = new BPatch_arithExpr(BPatch_assign, *$1, BPatch_arithExpr(BPatch_minus,
315 *$1, BPatch_constExpr(1)));
317 | MINUSMINUS variable_expr {
318 $$ = new BPatch_arithExpr(BPatch_assign, *$2, BPatch_arithExpr(BPatch_minus,
319 *$2, BPatch_constExpr(1)));
326 #if 0 // For testing the parser independently
327 extern "C" void set_lex_input(char *str);
329 main(int argc, char *argv[])
341 printf("Returned: %d\n", ret);
345 void yyerror(char *s)
347 fprintf(stderr, "Error on command line: %s\n",s);