388515e2c4722bea9c83de692479dd436fe15074
[fio.git] / exp / expression-parser.l
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
27 extern 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
33 extern int yyerror(long long *result, double *dresult,
34                 int *has_error, int *bye, const char *msg);
35
36 static void __attribute__((unused)) yyunput(int c,char *buf_ptr);
37 static int __attribute__((unused)) input(void);
38
39 %}
40
41 %%
42
43
44 bye     return BYE;
45 [ \t] ; /* ignore whitespace */
46 #.+ ; /* ignore comments */
47 [0-9]*[.][0-9]+ {
48                         int rc;
49                         double dval;
50
51                         rc = sscanf(yytext, "%lf", &dval);
52                         if (rc == 1) {
53                                 yylval.v.dval = dval;
54                                 yylval.v.ival = (long long) dval;
55                                 yylval.v.has_dval = 1;
56                                 yylval.v.has_error = 0;
57                                 return NUMBER;
58                         } else {
59                                 yyerror(0, 0, 0, 0, "bad number\n");
60                                 yylval.v.has_error = 1;
61                                 return NUMBER;
62                         }
63                 }
64 0x[0-9a-fA-F]+ {
65                 int rc, intval;
66                 rc = sscanf(yytext, "%x", &intval);
67                 if (rc == 1) {
68                         yylval.v.ival = intval;
69                         yylval.v.dval = (double) intval;
70                         yylval.v.has_dval = 0;
71                         yylval.v.has_error = 0;
72                         return NUMBER;
73                 } else {
74                         yyerror(0, 0, 0, 0, "bad number\n");
75                         yylval.v.has_error = 1;
76                         return NUMBER;
77                 }
78         }
79 [0-9]+  {
80                 int rc, intval;
81                 rc = sscanf(yytext, "%d", &intval);
82                 if (rc == 1) {
83                         yylval.v.ival = intval;
84                         yylval.v.dval = (double) intval;
85                         yylval.v.has_dval = 0;
86                         yylval.v.has_error = 0;
87                         return NUMBER;
88                 } else {
89                         yyerror(0, 0, 0, 0, "bad number\n");
90                         yylval.v.has_error = 1;
91                         return NUMBER;
92                 }
93         }
94 \n      return 0;
95 [+-/*()]        return yytext[0];
96 .       {
97                 yylval.v.has_error = 1;
98                 return NUMBER;  
99         }
100 %%
101