Commit | Line | Data |
---|---|---|
b470a02c SC |
1 | %{ |
2 | ||
3 | /* | |
4 | * (C) Copyright 2014, Stephen M. Cameron. | |
5 | * | |
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. | |
9 | * | |
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. | |
14 | * | |
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 | |
18 | * | |
19 | */ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include <string.h> | |
23 | #include "y.tab.h" | |
24 | ||
25 | #define YYSTYPE PARSER_VALUE_TYPE | |
26 | ||
de06a468 | 27 | extern int lexer_input(char *buffer, unsigned int *nbytes, int buffersize); |
b470a02c SC |
28 | |
29 | #undef YY_INPUT | |
bc10c331 JA |
30 | #define YY_INPUT(buffer, bytes_read, bytes_requested) \ |
31 | ({ \ | |
32 | int __ret; \ | |
de06a468 | 33 | unsigned int __bread = bytes_read; \ |
3fcc6ca7 JA |
34 | __ret = lexer_input((buffer), &__bread, (bytes_requested)); \ |
35 | bytes_read = __bread; \ | |
bc10c331 | 36 | __ret; \ |
3fcc6ca7 | 37 | }) |
b470a02c SC |
38 | |
39 | extern int yyerror(long long *result, double *dresult, | |
3b0d05e8 | 40 | int *has_error, int *units_specified, const char *msg); |
b470a02c | 41 | |
bc10c331 | 42 | static void __attribute__((unused)) yyunput(int c, char *buf_ptr); |
b470a02c SC |
43 | static int __attribute__((unused)) input(void); |
44 | ||
18722a18 SC |
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; | |
50 | ||
b470a02c SC |
51 | %} |
52 | ||
53 | %% | |
54 | ||
55 | ||
18722a18 SC |
56 | [kK]|[kK][bB] { |
57 | set_suffix_value(yylval, 1024, 1024.0, 0); | |
58 | return SUFFIX; | |
59 | } | |
60 | [Mm]|[Mm][bB] { | |
61 | set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0); | |
62 | return SUFFIX; | |
63 | } | |
64 | [mM][sS] { | |
65 | set_suffix_value(yylval, 1000, 1000.0, 1); | |
66 | return SUFFIX; | |
67 | } | |
68 | [uU][sS] { | |
69 | set_suffix_value(yylval, 1, 1.0, 1); | |
70 | return SUFFIX; | |
71 | } | |
72 | [gG]|[Gg][Bb] { | |
73 | set_suffix_value(yylval, 1024LL * 1024 * 1024, 1024.0 * 1024.0 * 1024, 0); | |
74 | return SUFFIX; | |
75 | } | |
76 | [tT]|[tT][bB] { | |
77 | set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024, | |
78 | 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024, 0); | |
79 | return SUFFIX; | |
80 | } | |
81 | [pP]|[pP][bB] { | |
82 | set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024 * 1024, | |
83 | 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0, 0); | |
84 | return SUFFIX; | |
85 | } | |
86 | [kK][iI][Bb] { | |
87 | set_suffix_value(yylval, 1000LL, 1000.0, 0); | |
88 | return SUFFIX; | |
89 | } | |
90 | [mM][Ii][bB] { | |
91 | set_suffix_value(yylval, 1000000LL, 1000000.0 , 0); | |
92 | return SUFFIX; | |
93 | } | |
94 | [gG][iI][Bb] { | |
95 | set_suffix_value(yylval, 1000000000LL, 1000000000.0 , 0); | |
96 | return SUFFIX; | |
97 | } | |
98 | [pP][iI][Bb] { | |
99 | set_suffix_value(yylval, 1000000000000LL, 1000000000000.0 , 0); | |
100 | return SUFFIX; | |
101 | } | |
102 | [sS] { | |
103 | set_suffix_value(yylval, 1000000LL, 1000000.0 , 0); | |
104 | return SUFFIX; | |
105 | } | |
106 | [dD] { | |
107 | set_suffix_value(yylval, 60LL * 60LL * 24LL * 1000000LL, | |
108 | 60.0 * 60.0 * 24.0 * 1000000.0, 0); | |
109 | return SUFFIX; | |
110 | } | |
111 | [hH] { | |
112 | set_suffix_value(yylval, 60LL * 60LL * 1000000LL, | |
113 | 60.0 * 60.0 * 1000000.0, 0); | |
114 | return SUFFIX; | |
115 | } | |
b470a02c | 116 | [ \t] ; /* ignore whitespace */ |
51a65a41 | 117 | [#:,].* ; /* ignore comments, and everything after colons and commas */ |
ca45c1f3 | 118 | [0-9]*[.][0-9]+|[0-9]*[.]?[0-9]+[eE][-+]*[0-9]+ { |
b470a02c SC |
119 | int rc; |
120 | double dval; | |
121 | ||
122 | rc = sscanf(yytext, "%lf", &dval); | |
123 | if (rc == 1) { | |
124 | yylval.v.dval = dval; | |
125 | yylval.v.ival = (long long) dval; | |
126 | yylval.v.has_dval = 1; | |
127 | yylval.v.has_error = 0; | |
128 | return NUMBER; | |
129 | } else { | |
3b0d05e8 | 130 | yyerror(0, 0, 0, 0, "bad number\n"); |
b470a02c SC |
131 | yylval.v.has_error = 1; |
132 | return NUMBER; | |
133 | } | |
134 | } | |
135 | 0x[0-9a-fA-F]+ { | |
136 | int rc, intval; | |
137 | rc = sscanf(yytext, "%x", &intval); | |
138 | if (rc == 1) { | |
139 | yylval.v.ival = intval; | |
140 | yylval.v.dval = (double) intval; | |
141 | yylval.v.has_dval = 0; | |
142 | yylval.v.has_error = 0; | |
143 | return NUMBER; | |
144 | } else { | |
3b0d05e8 | 145 | yyerror(0, 0, 0, 0, "bad number\n"); |
b470a02c SC |
146 | yylval.v.has_error = 1; |
147 | return NUMBER; | |
148 | } | |
149 | } | |
150 | [0-9]+ { | |
151 | int rc, intval; | |
152 | rc = sscanf(yytext, "%d", &intval); | |
153 | if (rc == 1) { | |
154 | yylval.v.ival = intval; | |
155 | yylval.v.dval = (double) intval; | |
156 | yylval.v.has_dval = 0; | |
157 | yylval.v.has_error = 0; | |
158 | return NUMBER; | |
159 | } else { | |
3b0d05e8 | 160 | yyerror(0, 0, 0, 0, "bad number\n"); |
b470a02c SC |
161 | yylval.v.has_error = 1; |
162 | return NUMBER; | |
163 | } | |
164 | } | |
165 | \n return 0; | |
886e5ecd | 166 | [+-/*()^%] return yytext[0]; |
ae46966a | 167 | |
b470a02c SC |
168 | . { |
169 | yylval.v.has_error = 1; | |
170 | return NUMBER; | |
171 | } | |
172 | %% | |
173 |