(file) Return to WQL.l CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / WQL

  1 mike  1.2 %option never-interactive
  2           %{
  3           
  4           extern int WQLInput(char* buffer, int& numRead, int numRequested);
  5 kumpf 1.3 extern int WQL_error(const char*);
  6 mike  1.2 
  7           #define YY_INPUT(BUF, NREAD, NREQUESTED) WQLInput(BUF, NREAD, NREQUESTED)
  8           
  9           #include <Pegasus/Common/Config.h>
 10           #include <Pegasus/WQL/WQLParserState.h>
 11           #include <cstring>
 12           #include <cassert>
 13           #include "WQLYACC.h"
 14           
 15           #if 0
 16           # define WQL_TRACE(X) printf X
 17           #else
 18           # define WQL_TRACE(X)
 19           #endif
 20           
 21           PEGASUS_NAMESPACE_BEGIN
 22           
 23           extern WQLParserState* globalParserState;
 24           
 25           static char* CloneString(const char* str, Uint32 size = (Uint32)-1);
 26           
 27 mike  1.2 PEGASUS_NAMESPACE_END
 28           
 29           PEGASUS_USING_PEGASUS;
 30           
 31           %}
 32           
 33           POSITIVE_DECIMAL_DIGIT [1-9]
 34           DECIMAL_DIGIT [0-9]
 35           BLANK [ \t\n]
 36           IDENT_CHAR [A-Za-z_]
 37           
 38           %%
 39           
 40           [Ss][Ee][Ll][Ee][Cc][Tt] {
 41           
 42               WQL_TRACE(("LEX: %s [TOK_SELECT]\n", yytext));
 43               return TOK_SELECT;
 44           }
 45           
 46           [Ff][Rr][Oo][Mm] {
 47           
 48 mike  1.2     WQL_TRACE(("LEX: %s [TOK_FROM]\n", yytext));
 49               return TOK_FROM;
 50           }
 51           
 52           [Ww][Hh][Ee][Rr][Ee] {
 53           
 54               WQL_TRACE(("LEX: %s [TOK_WHERE]\n", yytext));
 55               return TOK_WHERE;
 56           }
 57           
 58           [Tt][Rr][Uu][Ee] {
 59           
 60               WQL_TRACE(("LEX: %s [TOK_TRUE]\n", yytext));
 61               return TOK_TRUE;
 62           }
 63           
 64           [Ff][Aa][Ll][Ss][Ee] {
 65           
 66               WQL_TRACE(("LEX: %s [TOK_FALSE]\n", yytext));
 67               return TOK_FALSE;
 68           }
 69 mike  1.2 
 70           [Nn][Uu][Ll][Ll] {
 71           
 72               WQL_TRACE(("LEX: %s [TOK_NULL]\n", yytext));
 73               return TOK_NULL;
 74           }
 75           
 76           [Nn][Oo][Tt] {
 77           
 78               WQL_TRACE(("LEX: %s [TOK_NOT]\n", yytext));
 79               return TOK_NOT;
 80           }
 81           
 82           [Aa][Nn][Dd] {
 83           
 84               WQL_TRACE(("LEX: %s [TOK_AND]\n", yytext));
 85               return TOK_AND;
 86           }
 87           
 88           [Oo][Rr] {
 89           
 90 mike  1.2     WQL_TRACE(("LEX: %s [TOK_OR]\n", yytext));
 91               return TOK_OR;
 92           }
 93           
 94           [Ii][Ss] {
 95           
 96               WQL_TRACE(("LEX: %s [TOK_IS]\n", yytext));
 97               return TOK_IS;
 98           }
 99           
100           [-+]?{POSITIVE_DECIMAL_DIGIT}{DECIMAL_DIGIT}* {
101           
102               WQL_TRACE(("LEX: %s [TOK_INTEGER]\n", yytext));
103               WQL_lval.intValue = strtol(yytext, (char**)0, 10);
104               return TOK_INTEGER;
105           }
106           
107           [+-]?0 {
108           
109               WQL_TRACE(("LEX: %s [TOK_INTEGER]\n", yytext));
110               WQL_lval.intValue = 0;
111 mike  1.2     return TOK_INTEGER;
112           }
113           
114           [-+]?{DECIMAL_DIGIT}*\.{DECIMAL_DIGIT}+([eE][+-]?{DECIMAL_DIGIT}+)? {
115           
116               WQL_TRACE(("LEX: %s [TOK_DOUBLE]\n", yytext));
117               WQL_lval.doubleValue = strtod((char*)yytext, (char**)0);
118               return TOK_DOUBLE;
119           }
120           
121           \"[^\"\n]*\" {
122           
123               /* ATTN-B: handle long literals by using yyinput(). */
124               /* ATTN-B: Handle expansion of special characters */
125           
126               WQL_TRACE(("LEX: %s [TOK_STRING]\n", yytext));
127           
128               /* Copy the string (but remove the surrounding quotes */
129           
130               {
131           	size_t n = strlen(yytext) - 2;
132 mike  1.2 	char* strValue = new char[n + 1];
133           	memcpy(strValue, yytext + 1, n);
134           	strValue[n] = '\0';
135           	WQL_lval.strValue = strValue;
136           	globalParserState->outstandingStrings.append(strValue);
137               }
138           
139               return TOK_STRING;
140           }
141           
142           \"[^\"\n]*$ {
143           
144               WQL_error("Unterminated string");
145           }
146           
147           [\*(),] { 
148           
149               WQL_TRACE(("LEX: %c\n", yytext[0]));
150               return yytext[0];
151           }
152           
153 mike  1.2 "=" { 
154               WQL_TRACE(("LEX: %s [TOK_EQ]\n", yytext));
155               return TOK_EQ; 
156           }
157           
158           "!=" { 
159           
160               WQL_TRACE(("LEX: %s [TOK_NE]\n", yytext));
161               return TOK_NE; 
162           }
163           
164           "<=" { 
165           
166               WQL_TRACE(("LEX: %s [TOK_LE]\n", yytext));
167               return TOK_LE; 
168           }
169           
170           "<" { 
171           
172               WQL_TRACE(("LEX: %s [TOK_LT]\n", yytext));
173               return TOK_LT; 
174 mike  1.2 }
175           
176           ">=" { 
177           
178               WQL_TRACE(("LEX: %s [TOK_GE]\n", yytext));
179               return TOK_GE; 
180           }
181           
182 karl  1.3.24.1 "<>" { 
183                
184                    WQL_TRACE(("LEX: %s [TOK_NE]\n", yytext));
185                    return TOK_NE; 
186                }
187                
188 mike  1.2      ">" { 
189                
190                    WQL_TRACE(("LEX: %s [TOK_GT]\n", yytext));
191                    return TOK_GT; 
192                }
193                
194                {IDENT_CHAR}({IDENT_CHAR}|{DECIMAL_DIGIT})*  {
195                
196                    WQL_TRACE(("LEX: %s [TOK_IDENTIFIER]\n", yytext));
197                
198                    {
199                	size_t n = strlen(yytext);
200                	char* strValue = new char[n + 1];
201                	memcpy(strValue, yytext, n);
202                	strValue[n] = '\0';
203                	WQL_lval.strValue = strValue;
204                	globalParserState->outstandingStrings.append(strValue);
205                    }
206                
207                    return TOK_IDENTIFIER;
208                }
209 mike  1.2      
210                {BLANK}+ {
211                
212                    /* Ignore blanks */
213                }
214                
215                . {
216                    WQL_lval.intValue = 0;
217                    return TOK_UNEXPECTED_CHAR;
218                }
219                
220                %%
221                
222                extern "C" int WQL_wrap()
223                {
224                    return 1;
225                }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2