1 /******************************************************
2 SQL parser lexical analyzer: input file for the GNU Flex lexer generator
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
21 *******************************************************/
27 %option never-interactive
32 %option noyy_scan_buffer
33 %option noyy_scan_bytes
34 %option noyy_scan_string
38 #define YYSTYPE que_node_t*
41 #include "pars0pars.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. */
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;
71 if (stringbuf_len + len > stringbuf_len_alloc) {
72 while (stringbuf_len + len > stringbuf_len_alloc) {
73 stringbuf_len_alloc <<= 1;
75 stringbuf = realloc(stringbuf, stringbuf_len_alloc);
78 memcpy(stringbuf + stringbuf_len, str, len);
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]+
95 yylval = sym_tab_add_int_lit(pars_sym_tab_global,
100 {DIGIT}+"."{DIGIT}* {
101 ut_error; /* not implemented */
103 return(PARS_FLOAT_LIT);
109 yylval = sym_tab_add_bound_lit(pars_sym_tab_global,
116 yylval = sym_tab_add_bound_id(pars_sym_tab_global,
119 return(PARS_ID_TOKEN);
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). */
132 /* Got a sequence of characters other than "'":
133 append to string buffer */
134 string_append(yytext, yyleng);
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
153 yylval = sym_tab_add_str_lit(
155 (byte*) stringbuf, stringbuf_len);
156 return(PARS_STR_LIT);
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). */
170 /* Got a sequence of characters other than '"':
171 append to string buffer */
172 string_append(yytext, yyleng);
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
191 yylval = sym_tab_add_id(
193 (byte*) stringbuf, stringbuf_len);
195 return(PARS_ID_TOKEN);
200 yylval = sym_tab_add_null_lit(pars_sym_tab_global);
202 return(PARS_NULL_LIT);
206 /* Implicit cursor name */
207 yylval = sym_tab_add_str_lit(pars_sym_tab_global,
208 (byte*) yytext, yyleng);
209 return(PARS_SQL_TOKEN);
213 return(PARS_AND_TOKEN);
217 return(PARS_OR_TOKEN);
221 return(PARS_NOT_TOKEN);
225 return(PARS_PROCEDURE_TOKEN);
229 return(PARS_IN_TOKEN);
233 return(PARS_OUT_TOKEN);
237 return(PARS_BINARY_TOKEN);
241 return(PARS_BLOB_TOKEN);
245 return(PARS_INT_TOKEN);
249 return(PARS_INT_TOKEN);
253 return(PARS_FLOAT_TOKEN);
257 return(PARS_CHAR_TOKEN);
261 return(PARS_IS_TOKEN);
265 return(PARS_BEGIN_TOKEN);
269 return(PARS_END_TOKEN);
273 return(PARS_IF_TOKEN);
277 return(PARS_THEN_TOKEN);
281 return(PARS_ELSE_TOKEN);
285 return(PARS_ELSIF_TOKEN);
289 return(PARS_LOOP_TOKEN);
293 return(PARS_WHILE_TOKEN);
297 return(PARS_RETURN_TOKEN);
301 return(PARS_SELECT_TOKEN);
305 return(PARS_SUM_TOKEN);
309 return(PARS_COUNT_TOKEN);
313 return(PARS_DISTINCT_TOKEN);
317 return(PARS_FROM_TOKEN);
321 return(PARS_WHERE_TOKEN);
325 return(PARS_FOR_TOKEN);
329 return(PARS_READ_TOKEN);
333 return(PARS_ORDER_TOKEN);
337 return(PARS_BY_TOKEN);
341 return(PARS_ASC_TOKEN);
345 return(PARS_DESC_TOKEN);
349 return(PARS_INSERT_TOKEN);
353 return(PARS_INTO_TOKEN);
357 return(PARS_VALUES_TOKEN);
361 return(PARS_UPDATE_TOKEN);
365 return(PARS_SET_TOKEN);
369 return(PARS_DELETE_TOKEN);
373 return(PARS_CURRENT_TOKEN);
377 return(PARS_OF_TOKEN);
381 return(PARS_CREATE_TOKEN);
385 return(PARS_TABLE_TOKEN);
389 return(PARS_INDEX_TOKEN);
393 return(PARS_UNIQUE_TOKEN);
397 return(PARS_CLUSTERED_TOKEN);
400 "DOES_NOT_FIT_IN_MEMORY" {
401 return(PARS_DOES_NOT_FIT_IN_MEM_TOKEN);
405 return(PARS_ON_TOKEN);
409 return(PARS_DECLARE_TOKEN);
413 return(PARS_CURSOR_TOKEN);
417 return(PARS_OPEN_TOKEN);
421 return(PARS_FETCH_TOKEN);
425 return(PARS_CLOSE_TOKEN);
429 return(PARS_NOTFOUND_TOKEN);
433 return(PARS_TO_CHAR_TOKEN);
437 return(PARS_TO_NUMBER_TOKEN);
441 return(PARS_TO_BINARY_TOKEN);
445 return(PARS_BINARY_TO_NUMBER_TOKEN);
449 return(PARS_SUBSTR_TOKEN);
453 return(PARS_REPLSTR_TOKEN);
457 return(PARS_CONCAT_TOKEN);
461 return(PARS_INSTR_TOKEN);
465 return(PARS_LENGTH_TOKEN);
469 return(PARS_SYSDATE_TOKEN);
473 return(PARS_PRINTF_TOKEN);
477 return(PARS_ASSERT_TOKEN);
481 return(PARS_RND_TOKEN);
485 return(PARS_RND_STR_TOKEN);
489 return(PARS_ROW_PRINTF_TOKEN);
493 return(PARS_COMMIT_TOKEN);
497 return(PARS_ROLLBACK_TOKEN);
501 return(PARS_WORK_TOKEN);
505 return(PARS_UNSIGNED_TOKEN);
509 return(PARS_EXIT_TOKEN);
513 return(PARS_FUNCTION_TOKEN);
517 return(PARS_LOCK_TOKEN);
521 return(PARS_SHARE_TOKEN);
525 return(PARS_MODE_TOKEN);
529 yylval = sym_tab_add_id(pars_sym_tab_global,
532 return(PARS_ID_TOKEN);
536 return(PARS_DDOT_TOKEN);
540 return(PARS_ASSIGN_TOKEN);
544 return(PARS_LE_TOKEN);
548 return(PARS_GE_TOKEN);
552 return(PARS_NE_TOKEN);
557 return((int)(*yytext));
562 return((int)(*yytext));
567 return((int)(*yytext));
572 return((int)(*yytext));
577 return((int)(*yytext));
582 return((int)(*yytext));
587 return((int)(*yytext));
592 return((int)(*yytext));
597 return((int)(*yytext));
602 return((int)(*yytext));
607 return((int)(*yytext));
612 return((int)(*yytext));
617 return((int)(*yytext));
622 return((int)(*yytext));
627 return((int)(*yytext));
630 "/*" BEGIN(comment); /* eat up comment */
634 <comment>"*"+"/" BEGIN(INITIAL);
636 [ \t\n]+ /* eat up whitespace */
640 fprintf(stderr,"Unrecognized character: %02x\n",