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 *bye, 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;
52 set_suffix_value(yylval, 1024, 1024.0, 0);
56 set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0);
60 set_suffix_value(yylval, 1000, 1000.0, 1);
64 set_suffix_value(yylval, 1, 1.0, 1);
68 set_suffix_value(yylval, 1024LL * 1024 * 1024, 1024.0 * 1024.0 * 1024, 0);
72 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024,
73 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024, 0);
77 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024 * 1024,
78 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0, 0);
82 set_suffix_value(yylval, 1000LL, 1000.0, 0);
86 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
90 set_suffix_value(yylval, 1000000000LL, 1000000000.0 , 0);
94 set_suffix_value(yylval, 1000000000000LL, 1000000000000.0 , 0);
98 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
102 set_suffix_value(yylval, 60LL * 60LL * 24LL * 1000000LL,
103 60.0 * 60.0 * 24.0 * 1000000.0, 0);
107 set_suffix_value(yylval, 60LL * 60LL * 1000000LL,
108 60.0 * 60.0 * 1000000.0, 0);
111 [ \t] ; /* ignore whitespace */
112 #.+ ; /* ignore comments */
117 rc = sscanf(yytext, "%lf", &dval);
119 yylval.v.dval = dval;
120 yylval.v.ival = (long long) dval;
121 yylval.v.has_dval = 1;
122 yylval.v.has_error = 0;
125 yyerror(0, 0, 0, 0, "bad number\n");
126 yylval.v.has_error = 1;
132 rc = sscanf(yytext, "%x", &intval);
134 yylval.v.ival = intval;
135 yylval.v.dval = (double) intval;
136 yylval.v.has_dval = 0;
137 yylval.v.has_error = 0;
140 yyerror(0, 0, 0, 0, "bad number\n");
141 yylval.v.has_error = 1;
147 rc = sscanf(yytext, "%d", &intval);
149 yylval.v.ival = intval;
150 yylval.v.dval = (double) intval;
151 yylval.v.has_dval = 0;
152 yylval.v.has_error = 0;
155 yyerror(0, 0, 0, 0, "bad number\n");
156 yylval.v.has_error = 1;
161 [+-/*()^%] return yytext[0];
164 yylval.v.has_error = 1;