4 * (C) Copyright 2014, Stephen M. Cameron.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define YYSTYPE PARSER_VALUE_TYPE
27 extern int lexer_input(char* buffer, size_t *nbytes, int buffersize);
30 #define YY_INPUT(buffer, bytes_read, bytes_requested) \
33 size_t __bread = bytes_read; \
34 __ret = lexer_input((buffer), &__bread, (bytes_requested)); \
35 bytes_read = __bread; \
39 extern int yyerror(long long *result, double *dresult,
40 int *has_error, int *units_specified, const char *msg);
42 static void __attribute__((unused)) yyunput(int c,char *buf_ptr);
43 static int __attribute__((unused)) input(void);
45 #define set_suffix_value(yylval, i_val, d_val, has_d_val) \
46 (yylval).v.dval = (d_val); \
47 (yylval).v.ival = (i_val); \
48 (yylval).v.has_dval = (has_d_val); \
49 (yylval).v.has_error = 0;
57 set_suffix_value(yylval, 1024, 1024.0, 0);
61 set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0);
65 set_suffix_value(yylval, 1000, 1000.0, 1);
69 set_suffix_value(yylval, 1, 1.0, 1);
73 set_suffix_value(yylval, 1024LL * 1024 * 1024, 1024.0 * 1024.0 * 1024, 0);
77 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024,
78 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024, 0);
82 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024 * 1024,
83 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0, 0);
87 set_suffix_value(yylval, 1000LL, 1000.0, 0);
91 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
95 set_suffix_value(yylval, 1000000000LL, 1000000000.0 , 0);
99 set_suffix_value(yylval, 1000000000000LL, 1000000000000.0 , 0);
103 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
107 set_suffix_value(yylval, 60LL * 60LL * 24LL * 1000000LL,
108 60.0 * 60.0 * 24.0 * 1000000.0, 0);
112 set_suffix_value(yylval, 60LL * 60LL * 1000000LL,
113 60.0 * 60.0 * 1000000.0, 0);
116 [ \t] ; /* ignore whitespace */
117 [#:,].* ; /* ignore comments, and everything after colons and commas */
118 [0-9]*[.][0-9]+|[0-9]*[.]?[0-9]+[eE][-+]*[0-9]+ {
122 rc = sscanf(yytext, "%lf", &dval);
124 yylval.v.dval = dval;
125 yylval.v.ival = (long long) dval;
126 yylval.v.has_dval = 1;
127 yylval.v.has_error = 0;
130 yyerror(0, 0, 0, 0, "bad number\n");
131 yylval.v.has_error = 1;
137 rc = sscanf(yytext, "%x", &intval);
139 yylval.v.ival = intval;
140 yylval.v.dval = (double) intval;
141 yylval.v.has_dval = 0;
142 yylval.v.has_error = 0;
145 yyerror(0, 0, 0, 0, "bad number\n");
146 yylval.v.has_error = 1;
152 rc = sscanf(yytext, "%d", &intval);
154 yylval.v.ival = intval;
155 yylval.v.dval = (double) intval;
156 yylval.v.has_dval = 0;
157 yylval.v.has_error = 0;
160 yyerror(0, 0, 0, 0, "bad number\n");
161 yylval.v.has_error = 1;
166 [+-/*()^%] return yytext[0];
169 yylval.v.has_error = 1;