X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=exp%2Fexpression-parser.y;h=04a6e07a38ae924ed04cbb6736b87894eeceee61;hp=1cc07918df9ceb970e1d279d52ad4fef536ad260;hb=fa07eaa6913d7171c4259b3b0cd76dae3e76ca00;hpb=8e2c678f1fbc8321372c80447eec2ae9eabba747;ds=sidebyside diff --git a/exp/expression-parser.y b/exp/expression-parser.y index 1cc07918..04a6e07a 100644 --- a/exp/expression-parser.y +++ b/exp/expression-parser.y @@ -14,13 +14,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include #include #include + struct parser_value_type { double dval; long long ival; @@ -38,10 +39,11 @@ int yyerror(__attribute__((unused)) long long *result, __attribute__((unused)) double *dresult, __attribute__((unused)) int *has_error, __attribute__((unused)) int *units_specified, - __attribute__((unused)) int *bye, const char *msg); + __attribute__((unused)) const char *msg); extern int yylex(void); extern void yyrestart(FILE *file); +extern int lexer_value_is_time; %} @@ -67,7 +69,6 @@ extern void yyrestart(FILE *file); %parse-param { double *dresult } %parse-param { int *has_error } %parse-param { int *units_specified } -%parse-param { int *bye } %type expression %% @@ -108,11 +109,11 @@ expression: expression '+' expression { } | expression '/' expression { if ($3.ival == 0) - yyerror(0, 0, 0, 0, 0, "divide by zero"); + yyerror(0, 0, 0, 0, "divide by zero"); else $$.ival = $1.ival / $3.ival; if ($3.dval < 1e-20 && $3.dval > -1e-20) - yyerror(0, 0, 0, 0, 0, "divide by zero"); + yyerror(0, 0, 0, 0, "divide by zero"); else $$.dval = $1.dval / $3.dval; if ($3.has_dval || $1.has_dval) @@ -139,9 +140,9 @@ expression: expression '+' expression { } | expression '%' expression { if ($1.has_dval || $3.has_dval) - yyerror(0, 0, 0, 0, 0, "modulo on floats"); + yyerror(0, 0, 0, 0, "modulo on floats"); if ($3.ival == 0) - yyerror(0, 0, 0, 0, 0, "divide by zero"); + yyerror(0, 0, 0, 0, "divide by zero"); else { $$.ival = $1.ival % $3.ival; $$.dval = $$.ival; @@ -179,8 +180,7 @@ expression: expression '+' expression { $$.ival = (long long) $$.dval; } } - | NUMBER { $$ = $1; } - | BYE { $$ = $1; *bye = 1; }; + | NUMBER { $$ = $1; }; %% #include @@ -188,7 +188,7 @@ expression: expression '+' expression { static int lexer_read_offset = 0; static char lexer_input_buffer[1000]; -int lexer_input(char* buffer, int *bytes_read, int bytes_requested) +int lexer_input(char* buffer, unsigned int *bytes_read, int bytes_requested) { int bytes_left = strlen(lexer_input_buffer) - lexer_read_offset; @@ -215,14 +215,15 @@ static void setup_to_parse_string(const char *string) } int evaluate_arithmetic_expression(const char *buffer, long long *ival, double *dval, - double implied_units) + double implied_units, int is_time) { - int rc, units_specified = 0, bye = 0, has_error = 0; + int rc, units_specified = 0, has_error = 0; + lexer_value_is_time = is_time; setup_to_parse_string(buffer); - rc = yyparse(ival, dval, &has_error, &units_specified, &bye); + rc = yyparse(ival, dval, &has_error, &units_specified); yyrestart(NULL); - if (rc || bye || has_error) { + if (rc || has_error) { *ival = 0; *dval = 0; has_error = 1; @@ -238,7 +239,6 @@ int yyerror(__attribute__((unused)) long long *result, __attribute__((unused)) double *dresult, __attribute__((unused)) int *has_error, __attribute__((unused)) int *units_specified, - __attribute__((unused)) int *bye, __attribute__((unused)) const char *msg) { /* We do not need to do anything here. */