用Lex(flex)和yacc(bison)写的简单计算器(5) { $$ = -$2; } PLUS rexpr %prec UNARYMINUS { $$ = $2;} iexpr PLUS rexpr { $$ = (double)$1 + $3;} iexpr MINUS rexpr { $$ = (double)$1 - $3;} iexpr TIMES rexpr { $$ = (double)$1 * $3;} iexpr DIVIDE rexpr { if($3) $$ = (double)$1 / $3; else { $$ = $1; printf (stderr, "%d.%d-%d.%d: division by zero", @3.first_line, @3.first_column, @3.last_line, @3.last_column); } } iexpr POWER rexpr { $$ = pow((double)$1,$3); } rexpr PLUS iexpr { $$ = $1 + (double)$3;} rexpr MINUS iexpr { $$ = $1 - (double)$3;} rexpr TIMES iexpr { $$ = $1 * (double)$3;} rexpr DIVIDE iexpr { if($3)