exp: fix shift/reduce conflict complaints
[fio.git] / exp / expression-parser.y
index f5a7981f2fbfa8eb6bdacc61d5d99c6e81c9e1f5..6ab6408874b829d2dffbf0ed6fa82ebc9558414d 100644 (file)
@@ -57,8 +57,10 @@ extern void yyrestart(FILE *file);
 %token <v> BYE
 %token <v> SUFFIX 
 %left '-' '+'
+%right SUFFIX
 %left '*' '/'
 %right '^'
+%left '%'
 %nonassoc UMINUS
 %parse-param { long long *result }
 %parse-param { double *dresult }
@@ -132,6 +134,17 @@ expression:        expression '+' expression {
                                $$.dval = $1.ival * $2.ival;
                        $$.has_error = $1.has_error || $2.has_error;
                }
+       |       expression '%' expression {
+                       if ($1.has_dval || $3.has_dval)
+                               yyerror(0, 0, 0, 0, "modulo on floats");
+                       if ($3.ival == 0)
+                               yyerror(0, 0, 0, 0, "divide by zero");
+                       else {
+                               $$.ival = $1.ival % $3.ival;
+                               $$.dval = $$.ival;
+                       }
+                       $$.has_error = $1.has_error || $3.has_error;
+               }
        |       expression '^' expression {
                        $$.has_error = $1.has_error || $3.has_error;
                        if (!$1.has_dval && !$3.has_dval) {
@@ -151,8 +164,9 @@ expression: expression '+' expression {
                                                tmp = 1.0;
                                                $$.has_error = 1;
                                        } else {
-                                               tmp = pow((double) $1.ival,
-                                                               (double) $3.ival);
+                                               double x = (double) $1.ival;
+                                               double y = (double) $3.ival;
+                                               tmp = pow(x, y);
                                        }
                                        $$.ival = (long long) tmp;
                                }