blob: 7d5e787dd9748bceebaa747ffcbe4edc37f9c2fc [file] [log] [blame]
Stephen M. Cameron88b635b2014-09-29 12:10:49 -06001%{
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
27extern int lexer_input(char* buffer, int *nbytes, int buffersize);
28
29#undef YY_INPUT
30#define YY_INPUT(buffer, bytes_read, bytes_requested) \
31 lexer_input((buffer), &(bytes_read), (bytes_requested))
32
33extern int yyerror(long long *result, double *dresult,
Stephen M. Camerona22867a2014-09-30 11:21:20 -050034 int *has_error, int *units_specified, const char *msg);
Stephen M. Cameron88b635b2014-09-29 12:10:49 -060035
36static void __attribute__((unused)) yyunput(int c,char *buf_ptr);
37static int __attribute__((unused)) input(void);
38
Stephen M. Cameronc3805eb2014-09-29 12:15:35 -060039#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;
44
Stephen M. Cameron88b635b2014-09-29 12:10:49 -060045%}
46
47%%
48
49
Stephen M. Cameronc3805eb2014-09-29 12:15:35 -060050[kK]|[kK][bB] {
51 set_suffix_value(yylval, 1024, 1024.0, 0);
52 return SUFFIX;
53 }
54[Mm]|[Mm][bB] {
55 set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0);
56 return SUFFIX;
57 }
58[mM][sS] {
59 set_suffix_value(yylval, 1000, 1000.0, 1);
60 return SUFFIX;
61 }
62[uU][sS] {
63 set_suffix_value(yylval, 1, 1.0, 1);
64 return SUFFIX;
65 }
66[gG]|[Gg][Bb] {
67 set_suffix_value(yylval, 1024LL * 1024 * 1024, 1024.0 * 1024.0 * 1024, 0);
68 return SUFFIX;
69 }
70[tT]|[tT][bB] {
71 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024,
72 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024, 0);
73 return SUFFIX;
74 }
75[pP]|[pP][bB] {
76 set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024 * 1024,
77 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0, 0);
78 return SUFFIX;
79 }
80[kK][iI][Bb] {
81 set_suffix_value(yylval, 1000LL, 1000.0, 0);
82 return SUFFIX;
83 }
84[mM][Ii][bB] {
85 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
86 return SUFFIX;
87 }
88[gG][iI][Bb] {
89 set_suffix_value(yylval, 1000000000LL, 1000000000.0 , 0);
90 return SUFFIX;
91 }
92[pP][iI][Bb] {
93 set_suffix_value(yylval, 1000000000000LL, 1000000000000.0 , 0);
94 return SUFFIX;
95 }
96[sS] {
97 set_suffix_value(yylval, 1000000LL, 1000000.0 , 0);
98 return SUFFIX;
99 }
100[dD] {
101 set_suffix_value(yylval, 60LL * 60LL * 24LL * 1000000LL,
102 60.0 * 60.0 * 24.0 * 1000000.0, 0);
103 return SUFFIX;
104 }
105[hH] {
106 set_suffix_value(yylval, 60LL * 60LL * 1000000LL,
107 60.0 * 60.0 * 1000000.0, 0);
108 return SUFFIX;
109 }
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600110[ \t] ; /* ignore whitespace */
Stephen M. Cameron303b5ca2014-09-30 08:44:24 -0500111[#:,].* ; /* ignore comments, and everything after colons and commas */
Stephen M. Cameron5abaf3e2014-10-02 20:31:11 -0500112[0-9]*[.][0-9]+|[0-9]*[.]?[0-9]+[eE][-+]*[0-9]+ {
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600113 int rc;
114 double dval;
115
116 rc = sscanf(yytext, "%lf", &dval);
117 if (rc == 1) {
118 yylval.v.dval = dval;
119 yylval.v.ival = (long long) dval;
120 yylval.v.has_dval = 1;
121 yylval.v.has_error = 0;
122 return NUMBER;
123 } else {
Stephen M. Camerona22867a2014-09-30 11:21:20 -0500124 yyerror(0, 0, 0, 0, "bad number\n");
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600125 yylval.v.has_error = 1;
126 return NUMBER;
127 }
128 }
1290x[0-9a-fA-F]+ {
130 int rc, intval;
131 rc = sscanf(yytext, "%x", &intval);
132 if (rc == 1) {
133 yylval.v.ival = intval;
134 yylval.v.dval = (double) intval;
135 yylval.v.has_dval = 0;
136 yylval.v.has_error = 0;
137 return NUMBER;
138 } else {
Stephen M. Camerona22867a2014-09-30 11:21:20 -0500139 yyerror(0, 0, 0, 0, "bad number\n");
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600140 yylval.v.has_error = 1;
141 return NUMBER;
142 }
143 }
144[0-9]+ {
145 int rc, intval;
146 rc = sscanf(yytext, "%d", &intval);
147 if (rc == 1) {
148 yylval.v.ival = intval;
149 yylval.v.dval = (double) intval;
150 yylval.v.has_dval = 0;
151 yylval.v.has_error = 0;
152 return NUMBER;
153 } else {
Stephen M. Camerona22867a2014-09-30 11:21:20 -0500154 yyerror(0, 0, 0, 0, "bad number\n");
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600155 yylval.v.has_error = 1;
156 return NUMBER;
157 }
158 }
159\n return 0;
Jens Axboeded6ec22014-09-29 13:20:40 -0600160[+-/*()^%] return yytext[0];
Stephen M. Cameron4fe690e2014-09-29 12:16:54 -0600161
Stephen M. Cameron88b635b2014-09-29 12:10:49 -0600162. {
163 yylval.v.has_error = 1;
164 return NUMBER;
165 }
166%%
167