mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / innobase / pars / pars0lex.l
blobad65034fab021ee853ee35ab59872bc5e7036426
1 /******************************************************
2 SQL parser lexical analyzer: input file for the GNU Flex lexer generator
4 (c) 1997 Innobase Oy
6 Created 12/14/1997 Heikki Tuuri
7 Published under the GPL version 2
9 The InnoDB parser is frozen because MySQL takes care of SQL parsing.
10 Therefore we normally keep the InnoDB parser C files as they are, and do
11 not automatically generate them from pars0grm.y and pars0lex.l.
13 How to make the InnoDB parser and lexer C files:
15 1. Run ./make_flex.sh to generate lexer files.
17 2. Run ./make_bison.sh to generate parser files.
19 These instructions seem to work at least with bison-1.875d and flex-2.5.31 on
20 Linux.
21 *******************************************************/
23 %option nostdinit
24 %option 8bit
25 %option warn
26 %option pointer
27 %option never-interactive
28 %option nodefault
29 %option noinput
30 %option nounput
31 %option noyywrap
32 %option noyy_scan_buffer
33 %option noyy_scan_bytes
34 %option noyy_scan_string
35 %option nounistd
38 #define YYSTYPE que_node_t*
40 #include "univ.i"
41 #include "pars0pars.h"
42 #include "pars0grm.h"
43 #include "pars0sym.h"
44 #include "mem0mem.h"
45 #include "os0proc.h"
47 #define malloc(A)       ut_malloc(A)
48 #define free(A)         ut_free(A)
49 #define realloc(P, A)   ut_realloc(P, A)
50 #define exit(A)         ut_error
52 #define YY_INPUT(buf, result, max_size) pars_get_lex_chars(buf, &result, max_size)
54 /* String buffer for removing quotes */
55 static ulint    stringbuf_len_alloc = 0; /* Allocated length */
56 static ulint    stringbuf_len = 0; /* Current length */
57 static char*    stringbuf; /* Start of buffer */
58 /* Appends a string to the buffer. */
59 static
60 void
61 string_append(
62 /*==========*/
63         const char*     str,    /* in: string to be appended */
64         ulint           len)    /* in: length of the string */
66         if (stringbuf == NULL) {
67                 stringbuf = malloc(1);
68                 stringbuf_len_alloc = 1;
69         }
71         if (stringbuf_len + len > stringbuf_len_alloc) {
72                 while (stringbuf_len + len > stringbuf_len_alloc) {
73                         stringbuf_len_alloc <<= 1;
74                 }
75                 stringbuf = realloc(stringbuf, stringbuf_len_alloc);
76         }
78         memcpy(stringbuf + stringbuf_len, str, len);
79         stringbuf_len += len;
84 DIGIT   [0-9]
85 ID      [a-z_A-Z][a-z_A-Z0-9]*
86 BOUND_LIT       \:[a-z_A-Z0-9]+
87 BOUND_ID        \$[a-z_A-Z0-9]+
89 %x comment
90 %x quoted
91 %x id
94 {DIGIT}+        {
95                         yylval = sym_tab_add_int_lit(pars_sym_tab_global,
96                                                                 atoi(yytext));
97                         return(PARS_INT_LIT);
100 {DIGIT}+"."{DIGIT}* {
101                         ut_error;       /* not implemented */
103                         return(PARS_FLOAT_LIT);
106 {BOUND_LIT}     {
107                         ulint   type;
109                         yylval = sym_tab_add_bound_lit(pars_sym_tab_global,
110                                 yytext + 1, &type);
112                         return((int) type);
115 {BOUND_ID}      {
116                         yylval = sym_tab_add_bound_id(pars_sym_tab_global,
117                                 yytext + 1);
119                         return(PARS_ID_TOKEN);
122 "'"             {
123 /* Quoted character string literals are handled in an explicit
124 start state 'quoted'.  This state is entered and the buffer for
125 the scanned string is emptied upon encountering a starting quote.
127 In the state 'quoted', only two actions are possible (defined below). */
128                         BEGIN(quoted);
129                         stringbuf_len = 0;
131 <quoted>[^\']+  {
132                         /* Got a sequence of characters other than "'":
133                         append to string buffer */
134                         string_append(yytext, yyleng);
136 <quoted>"'"+    {
137                         /* Got a sequence of "'" characters:
138                         append half of them to string buffer,
139                         as "''" represents a single "'".
140                         We apply truncating division,
141                         so that "'''" will result in "'". */
143                         string_append(yytext, yyleng / 2);
145                         /* If we got an odd number of quotes, then the
146                         last quote we got is the terminating quote.
147                         At the end of the string, we return to the
148                         initial start state and report the scanned
149                         string literal. */
151                         if (yyleng % 2) {
152                                 BEGIN(INITIAL);
153                                 yylval = sym_tab_add_str_lit(
154                                         pars_sym_tab_global,
155                                         (byte*) stringbuf, stringbuf_len);
156                                 return(PARS_STR_LIT);
157                         }
160 \"              {
161 /* Quoted identifiers are handled in an explicit start state 'id'.
162 This state is entered and the buffer for the scanned string is emptied
163 upon encountering a starting quote.
165 In the state 'id', only two actions are possible (defined below). */
166                         BEGIN(id);
167                         stringbuf_len = 0;
169 <id>[^\"]+      {
170                         /* Got a sequence of characters other than '"':
171                         append to string buffer */
172                         string_append(yytext, yyleng);
174 <id>\"+ {
175                         /* Got a sequence of '"' characters:
176                         append half of them to string buffer,
177                         as '""' represents a single '"'.
178                         We apply truncating division,
179                         so that '"""' will result in '"'. */
181                         string_append(yytext, yyleng / 2);
183                         /* If we got an odd number of quotes, then the
184                         last quote we got is the terminating quote.
185                         At the end of the string, we return to the
186                         initial start state and report the scanned
187                         identifier. */
189                         if (yyleng % 2) {
190                                 BEGIN(INITIAL);
191                                 yylval = sym_tab_add_id(
192                                         pars_sym_tab_global,
193                                         (byte*) stringbuf, stringbuf_len);
195                                 return(PARS_ID_TOKEN);
196                         }
199 "NULL"          {
200                         yylval = sym_tab_add_null_lit(pars_sym_tab_global);
202                         return(PARS_NULL_LIT);
205 "SQL"           {
206                         /* Implicit cursor name */
207                         yylval = sym_tab_add_str_lit(pars_sym_tab_global,
208                                                         (byte*) yytext, yyleng);
209                         return(PARS_SQL_TOKEN);
212 "AND"           {
213                         return(PARS_AND_TOKEN);
216 "OR"            {
217                         return(PARS_OR_TOKEN);
220 "NOT"           {
221                         return(PARS_NOT_TOKEN);
224 "PROCEDURE"     {
225                         return(PARS_PROCEDURE_TOKEN);
228 "IN"            {
229                         return(PARS_IN_TOKEN);
232 "OUT"           {
233                         return(PARS_OUT_TOKEN);
236 "BINARY"        {
237                         return(PARS_BINARY_TOKEN);
240 "BLOB"          {
241                         return(PARS_BLOB_TOKEN);
244 "INT"           {
245                         return(PARS_INT_TOKEN);
248 "INTEGER"       {
249                         return(PARS_INT_TOKEN);
252 "FLOAT"         {
253                         return(PARS_FLOAT_TOKEN);
256 "CHAR"          {
257                         return(PARS_CHAR_TOKEN);
260 "IS"            {
261                         return(PARS_IS_TOKEN);
264 "BEGIN"         {
265                         return(PARS_BEGIN_TOKEN);
268 "END"           {
269                         return(PARS_END_TOKEN);
272 "IF"            {
273                         return(PARS_IF_TOKEN);
276 "THEN"          {
277                         return(PARS_THEN_TOKEN);
280 "ELSE"          {
281                         return(PARS_ELSE_TOKEN);
284 "ELSIF"         {
285                         return(PARS_ELSIF_TOKEN);
288 "LOOP"          {
289                         return(PARS_LOOP_TOKEN);
292 "WHILE"         {
293                         return(PARS_WHILE_TOKEN);
296 "RETURN"        {
297                         return(PARS_RETURN_TOKEN);
300 "SELECT"        {
301                         return(PARS_SELECT_TOKEN);
304 "SUM"           {
305                         return(PARS_SUM_TOKEN);
308 "COUNT"         {
309                         return(PARS_COUNT_TOKEN);
312 "DISTINCT"      {
313                         return(PARS_DISTINCT_TOKEN);
316 "FROM"          {
317                         return(PARS_FROM_TOKEN);
320 "WHERE"         {
321                         return(PARS_WHERE_TOKEN);
324 "FOR"           {
325                         return(PARS_FOR_TOKEN);
328 "READ"          {
329                         return(PARS_READ_TOKEN);
332 "ORDER"         {
333                         return(PARS_ORDER_TOKEN);
336 "BY"            {
337                         return(PARS_BY_TOKEN);
340 "ASC"           {
341                         return(PARS_ASC_TOKEN);
344 "DESC"          {
345                         return(PARS_DESC_TOKEN);
348 "INSERT"        {
349                         return(PARS_INSERT_TOKEN);
352 "INTO"          {
353                         return(PARS_INTO_TOKEN);
356 "VALUES"        {
357                         return(PARS_VALUES_TOKEN);
360 "UPDATE"        {
361                         return(PARS_UPDATE_TOKEN);
364 "SET"           {
365                         return(PARS_SET_TOKEN);
368 "DELETE"        {
369                         return(PARS_DELETE_TOKEN);
372 "CURRENT"       {
373                         return(PARS_CURRENT_TOKEN);
376 "OF"            {
377                         return(PARS_OF_TOKEN);
380 "CREATE"        {
381                         return(PARS_CREATE_TOKEN);
384 "TABLE"         {
385                         return(PARS_TABLE_TOKEN);
388 "INDEX"         {
389                         return(PARS_INDEX_TOKEN);
392 "UNIQUE"        {
393                         return(PARS_UNIQUE_TOKEN);
396 "CLUSTERED"     {
397                         return(PARS_CLUSTERED_TOKEN);
400 "DOES_NOT_FIT_IN_MEMORY"        {
401                         return(PARS_DOES_NOT_FIT_IN_MEM_TOKEN);
404 "ON"            {
405                         return(PARS_ON_TOKEN);
408 "DECLARE"       {
409                         return(PARS_DECLARE_TOKEN);
412 "CURSOR"        {
413                         return(PARS_CURSOR_TOKEN);
416 "OPEN"  {
417                         return(PARS_OPEN_TOKEN);
420 "FETCH" {
421                         return(PARS_FETCH_TOKEN);
424 "CLOSE" {
425                         return(PARS_CLOSE_TOKEN);
428 "NOTFOUND"      {
429                         return(PARS_NOTFOUND_TOKEN);
432 "TO_CHAR"       {
433                         return(PARS_TO_CHAR_TOKEN);
436 "TO_NUMBER"     {
437                         return(PARS_TO_NUMBER_TOKEN);
440 "TO_BINARY"     {
441                         return(PARS_TO_BINARY_TOKEN);
444 "BINARY_TO_NUMBER" {
445                         return(PARS_BINARY_TO_NUMBER_TOKEN);
448 "SUBSTR"        {
449                         return(PARS_SUBSTR_TOKEN);
452 "REPLSTR"       {
453                         return(PARS_REPLSTR_TOKEN);
456 "CONCAT"        {
457                         return(PARS_CONCAT_TOKEN);
460 "INSTR"         {
461                         return(PARS_INSTR_TOKEN);
464 "LENGTH"        {
465                         return(PARS_LENGTH_TOKEN);
468 "SYSDATE"       {
469                         return(PARS_SYSDATE_TOKEN);
472 "PRINTF"        {
473                         return(PARS_PRINTF_TOKEN);
476 "ASSERT"        {
477                         return(PARS_ASSERT_TOKEN);
480 "RND"           {
481                         return(PARS_RND_TOKEN);
484 "RND_STR"       {
485                         return(PARS_RND_STR_TOKEN);
488 "ROW_PRINTF"    {
489                         return(PARS_ROW_PRINTF_TOKEN);
492 "COMMIT"        {
493                         return(PARS_COMMIT_TOKEN);
496 "ROLLBACK"      {
497                         return(PARS_ROLLBACK_TOKEN);
500 "WORK"          {
501                         return(PARS_WORK_TOKEN);
504 "UNSIGNED"      {
505                         return(PARS_UNSIGNED_TOKEN);
508 "EXIT"          {
509                         return(PARS_EXIT_TOKEN);
512 "FUNCTION"      {
513                         return(PARS_FUNCTION_TOKEN);
516 "LOCK"  {
517                         return(PARS_LOCK_TOKEN);
520 "SHARE" {
521                         return(PARS_SHARE_TOKEN);
524 "MODE"  {
525                         return(PARS_MODE_TOKEN);
528 {ID}            {
529                         yylval = sym_tab_add_id(pars_sym_tab_global,
530                                                         (byte*)yytext,
531                                                         ut_strlen(yytext));
532                         return(PARS_ID_TOKEN);
535 ".."            {
536                         return(PARS_DDOT_TOKEN);
539 ":="            {
540                         return(PARS_ASSIGN_TOKEN);
543 "<="            {
544                         return(PARS_LE_TOKEN);
547 ">="            {
548                         return(PARS_GE_TOKEN);
551 "<>"            {
552                         return(PARS_NE_TOKEN);
555 "("             {
557                         return((int)(*yytext));
560 "="             {
562                         return((int)(*yytext));
565 ">"             {
567                         return((int)(*yytext));
570 "<"             {
572                         return((int)(*yytext));
575 ","             {
577                         return((int)(*yytext));
580 ";"             {
582                         return((int)(*yytext));
585 ")"             {
587                         return((int)(*yytext));
590 "+"             {
592                         return((int)(*yytext));
595 "-"             {
597                         return((int)(*yytext));
600 "*"             {
602                         return((int)(*yytext));
605 "/"             {
607                         return((int)(*yytext));
610 "%"             {
612                         return((int)(*yytext));
615 "{"             {
617                         return((int)(*yytext));
620 "}"             {
622                         return((int)(*yytext));
625 "?"             {
627                         return((int)(*yytext));
630 "/*"                    BEGIN(comment); /* eat up comment */
632 <comment>[^*]*
633 <comment>"*"+[^*/]*
634 <comment>"*"+"/"        BEGIN(INITIAL);
636 [ \t\n]+                /* eat up whitespace */
639 .               {
640                         fprintf(stderr,"Unrecognized character: %02x\n",
641                                 *yytext);
643                         ut_error;
645                         return(0);