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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #define YYSTYPE PARSER_VALUE_TYPE
27 extern int lexer_input(char *buffer, unsigned int *nbytes, int buffersize);
30 #define YY_INPUT(buffer, bytes_read, bytes_requested) \
33 unsigned int __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 /* set by parser -- this is another thing which makes the parser thread-unsafe :(. */
46 int lexer_value_is_time = 0; /* for determining if "m" suffix means mega- or minutes */
48 #define set_suffix_value(yylval, i_val, d_val, has_d_val) \
49 (yylval).v.dval = (d_val); \
50 (yylval).v.ival = (i_val); \
51 (yylval).v.has_dval = (has_d_val); \
52 (yylval).v.has_error = 0;
60 set_suffix_value(yylval, 1024, 1024.0, 0);
64 set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0);
68 set_suffix_value(yylval, 1000, 1000.0, 1);
72 set_suffix_value(yylval, 1, 1.0, 1);
76 set_suffix_value(yylval, 1024LL * 1024 * 1024, 1024.0 * 1024.0 * 1024, 0);
80 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024,
81 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024, 0);
85 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024 * 1024,
86 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0, 0);
90 set_suffix_value(yylval, 1000LL, 1000.0, 0);
94 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
98 set_suffix_value(yylval, 1000000000LL, 1000000000.0 , 0);
102 set_suffix_value(yylval, 1000000000000LL, 1000000000000.0 , 0);
106 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
110 if (!lexer_value_is_time) {
111 set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0);
113 set_suffix_value(yylval, 60LL * 1000000LL, 60.0 * 1000000.0, 0);
118 set_suffix_value(yylval, 60LL * 60LL * 24LL * 1000000LL,
119 60.0 * 60.0 * 24.0 * 1000000.0, 0);
123 set_suffix_value(yylval, 60LL * 60LL * 1000000LL,
124 60.0 * 60.0 * 1000000.0, 0);
127 [ \t] ; /* ignore whitespace */
128 [#:,].* ; /* ignore comments, and everything after colons and commas */
129 [0-9]*[.][0-9]+|[0-9]*[.]?[0-9]+[eE][-+]*[0-9]+ {
133 rc = sscanf(yytext, "%lf", &dval);
135 yylval.v.dval = dval;
136 yylval.v.ival = (long long) dval;
137 yylval.v.has_dval = 1;
138 yylval.v.has_error = 0;
141 yyerror(0, 0, 0, 0, "bad number\n");
142 yylval.v.has_error = 1;
148 rc = sscanf(yytext, "%x", &intval);
150 yylval.v.ival = intval;
151 yylval.v.dval = (double) intval;
152 yylval.v.has_dval = 0;
153 yylval.v.has_error = 0;
156 yyerror(0, 0, 0, 0, "bad number\n");
157 yylval.v.has_error = 1;
163 rc = sscanf(yytext, "%d", &intval);
165 yylval.v.ival = intval;
166 yylval.v.dval = (double) intval;
167 yylval.v.has_dval = 0;
168 yylval.v.has_error = 0;
171 yyerror(0, 0, 0, 0, "bad number\n");
172 yylval.v.has_error = 1;
177 [+-/*()^%] return yytext[0];
180 yylval.v.has_error = 1;