diff options
Diffstat (limited to 'igdbg.yacc.y')
-rw-r--r-- | igdbg.yacc.y | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/igdbg.yacc.y b/igdbg.yacc.y new file mode 100644 index 0000000..956c7e3 --- /dev/null +++ b/igdbg.yacc.y @@ -0,0 +1,67 @@ +%{ +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +int process_cmd(char *cmdhdr, int argc, ...); +void yyerror(char *s); +int yylex(void); +int yyparse(void); +int yywrap(void); + +%} + +%union { + unsigned long expr; + char *string; +} + +%token <string> CMDHDR0 CMDHDR1 CMDHDR2 CMDHDR3 CMDHDR4 CMDHDR5 CMDBEAGLE SUBCMD0 SUBCMD1 SUBCMD2 SUBCMD3 FILENAME CMDTOPAZ +%token <expr> NUMBER +%token LSHIFT RSHIFT +%left '-' '+' +%left '*' '/' +%nonassoc UMINUS + +%type <expr> expression + +%% + +command: CMDHDR0 { process_cmd($1,0); } +| CMDHDR1 expression { process_cmd($1,1,$2); } +| CMDHDR2 expression expression { process_cmd($1,2,$2,$3); } +| CMDHDR3 expression expression expression { process_cmd($1,3,$2,$3,$4);} +| CMDHDR4 expression expression expression expression { process_cmd($1,4,$2,$3,$4,$5);} +| CMDHDR5 expression expression expression expression expression { process_cmd($1,4,$2,$3,$4,$5,$6);} + +expression: expression '+' expression { $$ = $1 + $3; } +| expression '-' expression { $$ = $1 - $3; } +| expression '*' expression { $$ = $1 * $3; } +| expression '/' expression { + if ($3 == 0.0) yyerror("divide by zero"); + else $$ = $1 / $3; +} +| expression LSHIFT expression { $$ = $1 << $3; } +| expression RSHIFT expression { $$ = $1 >> $3; } +| '-' expression %prec UMINUS { $$ = -$2; } +| '(' expression ')' { $$ = $2; } +| NUMBER +; + +%% + +void yyerror(char *s) +{ + fprintf(stderr,"%s\n",s); +} + +int yywrap() +{ + return(1); +} + +#ifdef __cplusplus +} +#endif |