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, int *nbytes, int buffersize);
30 #define YY_INPUT(buffer, bytes_read, bytes_requested) \
31 lexer_input((buffer), &(bytes_read), (bytes_requested))
33 extern int yyerror(long long *result, double *dresult,
34 int *has_error, int *units_specified, const char *msg);
36 static void __attribute__((unused)) yyunput(int c,char *buf_ptr);
37 static int __attribute__((unused)) input(void);
39 #define set_suffix_value(yylval, i_val, d_val, has_d_val) \
40 (yylval).v.dval = (d_val); \
41 (yylval).v.ival = (i_val); \
42 (yylval).v.has_dval = (has_d_val); \
43 (yylval).v.has_error = 0;
51 set_suffix_value(yylval, 1024, 1024.0, 0);
55 set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0);
59 set_suffix_value(yylval, 1000, 1000.0, 1);
63 set_suffix_value(yylval, 1, 1.0, 1);
67 set_suffix_value(yylval, 1024LL * 1024 * 1024, 1024.0 * 1024.0 * 1024, 0);
71 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024,
72 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024, 0);
76 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024 * 1024,
77 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0, 0);
81 set_suffix_value(yylval, 1000LL, 1000.0, 0);
85 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
89 set_suffix_value(yylval, 1000000000LL, 1000000000.0 , 0);
93 set_suffix_value(yylval, 1000000000000LL, 1000000000000.0 , 0);
97 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
101 set_suffix_value(yylval, 60LL * 60LL * 24LL * 1000000LL,
102 60.0 * 60.0 * 24.0 * 1000000.0, 0);
106 set_suffix_value(yylval, 60LL * 60LL * 1000000LL,
107 60.0 * 60.0 * 1000000.0, 0);
110 [ \t] ; /* ignore whitespace */
111 [#:,].* ; /* ignore comments, and everything after colons and commas */
112 [0-9]*[.][0-9]+|[0-9]*[.]?[0-9]+[eE][-+]*[0-9]+ {
116 rc = sscanf(yytext, "%lf", &dval);
118 yylval.v.dval = dval;
119 yylval.v.ival = (long long) dval;
120 yylval.v.has_dval = 1;
121 yylval.v.has_error = 0;
124 yyerror(0, 0, 0, 0, "bad number\n");
125 yylval.v.has_error = 1;
131 rc = sscanf(yytext, "%x", &intval);
133 yylval.v.ival = intval;
134 yylval.v.dval = (double) intval;
135 yylval.v.has_dval = 0;
136 yylval.v.has_error = 0;
139 yyerror(0, 0, 0, 0, "bad number\n");
140 yylval.v.has_error = 1;
146 rc = sscanf(yytext, "%d", &intval);
148 yylval.v.ival = intval;
149 yylval.v.dval = (double) intval;
150 yylval.v.has_dval = 0;
151 yylval.v.has_error = 0;
154 yyerror(0, 0, 0, 0, "bad number\n");
155 yylval.v.has_error = 1;
160 [+-/*()^%] return yytext[0];
163 yylval.v.has_error = 1;