remove unused bye symbol from arithmetic parser
[fio.git] / exp / expression-parser.l
CommitLineData
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
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,
3b0d05e8 34 int *has_error, int *units_specified, const char *msg);
b470a02c
SC
35
36static void __attribute__((unused)) yyunput(int c,char *buf_ptr);
37static int __attribute__((unused)) input(void);
38
18722a18
SC
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;
44
b470a02c
SC
45%}
46
47%%
48
49
18722a18
SC
50[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 }
b470a02c 110[ \t] ; /* ignore whitespace */
51a65a41 111[#:,].* ; /* ignore comments, and everything after colons and commas */
b470a02c
SC
112[0-9]*[.][0-9]+ {
113 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 {
3b0d05e8 124 yyerror(0, 0, 0, 0, "bad number\n");
b470a02c
SC
125 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 {
3b0d05e8 139 yyerror(0, 0, 0, 0, "bad number\n");
b470a02c
SC
140 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 {
3b0d05e8 154 yyerror(0, 0, 0, 0, "bad number\n");
b470a02c
SC
155 yylval.v.has_error = 1;
156 return NUMBER;
157 }
158 }
159\n return 0;
886e5ecd 160[+-/*()^%] return yytext[0];
ae46966a 161
b470a02c
SC
162. {
163 yylval.v.has_error = 1;
164 return NUMBER;
165 }
166%%
167