~drizzle-trunk/drizzle/development

641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
1
/******************************************************
2
SQL parser lexical analyzer: input file for the GNU Flex lexer generator
3
4
(c) 1997 Innobase Oy
5
6
Created 12/14/1997 Heikki Tuuri
7
Published under the GPL version 2
8
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.
12
13
How to make the InnoDB parser and lexer C files:
14
15
1. Run ./make_flex.sh to generate lexer files.
16
17
2. Run ./make_bison.sh to generate parser files.
18
19
These instructions seem to work at least with bison-1.875d and flex-2.5.31 on
20
Linux.
21
*******************************************************/
22
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
36
37
%{
38
#define YYSTYPE que_node_t*
39
40
#include "univ.i"
41
#include "pars0pars.h"
42
#include "pars0grm.h"
43
#include "pars0sym.h"
44
#include "mem0mem.h"
45
#include "os0proc.h"
46
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
51
52
#define YY_INPUT(buf, result, max_size) pars_get_lex_chars(buf, &result, max_size)
53
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 */
65
{
66
	if (stringbuf == NULL) {
67
		stringbuf = malloc(1);
68
		stringbuf_len_alloc = 1;
69
	}
70
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
	}
77
78
	memcpy(stringbuf + stringbuf_len, str, len);
79
	stringbuf_len += len;
80
}
81
82
%}
83
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]+
88
89
%x comment
90
%x quoted
91
%x id
92
%%
93
94
{DIGIT}+	{
95
			yylval = sym_tab_add_int_lit(pars_sym_tab_global,
96
								atoi(yytext));
97
			return(PARS_INT_LIT);
98
}
99
100
{DIGIT}+"."{DIGIT}* {
101
			ut_error;	/* not implemented */
102
103
			return(PARS_FLOAT_LIT);
104
}
105
106
{BOUND_LIT}	{
107
			ulint	type;
108
109
			yylval = sym_tab_add_bound_lit(pars_sym_tab_global,
110
				yytext + 1, &type);
111
112
			return((int) type);
113
}
114
115
{BOUND_ID}	{
116
			yylval = sym_tab_add_bound_id(pars_sym_tab_global,
117
				yytext + 1);
118
119
			return(PARS_ID_TOKEN);
120
}
121
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.
126
127
In the state 'quoted', only two actions are possible (defined below). */
128
			BEGIN(quoted);
129
			stringbuf_len = 0;
130
}
131
<quoted>[^\']+	{
132
			/* Got a sequence of characters other than "'":
133
			append to string buffer */
134
			string_append(yytext, yyleng);
135
}
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 "'". */
142
143
			string_append(yytext, yyleng / 2);
144
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. */
150
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
			}
158
}
159
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.
164
165
In the state 'id', only two actions are possible (defined below). */
166
			BEGIN(id);
167
			stringbuf_len = 0;
168
}
169
<id>[^\"]+	{
170
			/* Got a sequence of characters other than '"':
171
			append to string buffer */
172
			string_append(yytext, yyleng);
173
}
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 '"'. */
180
181
			string_append(yytext, yyleng / 2);
182
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. */
188
189
			if (yyleng % 2) {
190
				BEGIN(INITIAL);
191
				yylval = sym_tab_add_id(
192
					pars_sym_tab_global,
193
					(byte*) stringbuf, stringbuf_len);
194
195
				return(PARS_ID_TOKEN);
196
			}
197
}
198
199
"NULL"		{
200
			yylval = sym_tab_add_null_lit(pars_sym_tab_global);
201
202
			return(PARS_NULL_LIT);
203
}
204
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);
210
}
211
212
"AND"		{
213
			return(PARS_AND_TOKEN);
214
}
215
216
"OR"		{
217
			return(PARS_OR_TOKEN);
218
}
219
220
"NOT"		{
221
			return(PARS_NOT_TOKEN);
222
}
223
224
"PROCEDURE"	{
225
			return(PARS_PROCEDURE_TOKEN);
226
}
227
228
"IN"		{
229
			return(PARS_IN_TOKEN);
230
}
231
232
"OUT"		{
233
			return(PARS_OUT_TOKEN);
234
}
235
236
"BINARY"	{
237
	 		return(PARS_BINARY_TOKEN);
238
}
239
240
"BLOB"		{
241
	 		return(PARS_BLOB_TOKEN);
242
}
243
244
"INT"		{
245
	 		return(PARS_INT_TOKEN);
246
}
247
248
"INTEGER"	{
249
	 		return(PARS_INT_TOKEN);
250
}
251
252
"FLOAT"		{
253
	 		return(PARS_FLOAT_TOKEN);
254
}
255
256
"CHAR"		{
257
	 		return(PARS_CHAR_TOKEN);
258
}
259
260
"IS"		{
261
			return(PARS_IS_TOKEN);
262
}
263
264
"BEGIN"		{
265
			return(PARS_BEGIN_TOKEN);
266
}
267
268
"END"		{
269
			return(PARS_END_TOKEN);
270
}
271
272
"IF"		{
273
			return(PARS_IF_TOKEN);
274
}
275
276
"THEN"		{
277
			return(PARS_THEN_TOKEN);
278
}
279
280
"ELSE"		{
281
			return(PARS_ELSE_TOKEN);
282
}
283
284
"ELSIF"		{
285
			return(PARS_ELSIF_TOKEN);
286
}
287
288
"LOOP"		{
289
			return(PARS_LOOP_TOKEN);
290
}
291
292
"WHILE"		{
293
			return(PARS_WHILE_TOKEN);
294
}
295
296
"RETURN"	{
297
			return(PARS_RETURN_TOKEN);
298
}
299
300
"SELECT"	{
301
			return(PARS_SELECT_TOKEN);
302
}
303
304
"SUM"		{
305
			return(PARS_SUM_TOKEN);
306
}
307
308
"COUNT"		{
309
			return(PARS_COUNT_TOKEN);
310
}
311
312
"DISTINCT"	{
313
			return(PARS_DISTINCT_TOKEN);
314
}
315
316
"FROM"		{
317
			return(PARS_FROM_TOKEN);
318
}
319
320
"WHERE"		{
321
			return(PARS_WHERE_TOKEN);
322
}
323
324
"FOR"		{
325
			return(PARS_FOR_TOKEN);
326
}
327
328
"READ"		{
329
			return(PARS_READ_TOKEN);
330
}
331
332
"ORDER"		{
333
			return(PARS_ORDER_TOKEN);
334
}
335
336
"BY"		{
337
			return(PARS_BY_TOKEN);
338
}
339
340
"ASC"		{
341
			return(PARS_ASC_TOKEN);
342
}
343
344
"DESC"		{
345
			return(PARS_DESC_TOKEN);
346
}
347
348
"INSERT"	{
349
			return(PARS_INSERT_TOKEN);
350
}
351
352
"INTO"		{
353
			return(PARS_INTO_TOKEN);
354
}
355
356
"VALUES"	{
357
			return(PARS_VALUES_TOKEN);
358
}
359
360
"UPDATE"	{
361
			return(PARS_UPDATE_TOKEN);
362
}
363
364
"SET"		{
365
			return(PARS_SET_TOKEN);
366
}
367
368
"DELETE"	{
369
			return(PARS_DELETE_TOKEN);
370
}
371
372
"CURRENT"	{
373
			return(PARS_CURRENT_TOKEN);
374
}
375
376
"OF"		{
377
			return(PARS_OF_TOKEN);
378
}
379
380
"CREATE"	{
381
			return(PARS_CREATE_TOKEN);
382
}
383
384
"TABLE"		{
385
			return(PARS_TABLE_TOKEN);
386
}
387
388
"INDEX"		{
389
	 		return(PARS_INDEX_TOKEN);
390
}
391
392
"UNIQUE"	{
393
	 		return(PARS_UNIQUE_TOKEN);
394
}
395
396
"CLUSTERED"	{
397
	 		return(PARS_CLUSTERED_TOKEN);
398
}
399
400
"DOES_NOT_FIT_IN_MEMORY"	{
401
			return(PARS_DOES_NOT_FIT_IN_MEM_TOKEN);
402
}
403
404
"ON"		{
405
	 		return(PARS_ON_TOKEN);
406
}
407
408
"DECLARE"	{
409
			return(PARS_DECLARE_TOKEN);
410
}
411
412
"CURSOR"	{
413
			return(PARS_CURSOR_TOKEN);
414
}
415
416
"OPEN"	{
417
			return(PARS_OPEN_TOKEN);
418
}
419
420
"FETCH"	{
421
			return(PARS_FETCH_TOKEN);
422
}
423
424
"CLOSE"	{
425
			return(PARS_CLOSE_TOKEN);
426
}
427
428
"NOTFOUND"	{
429
			return(PARS_NOTFOUND_TOKEN);
430
}
431
432
"TO_CHAR"	{
433
			return(PARS_TO_CHAR_TOKEN);
434
}
435
436
"TO_NUMBER"	{
437
			return(PARS_TO_NUMBER_TOKEN);
438
}
439
440
"TO_BINARY"	{
441
			return(PARS_TO_BINARY_TOKEN);
442
}
443
444
"BINARY_TO_NUMBER" {
445
			return(PARS_BINARY_TO_NUMBER_TOKEN);
446
}
447
448
"SUBSTR"	{
449
			return(PARS_SUBSTR_TOKEN);
450
}
451
452
"REPLSTR"	{
453
			return(PARS_REPLSTR_TOKEN);
454
}
455
456
"CONCAT"	{
457
			return(PARS_CONCAT_TOKEN);
458
}
459
460
"INSTR"		{
461
			return(PARS_INSTR_TOKEN);
462
}
463
464
"LENGTH"	{
465
			return(PARS_LENGTH_TOKEN);
466
}
467
468
"SYSDATE"	{
469
			return(PARS_SYSDATE_TOKEN);
470
}
471
472
"PRINTF"	{
473
			return(PARS_PRINTF_TOKEN);
474
}
475
476
"ASSERT"	{
477
			return(PARS_ASSERT_TOKEN);
478
}
479
480
"RND"		{
481
			return(PARS_RND_TOKEN);
482
}
483
484
"RND_STR"	{
485
			return(PARS_RND_STR_TOKEN);
486
}
487
488
"ROW_PRINTF"	{
489
			return(PARS_ROW_PRINTF_TOKEN);
490
}
491
492
"COMMIT"	{
493
			return(PARS_COMMIT_TOKEN);
494
}
495
496
"ROLLBACK"	{
497
			return(PARS_ROLLBACK_TOKEN);
498
}
499
500
"WORK"		{
501
			return(PARS_WORK_TOKEN);
502
}
503
504
"UNSIGNED"	{
505
			return(PARS_UNSIGNED_TOKEN);
506
}
507
508
"EXIT"		{
509
			return(PARS_EXIT_TOKEN);
510
}
511
512
"FUNCTION"	{
513
			return(PARS_FUNCTION_TOKEN);
514
}
515
516
"LOCK"	{
517
			return(PARS_LOCK_TOKEN);
518
}
519
520
"SHARE"	{
521
			return(PARS_SHARE_TOKEN);
522
}
523
524
"MODE"	{
525
			return(PARS_MODE_TOKEN);
526
}
527
528
{ID}		{
529
			yylval = sym_tab_add_id(pars_sym_tab_global,
530
							(byte*)yytext,
531
							ut_strlen(yytext));
532
			return(PARS_ID_TOKEN);
533
}
534
535
".."		{
536
			return(PARS_DDOT_TOKEN);
537
}
538
539
":="		{
540
			return(PARS_ASSIGN_TOKEN);
541
}
542
543
"<="		{
544
			return(PARS_LE_TOKEN);
545
}
546
547
">="		{
548
			return(PARS_GE_TOKEN);
549
}
550
551
"<>"		{
552
			return(PARS_NE_TOKEN);
553
}
554
555
"("		{
556
557
			return((int)(*yytext));
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
"/*"			BEGIN(comment); /* eat up comment */
631
632
<comment>[^*]*
633
<comment>"*"+[^*/]*
634
<comment>"*"+"/"        BEGIN(INITIAL);
635
636
[ \t\n]+		/* eat up whitespace */
637
638
639
.		{
640
			fprintf(stderr,"Unrecognized character: %02x\n",
641
				*yytext);
642
643
			ut_error;
644
645
			return(0);
646
}
647
648
%%