trie index changes
[csql.git] / src / sql / dmllex.lxx
blobe1de463b50127a55ddcf1dd4d9168058cd3876c1
1 /***************************************************************************
2  *   Copyright (C) 2007 by Prabakaran Thirumalai   *
3  *   praba_tuty@yahoo.com   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
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   ***************************************************************************/
16 %array yytext
18 #include "dmlyacc.h"
19 #include <stdlib.h>
20 #include <string.h>
22 int echo_on=0;
23 int lexEof=0;
24 extern char *lexInput;
26 #undef ECHO
27 #define ECHO { if(echo_on) printf("%s",yytext); }
30 /*    Macro definitions  */
34 letter          [a-zA-Z_]
35 digit           [0-9]
36 hex             [0-9A-Fa-f]
37 letter_or_digit [a-zA-Z_0-9.]
38 /*sign            [\+\-]*/
39 string_char     [\]\[\\\+\"=\)\(\{\}\*&\^\%\$#@!:;,\|\~\`\.\<\>\?\/a-zA-Z_0-9 \t\n\-]
40 white_space     [ \t\n]
41 blank           [ \t]
42 quota           \'\'
43 non_double_quota [^\"\n]
44 other           .
45 operator        "<"|">"|">="|"<="|"="|"\!="|"<>"|"LIKE"|"like"
49 {operator}  { 
50                 yylval.stringval = strdup((const char*)yytext);
51                 return(OPERATOR);
52             }
54 \'({quota}|{string_char})*\'{blank}*$   {
55                 int len; ECHO;
56                 if(*yytext != '\'') 
57                     printf("ERROR: wanted a string, got: %s\n",yytext);
58                 len = yyleng - 1;
59                 while (yytext[len] == ' ' || yytext[len] == '\t') 
60                 { 
61                     yytext[len] = '\0';
62                     len--;
63                 }
64                 yylval.stringval = strdup((const char*)yytext + 1);
65                 //printf("rule1: %s.\n", yylval.stringval );
66                 return (STRING);
67             }
69 \'({quota}|{string_char})*\'    {  ECHO;
70                 if(*yytext != '\'')
71                     printf("ERROR: wanted a string, got: %s\n",yytext);
72                 yytext[yyleng-1]='\0';
73                 yylval.stringval = strdup((const char*)yytext + 1);
74                 //printf("rule2: %s.\n", yylval.stringval );
75                 return (STRING);
76             }
78 \"{non_double_quota}*\"    {  ECHO;
79                 yytext[yyleng-1] = '\0'; /*remove the beginning and ending quota*/
80                     yytext[0]=' ';
81                 yylval.stringval = strdup((const char*)yytext + 1);
82                 return (STRING);
83             }
85 {letter}{letter_or_digit}*   {
86                     int token; 
87                 char *fieldname;
88                 token = FIELD;
89                 ECHO;
91                 if(strcasecmp(yytext,"SELECT") == 0) token = SELECT;
92                 if(strcasecmp(yytext,"FROM") == 0) token = FROM;
93                 if(strcasecmp(yytext,"AS") == 0) token = AS;
94                 if(strcasecmp(yytext,"WHERE") == 0) token = WHERE;
95                 if(strcasecmp(yytext,"BETWEEN") == 0) token = BETWEEN;
96                 if(strcasecmp(yytext,"IN") == 0) token = IN;
97                 if(strcasecmp(yytext,"AND") == 0) token = AND;
98                 if(strcasecmp(yytext,"OR") == 0) token = OR;
99                 if(strcasecmp(yytext,"NOT") == 0) token = NOT;
100                 if(strcasecmp(yytext,"INSERT") == 0) token = INSERT;
101                 if(strcasecmp(yytext,"INTO") == 0) token = INTO;
102                 if(strcasecmp(yytext,"VALUES") == 0) token = VALUES;
103                 if(strcasecmp(yytext,"DELETE") == 0) token = DELETE;
104                 if(strcasecmp(yytext,"UPDATE") == 0) token = UPDATE;
105                 if(strcasecmp(yytext,"SET") == 0) token = SET;
106                 if(strcasecmp(yytext,"NULL") == 0) token = NULL_VALUE;
107                 if(strcasecmp(yytext,"UNIQUE") == 0) token = UNIQUE;
108                 if(strcasecmp(yytext,"CREATE") == 0) token = CREATE;
109                 if(strcasecmp(yytext,"DROP") == 0) token = DROP;
110                 if(strcasecmp(yytext,"TABLE") == 0) token = TABLE;
111                 if(strcasecmp(yytext,"PRIMARY") == 0) token = PRIMARY;
112                 if(strcasecmp(yytext,"INDEX") == 0) token = INDEX;
113                 if(strcasecmp(yytext,"ON") == 0) token = ON;
114                 if(strcasecmp(yytext,"HASH") == 0) token = HASH;
115                 if(strcasecmp(yytext,"TREE") == 0) token = TREE;
116                 if(strcasecmp(yytext,"TRIE") == 0) token = TRIE;
118                 if(strcasecmp(yytext,"KEY") == 0) token = KEY;
119                 if(strcasecmp(yytext,"DEFAULT") == 0) token = DEFAULT;
120                 if(strcasecmp(yytext,"INT") ==0) token = INT_TYPE;
121                 if(strcasecmp(yytext,"INTEGER") ==0) token = INT_TYPE;
122                 if(strcasecmp(yytext,"LONG") ==0) token = LONG_TYPE;
123                 if(strcasecmp(yytext,"DOUBLE") ==0) token = DOUBLE_TYPE;
124                 if(strcasecmp(yytext,"REAL") ==0) token = DOUBLE_TYPE;
125                 if(strcasecmp(yytext,"SHORT") ==0) token = SHORT_TYPE;
126                 if(strcasecmp(yytext,"SMALLINT") ==0) token = SHORT_TYPE;
127                 if(strcasecmp(yytext,"DATE") ==0) token = DATE_TYPE;
128                 if(strcasecmp(yytext,"TIME") ==0) token = TIME_TYPE;
129                 if(strcasecmp(yytext,"TIMESTAMP") ==0) token = TIMESTAMP_TYPE;
130                 if(strcasecmp(yytext,"BINARY") ==0) token = BINARY_TYPE;
131                 if(strcasecmp(yytext,"CHAR") ==0) token = CHAR_TYPE;
132                 if(strcasecmp(yytext,"VARCHAR") ==0) token = VARCHAR_TYPE;
133                 if(strcasecmp(yytext,"BIGINT") ==0) token = BIGINT_TYPE;
134                 if(strcasecmp(yytext,"TINYINT") ==0) token = TINYINT_TYPE;
135                 if(strcasecmp(yytext,"FLOAT") ==0) token = FLOAT_TYPE;
136                 if(strcasecmp(yytext,"MIN") ==0) token = MIN;
137                 if(strcasecmp(yytext,"MAX") ==0) token = MAX;
138                 if(strcasecmp(yytext,"SUM") ==0) token = SUM;
139                 if(strcasecmp(yytext,"AVG") ==0) token = AVG;
140                 if(strcasecmp(yytext,"COUNT") ==0) token = COUNT;
141                 if(strcasecmp(yytext,"GROUP") ==0) token = GROUP;
142                 if(strcasecmp(yytext,"ORDER") ==0) token = ORDER;
143                 if(strcasecmp(yytext,"ASC") ==0) token = ASC;
144                 if(strcasecmp(yytext,"DESC") ==0) token = DESC;
145                 if(strcasecmp(yytext,"DISTINCT") ==0) token = DISTINCT;
146                 if(strcasecmp(yytext,"BY") ==0) token = BY;
147                 if(strcasecmp(yytext,"HAVING") ==0) token = HAVING;
148                 if(strcasecmp(yytext,"LIMIT") ==0) token = LIMIT;
149                 if(strcasecmp(yytext,"OFFSET") ==0) token = OFFSET;
150                 if(strcasecmp(yytext,"INNER") ==0) token = INNER;
151                 if(strcasecmp(yytext,"OUTER") ==0) token = OUTER;
152                 if(strcasecmp(yytext,"CROSS") ==0) token = CROSS;
153                 if(strcasecmp(yytext,"LEFT") ==0) token = LEFT;
154                 if(strcasecmp(yytext,"JOIN") ==0) token = JOIN;
155                 if(strcasecmp(yytext,"GETALLTABLES") ==0) token = ALLTABLE;
156                 if(strcasecmp(yytext,"DESCRIBE") ==0) token = DESCRIBE;
157                 if(strcasecmp(yytext,"GETPRIMARYKEY") ==0) token = PRIMARYINFO;
158                 if(strcasecmp(yytext,"AUTO_INCREMENT") ==0) token = AUTO_INCREMENT;
159                 if(strcasecmp(yytext,"GETDATATYPES") == 0) token = GETDATATYPES;
160                 if(strcasecmp(yytext,"GETTABLETYPES") == 0) token = GETTABLETYPES;
161                 if(strcasecmp(yytext,"IMPORTEDKEY") == 0) token = IMPORTEDKEY;
162                 if(strcasecmp(yytext,"EXPORTEDKEY") == 0) token = EXPORTEDKEY;
163                 if(strcasecmp(yytext,"SIZE") ==0) token = SIZE;
164                 if(strcasecmp(yytext,"FOREIGN") ==0) token = FOREIGN;
165                 if(strcasecmp(yytext,"REFERENCES") ==0) token = REFERENCES;
166                 if(strcasecmp(yytext,"CACHE") ==0) token = CACHE;
167                 if(strcasecmp(yytext,"UNCACHE") ==0) token = UNCACHE;
168                 if(strcasecmp(yytext,"CONDITION") ==0) token = CONDITION;
169                 if(strcasecmp(yytext,"FIELDLIST") ==0) token = FIELDLIST;
170                 if(strcasecmp(yytext,"PK") ==0) token = PK;
171                 if(strcasecmp(yytext,"DIRECT") ==0) token = DIRECT;
172                 if(strcasecmp(yytext,"DSN") ==0) token = DSN;
173                 if(strcasecmp(yytext,"NOSCHEMA") ==0) token = NOSCHEMA;
174                 if(strcasecmp(yytext,"COMPACT") ==0) token = COMPACT;
175                 if(strcasecmp(yytext,"IS") ==0) token = IS;
176                 if(strcasecmp(yytext,"EXPLAIN") ==0) token = EXPLAIN;
177                 if(strcasecmp(yytext,"PLAN") ==0) token = PLAN;
178                 if(strcasecmp(yytext,"GETCATALOGS") ==0) token = GETCATALOGS;
179                 if(strcasecmp(yytext,"USER") ==0) token = USER;
180                 if(strcasecmp(yytext,"PASSWORD") ==0) token = PASSWORD;
181                 if(strcasecmp(yytext,"ALTER") ==0) token = ALTER;
182                 if(strcasecmp(yytext,"FLUSH") ==0) token = FLUSH;
183                 if(strcasecmp(yytext,"ADD") ==0) token = ADD;
184                 if(strcasecmp(yytext,"MODIFY") ==0) token = MODIFY;
185                 if(strcasecmp(yytext,"COLUMN") ==0) token = COLUMN;
186                 if(strcasecmp(yytext,"RENAME") ==0) token = RENAME;
187                 if(strcasecmp(yytext,"TO") ==0) token = TO;
188                 if(strcasecmp(yytext,"DATE_DIFF") ==0) token = DATE_DIFF;
189                 if(strcasecmp(yytext,"DATE_ADD") ==0) token = DATE_ADD;
190                 if(strcasecmp(yytext,"DATE_SUB") ==0) token = DATE_SUB;
191                 if(strcasecmp(yytext,"TIME_DIFF") ==0) token = TIME_DIFF;
192                 if(strcasecmp(yytext,"TIME_ADD") ==0) token = TIME_ADD;
193                 if(strcasecmp(yytext,"TIME_SUB") ==0) token = TIME_SUB;
194                 if(strcasecmp(yytext,"DAY") ==0) token = DAY;
195                 if(strcasecmp(yytext,"MONTH") ==0) token = MONTH;
196                 if(strcasecmp(yytext,"YEAR") ==0) token = YEAR;
197                 if(strcasecmp(yytext,"HOUR") ==0) token = HOUR;
198                 if(strcasecmp(yytext,"MINUTE") ==0) token = MINUTE;
199                 if(strcasecmp(yytext,"SECOND") ==0) token = SECOND;
200                 if(strcasecmp(yytext,"INTERVAL") ==0) token = INTERVAL;
201                 if(strcasecmp(yytext,"TIMESTAMP_DIFF") ==0) token = TIMESTAMP_DIFF;
202                 if(strcasecmp(yytext,"TIMESTAMP_ADD") ==0) token = TIMESTAMP_ADD;
203                 if(strcasecmp(yytext,"TIMESTAMP_SUB") ==0) token = TIMESTAMP_SUB;
204                 if(strcasecmp(yytext,"EXTRACT") ==0) token = EXTRACT;
205                 if(strcasecmp(yytext,"TRUNCATE") ==0) token = TRUNCATE;
206                 if(strcasecmp(yytext,"NOW") ==0) token = NOW;
207                 if( token == FIELD )
208                     yylval.stringval = strdup((const char*)yytext);
209                 else
210                     yylval.stringval = 0;
212                 return(token);
213             }
215 {digit}+      { ECHO;
216                 yylval.stringval = strdup((const char*)yytext);
217                 return (NUMBER_STRING);
218             }
220 (({digit}*\.{digit}+)|({digit}+(\.{digit}*)?))([eE][-+]?{digit}+)?   {   ECHO;
221                 yylval.stringval = strdup((const char*)yytext);
222                 return (DOUBLE);
223             }
225 {hex}+      {   ECHO;
226                 yylval.stringval = strdup((const char*)yytext);
227                 return (BINARY_STRING);
228             }
229 \?          {
230                 yylval.stringval = strdup((const char*)yytext);
231                 return(PARAMETER);
232             }
233 {white_space}+  { ECHO; }
234 "#"{other}*     { ECHO; }
235 "//"{other}*    { ECHO; }
236 "--"{other}*    { ECHO; }
239 /*    Watch this C comment folks */
241 "/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/" { ECHO; }
243 {other} { ECHO; return yytext[0]; }
248 int yywrap()
250     lexEof = 1;
251     return 1;