1 /* 2 * (C) Copyright 2014, Stephen M. Cameron. 3 * 4 * The license below covers all files distributed with fio unless otherwise 5 * noted in the file itself. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * 20 */ 21 22 #include <stdio.h> 23 #include <string.h> 24 25 #include "../y.tab.h" 26 27 extern int evaluate_arithmetic_expression(const char *buffer, long long *ival, 28 double *dval, double implied_units, int is_time); 29 30 int main(int argc, char *argv[]) 31 { 32 int rc, bye = 0; 33 long long result; 34 double dresult; 35 char buffer[100]; 36 37 do { 38 if (fgets(buffer, 90, stdin) == NULL) 39 break; 40 rc = strlen(buffer); 41 if (rc > 0 && buffer[rc - 1] == '\n') 42 buffer[rc - 1] = '\0'; 43 rc = evaluate_arithmetic_expression(buffer, &result, &dresult, 1.0, 0); 44 if (!rc) { 45 printf("%lld (%20.20lf)\n", result, dresult); 46 } else { 47 fprintf(stderr, "Syntax error\n"); 48 result = 0; 49 dresult = 0; 50 } 51 } while (!bye); 52 return 0; 53 } 54 55