~drizzle-trunk/drizzle/development

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