drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
pars0lex.l
1/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: */
2/*****************************************************************************
3
4Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
5
6This program is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free Software
8Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful, but WITHOUT
11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16Place, Suite 330, Boston, MA 02110-1301 USA
17
18*****************************************************************************/
19
20/******************************************************
21SQL parser lexical analyzer: input file for the GNU Flex lexer generator
22
23Created 12/14/1997 Heikki Tuuri
24*******************************************************/
25
26%option nostdinit
27%option 8bit
28%option warn
29%option pointer
30%option never-interactive
31%option nodefault
32%option noinput
33%option nounput
34%option noyywrap
35%option noyy_scan_buffer
36%option noyy_scan_bytes
37%option noyy_scan_string
38
39%{
40#define YYSTYPE que_node_t*
41
42#include "univ.i"
43#include "pars0pars.h"
44#include "pars0grm.hh"
45#include "pars0sym.h"
46#include "mem0mem.h"
47#include "os0proc.h"
48
49#define malloc(A) ut_malloc(A)
50#define free(A) ut_free(A)
51#define realloc(P, A) ut_realloc(P, A)
52#define exit(A) ut_error
53
54#define YY_INPUT(buf, result, max_size) pars_get_lex_chars(buf, &result, max_size)
55
56/* String buffer for removing quotes */
57static ulint stringbuf_len_alloc = 0; /* Allocated length */
58static ulint stringbuf_len = 0; /* Current length */
59static char* stringbuf; /* Start of buffer */
61static
62void
63string_append(
64/*==========*/
65 const char* str,
66 ulint len)
67{
68 if (stringbuf == NULL) {
69 stringbuf = malloc(1);
70 stringbuf_len_alloc = 1;
71 }
72
73 if (stringbuf_len + len > stringbuf_len_alloc) {
74 while (stringbuf_len + len > stringbuf_len_alloc) {
75 stringbuf_len_alloc <<= 1;
76 }
77 stringbuf = realloc(stringbuf, stringbuf_len_alloc);
78 }
79
80 memcpy(stringbuf + stringbuf_len, str, len);
81 stringbuf_len += len;
82}
83
84%}
85
86DIGIT [0-9]
87ID [a-z_A-Z][a-z_A-Z0-9]*
88BOUND_LIT \:[a-z_A-Z0-9]+
89BOUND_ID \$[a-z_A-Z0-9]+
90
91%x comment
92%x quoted
93%x id
94
95%option prefix="innodb_"
96
97%%
98
99{DIGIT}+ {
100 innodb_lval = sym_tab_add_int_lit(pars_sym_tab_global,
101 atoi(yytext));
102 return(PARS_INT_LIT);
103}
UNIV_INTERN sym_node_t * sym_tab_add_int_lit(sym_tab_t *sym_tab, ulint val)
Definition pars0sym.cc:111
104
105{DIGIT}+"."{DIGIT}* {
106 ut_error; /* not implemented */
107
108 return(PARS_FLOAT_LIT);
109}
#define ut_error
Definition ut0dbg.h:115
110
111{BOUND_LIT} {
112 ulint type;
113
114 innodb_lval = sym_tab_add_bound_lit(pars_sym_tab_global,
115 yytext + 1, &type);
116
117 return((int) type);
118}
UNIV_INTERN sym_node_t * sym_tab_add_bound_lit(sym_tab_t *sym_tab, const char *name, ulint *lit_type)
Definition pars0sym.cc:204
119
120{BOUND_ID} {
121 innodb_lval = sym_tab_add_bound_id(pars_sym_tab_global,
122 yytext + 1);
123
124 return(PARS_ID_TOKEN);
125}
UNIV_INTERN sym_node_t * sym_tab_add_bound_id(sym_tab_t *sym_tab, const char *name)
Definition pars0sym.cc:360
126
127"'" {
128/* Quoted character string literals are handled in an explicit
129start state 'quoted'. This state is entered and the buffer for
130the scanned string is emptied upon encountering a starting quote.
131
132In the state 'quoted', only two actions are possible (defined below). */
133 BEGIN(quoted);
134 stringbuf_len = 0;
135}
136<quoted>[^\']+ {
137 /* Got a sequence of characters other than "'":
138 append to string buffer */
139 string_append(yytext, yyleng);
140}
141<quoted>"'"+ {
142 /* Got a sequence of "'" characters:
143 append half of them to string buffer,
144 as "''" represents a single "'".
145 We apply truncating division,
146 so that "'''" will result in "'". */
147
148 string_append(yytext, yyleng / 2);
149
150 /* If we got an odd number of quotes, then the
151 last quote we got is the terminating quote.
152 At the end of the string, we return to the
153 initial start state and report the scanned
154 string literal. */
155
156 if (yyleng % 2) {
157 BEGIN(INITIAL);
158 innodb_lval = sym_tab_add_str_lit(
159 pars_sym_tab_global,
160 (byte*) stringbuf, stringbuf_len);
161 return(PARS_STR_LIT);
162 }
163}
UNIV_INTERN sym_node_t * sym_tab_add_str_lit(sym_tab_t *sym_tab, byte *str, ulint len)
Definition pars0sym.cc:154
164
165\" {
166/* Quoted identifiers are handled in an explicit start state 'id'.
167This state is entered and the buffer for the scanned string is emptied
168upon encountering a starting quote.
169
170In the state 'id', only two actions are possible (defined below). */
171 BEGIN(id);
172 stringbuf_len = 0;
173}
174<id>[^\"]+ {
175 /* Got a sequence of characters other than '"':
176 append to string buffer */
177 string_append(yytext, yyleng);
178}
179<id>\"+ {
180 /* Got a sequence of '"' characters:
181 append half of them to string buffer,
182 as '""' represents a single '"'.
183 We apply truncating division,
184 so that '"""' will result in '"'. */
185
186 string_append(yytext, yyleng / 2);
187
188 /* If we got an odd number of quotes, then the
189 last quote we got is the terminating quote.
190 At the end of the string, we return to the
191 initial start state and report the scanned
192 identifier. */
193
194 if (yyleng % 2) {
195 BEGIN(INITIAL);
196 innodb_lval = sym_tab_add_id(
197 pars_sym_tab_global,
198 (byte*) stringbuf, stringbuf_len);
199
200 return(PARS_ID_TOKEN);
201 }
202}
UNIV_INTERN sym_node_t * sym_tab_add_id(sym_tab_t *sym_tab, byte *name, ulint len)
Definition pars0sym.cc:321
203
204"NULL" {
205 innodb_lval = sym_tab_add_null_lit(pars_sym_tab_global);
206
207 return(PARS_NULL_LIT);
208}
UNIV_INTERN sym_node_t * sym_tab_add_null_lit(sym_tab_t *sym_tab)
Definition pars0sym.cc:283
209
210"SQL" {
211 /* Implicit cursor name */
212 innodb_lval = sym_tab_add_str_lit(pars_sym_tab_global,
213 (byte*) yytext, yyleng);
214 return(PARS_SQL_TOKEN);
215}
216
217"AND" {
218 return(PARS_AND_TOKEN);
219}
220
221"OR" {
222 return(PARS_OR_TOKEN);
223}
224
225"NOT" {
226 return(PARS_NOT_TOKEN);
227}
228
229"PROCEDURE" {
230 return(PARS_PROCEDURE_TOKEN);
231}
232
233"IN" {
234 return(PARS_IN_TOKEN);
235}
236
237"OUT" {
238 return(PARS_OUT_TOKEN);
239}
240
241"BINARY" {
242 return(PARS_BINARY_TOKEN);
243}
244
245"BLOB" {
246 return(PARS_BLOB_TOKEN);
247}
248
249"INT" {
250 return(PARS_INT_TOKEN);
251}
252
253"INTEGER" {
254 return(PARS_INT_TOKEN);
255}
256
257"FLOAT" {
258 return(PARS_FLOAT_TOKEN);
259}
260
261"CHAR" {
262 return(PARS_CHAR_TOKEN);
263}
264
265"IS" {
266 return(PARS_IS_TOKEN);
267}
268
269"BEGIN" {
270 return(PARS_BEGIN_TOKEN);
271}
272
273"END" {
274 return(PARS_END_TOKEN);
275}
276
277"IF" {
278 return(PARS_IF_TOKEN);
279}
280
281"THEN" {
282 return(PARS_THEN_TOKEN);
283}
284
285"ELSE" {
286 return(PARS_ELSE_TOKEN);
287}
288
289"ELSIF" {
290 return(PARS_ELSIF_TOKEN);
291}
292
293"LOOP" {
294 return(PARS_LOOP_TOKEN);
295}
296
297"WHILE" {
298 return(PARS_WHILE_TOKEN);
299}
300
301"RETURN" {
302 return(PARS_RETURN_TOKEN);
303}
304
305"SELECT" {
306 return(PARS_SELECT_TOKEN);
307}
308
309"SUM" {
310 return(PARS_SUM_TOKEN);
311}
312
313"COUNT" {
314 return(PARS_COUNT_TOKEN);
315}
316
317"DISTINCT" {
318 return(PARS_DISTINCT_TOKEN);
319}
320
321"FROM" {
322 return(PARS_FROM_TOKEN);
323}
324
325"WHERE" {
326 return(PARS_WHERE_TOKEN);
327}
328
329"FOR" {
330 return(PARS_FOR_TOKEN);
331}
332
333"READ" {
334 return(PARS_READ_TOKEN);
335}
336
337"ORDER" {
338 return(PARS_ORDER_TOKEN);
339}
340
341"BY" {
342 return(PARS_BY_TOKEN);
343}
344
345"ASC" {
346 return(PARS_ASC_TOKEN);
347}
348
349"DESC" {
350 return(PARS_DESC_TOKEN);
351}
352
353"INSERT" {
354 return(PARS_INSERT_TOKEN);
355}
356
357"INTO" {
358 return(PARS_INTO_TOKEN);
359}
360
361"VALUES" {
362 return(PARS_VALUES_TOKEN);
363}
364
365"UPDATE" {
366 return(PARS_UPDATE_TOKEN);
367}
368
369"SET" {
370 return(PARS_SET_TOKEN);
371}
372
373"DELETE" {
374 return(PARS_DELETE_TOKEN);
375}
376
377"CURRENT" {
378 return(PARS_CURRENT_TOKEN);
379}
380
381"OF" {
382 return(PARS_OF_TOKEN);
383}
384
385"CREATE" {
386 return(PARS_CREATE_TOKEN);
387}
388
389"TABLE" {
390 return(PARS_TABLE_TOKEN);
391}
392
393"INDEX" {
394 return(PARS_INDEX_TOKEN);
395}
396
397"UNIQUE" {
398 return(PARS_UNIQUE_TOKEN);
399}
400
401"CLUSTERED" {
402 return(PARS_CLUSTERED_TOKEN);
403}
404
405"DOES_NOT_FIT_IN_MEMORY" {
406 return(PARS_DOES_NOT_FIT_IN_MEM_TOKEN);
407}
408
409"ON" {
410 return(PARS_ON_TOKEN);
411}
412
413"DECLARE" {
414 return(PARS_DECLARE_TOKEN);
415}
416
417"CURSOR" {
418 return(PARS_CURSOR_TOKEN);
419}
420
421"OPEN" {
422 return(PARS_OPEN_TOKEN);
423}
424
425"FETCH" {
426 return(PARS_FETCH_TOKEN);
427}
428
429"CLOSE" {
430 return(PARS_CLOSE_TOKEN);
431}
432
433"NOTFOUND" {
434 return(PARS_NOTFOUND_TOKEN);
435}
436
437"TO_CHAR" {
438 return(PARS_TO_CHAR_TOKEN);
439}
440
441"TO_NUMBER" {
442 return(PARS_TO_NUMBER_TOKEN);
443}
444
445"TO_BINARY" {
446 return(PARS_TO_BINARY_TOKEN);
447}
448
449"BINARY_TO_NUMBER" {
450 return(PARS_BINARY_TO_NUMBER_TOKEN);
451}
452
453"SUBSTR" {
454 return(PARS_SUBSTR_TOKEN);
455}
456
457"REPLSTR" {
458 return(PARS_REPLSTR_TOKEN);
459}
460
461"CONCAT" {
462 return(PARS_CONCAT_TOKEN);
463}
464
465"INSTR" {
466 return(PARS_INSTR_TOKEN);
467}
468
469"LENGTH" {
470 return(PARS_LENGTH_TOKEN);
471}
472
473"SYSDATE" {
474 return(PARS_SYSDATE_TOKEN);
475}
476
477"PRINTF" {
478 return(PARS_PRINTF_TOKEN);
479}
480
481"ASSERT" {
482 return(PARS_ASSERT_TOKEN);
483}
484
485"RND" {
486 return(PARS_RND_TOKEN);
487}
488
489"RND_STR" {
490 return(PARS_RND_STR_TOKEN);
491}
492
493"ROW_PRINTF" {
494 return(PARS_ROW_PRINTF_TOKEN);
495}
496
497"COMMIT" {
498 return(PARS_COMMIT_TOKEN);
499}
500
501"ROLLBACK" {
502 return(PARS_ROLLBACK_TOKEN);
503}
504
505"WORK" {
506 return(PARS_WORK_TOKEN);
507}
508
509"UNSIGNED" {
510 return(PARS_UNSIGNED_TOKEN);
511}
512
513"EXIT" {
514 return(PARS_EXIT_TOKEN);
515}
516
517"FUNCTION" {
518 return(PARS_FUNCTION_TOKEN);
519}
520
521"LOCK" {
522 return(PARS_LOCK_TOKEN);
523}
524
525"SHARE" {
526 return(PARS_SHARE_TOKEN);
527}
528
529"MODE" {
530 return(PARS_MODE_TOKEN);
531}
532
533{ID} {
534 innodb_lval = sym_tab_add_id(pars_sym_tab_global,
535 (byte*)yytext,
536 strlen(yytext));
537 return(PARS_ID_TOKEN);
538}
539
540".." {
541 return(PARS_DDOT_TOKEN);
542}
543
544":=" {
545 return(PARS_ASSIGN_TOKEN);
546}
547
548"<=" {
549 return(PARS_LE_TOKEN);
550}
551
552">=" {
553 return(PARS_GE_TOKEN);
554}
555
556"<>" {
557 return(PARS_NE_TOKEN);
558}
559
560"(" {
561
562 return((int)(*yytext));
563}
564
565"=" {
566
567 return((int)(*yytext));
568}
569
570">" {
571
572 return((int)(*yytext));
573}
574
575"<" {
576
577 return((int)(*yytext));
578}
579
580"," {
581
582 return((int)(*yytext));
583}
584
585";" {
586
587 return((int)(*yytext));
588}
589
590")" {
591
592 return((int)(*yytext));
593}
594
595"+" {
596
597 return((int)(*yytext));
598}
599
600"-" {
601
602 return((int)(*yytext));
603}
604
605"*" {
606
607 return((int)(*yytext));
608}
609
610"/" {
611
612 return((int)(*yytext));
613}
614
615"%" {
616
617 return((int)(*yytext));
618}
619
620"{" {
621
622 return((int)(*yytext));
623}
624
625"}" {
626
627 return((int)(*yytext));
628}
629
630"?" {
631
632 return((int)(*yytext));
633}
634
635"/*" BEGIN(comment); /* eat up comment */
636
637<comment>[^*]*
638<comment>"*"+[^*/]*
639<comment>"*"+"/" BEGIN(INITIAL);
640
641[ \t\n]+ /* eat up whitespace */
642
643
644. {
645 fprintf(stderr,"Unrecognized character: %02x\n",
646 *yytext);
647
648 ut_error;
649
650 return(0);
651}
652
653%%
654
655/* yylex_destroy() is not defined before Flex 2.5.9
656 so we attempt to define something that should be good enough
657 for old Flex - such as that found on CentOS 5
658*/
659#if !defined(YY_FLEX_MAJOR_VERSION) || YY_FLEX_MAJOR_VERSION < 2 \
660 || (YY_FLEX_MAJOR_VERSION == 2 \
661 && (!defined(YY_FLEX_MINOR_VERSION) || YY_FLEX_MINOR_VERSION < 5 \
662 || (YY_FLEX_MINOR_VERSION == 5 \
663 && (!defined(YY_FLEX_SUBMINOR_VERSION) \
664 || YY_FLEX_SUBMINOR_VERSION < 9))))
665# define yylex_destroy() yy_delete_buffer(YY_CURRENT_BUFFER)
666#endif
667
668/**********************************************************************
669Release any resources used by the lexer. */
670UNIV_INTERN
671void
673/*==================*/
674{
675 yylex_destroy();
676 free(stringbuf);
677 stringbuf = NULL;
678 stringbuf_len_alloc = stringbuf_len = 0;
679}
UNIV_INTERN void pars_lexer_close(void)
Definition pars0lex.l:672