1
/******************************************************
2
SQL parser: input file for the GNU Bison parser generator
6
Created 12/14/1997 Heikki Tuuri
7
Published under the GPL version 2
9
Look from pars0lex.l for instructions how to generate the C files for
11
*******************************************************/
14
/* The value of the semantic attribute is a pointer to a query tree node
18
#include <math.h> /* Can't be before univ.i */
19
#include "pars0pars.h"
21
#include "que0types.h"
25
#define YYSTYPE que_node_t*
27
/* #define __STDC__ */
36
%token PARS_FIXBINARY_LIT
46
%token PARS_PROCEDURE_TOKEN
49
%token PARS_BINARY_TOKEN
50
%token PARS_BLOB_TOKEN
52
%token PARS_INTEGER_TOKEN
53
%token PARS_FLOAT_TOKEN
54
%token PARS_CHAR_TOKEN
56
%token PARS_BEGIN_TOKEN
59
%token PARS_THEN_TOKEN
60
%token PARS_ELSE_TOKEN
61
%token PARS_ELSIF_TOKEN
62
%token PARS_LOOP_TOKEN
63
%token PARS_WHILE_TOKEN
64
%token PARS_RETURN_TOKEN
65
%token PARS_SELECT_TOKEN
67
%token PARS_COUNT_TOKEN
68
%token PARS_DISTINCT_TOKEN
69
%token PARS_FROM_TOKEN
70
%token PARS_WHERE_TOKEN
72
%token PARS_DDOT_TOKEN
73
%token PARS_READ_TOKEN
74
%token PARS_ORDER_TOKEN
77
%token PARS_DESC_TOKEN
78
%token PARS_INSERT_TOKEN
79
%token PARS_INTO_TOKEN
80
%token PARS_VALUES_TOKEN
81
%token PARS_UPDATE_TOKEN
83
%token PARS_DELETE_TOKEN
84
%token PARS_CURRENT_TOKEN
86
%token PARS_CREATE_TOKEN
87
%token PARS_TABLE_TOKEN
88
%token PARS_INDEX_TOKEN
89
%token PARS_UNIQUE_TOKEN
90
%token PARS_CLUSTERED_TOKEN
91
%token PARS_DOES_NOT_FIT_IN_MEM_TOKEN
93
%token PARS_ASSIGN_TOKEN
94
%token PARS_DECLARE_TOKEN
95
%token PARS_CURSOR_TOKEN
97
%token PARS_OPEN_TOKEN
98
%token PARS_FETCH_TOKEN
99
%token PARS_CLOSE_TOKEN
100
%token PARS_NOTFOUND_TOKEN
101
%token PARS_TO_CHAR_TOKEN
102
%token PARS_TO_NUMBER_TOKEN
103
%token PARS_TO_BINARY_TOKEN
104
%token PARS_BINARY_TO_NUMBER_TOKEN
105
%token PARS_SUBSTR_TOKEN
106
%token PARS_REPLSTR_TOKEN
107
%token PARS_CONCAT_TOKEN
108
%token PARS_INSTR_TOKEN
109
%token PARS_LENGTH_TOKEN
110
%token PARS_SYSDATE_TOKEN
111
%token PARS_PRINTF_TOKEN
112
%token PARS_ASSERT_TOKEN
113
%token PARS_RND_TOKEN
114
%token PARS_RND_STR_TOKEN
115
%token PARS_ROW_PRINTF_TOKEN
116
%token PARS_COMMIT_TOKEN
117
%token PARS_ROLLBACK_TOKEN
118
%token PARS_WORK_TOKEN
119
%token PARS_UNSIGNED_TOKEN
120
%token PARS_EXIT_TOKEN
121
%token PARS_FUNCTION_TOKEN
122
%token PARS_LOCK_TOKEN
123
%token PARS_SHARE_TOKEN
124
%token PARS_MODE_TOKEN
126
%left PARS_AND_TOKEN PARS_OR_TOKEN
128
%left '=' '<' '>' PARS_GE_TOKEN PARS_LE_TOKEN
131
%left NEG /* negation--unary minus */
134
/* Grammar follows */
138
procedure_definition ';'
141
stored_procedure_call
142
| predefined_procedure_call ';'
143
| while_statement ';'
147
| return_statement ';'
148
| assignment_statement ';'
149
| select_statement ';'
150
| insert_statement ';'
151
| row_printf_statement ';'
152
| delete_statement_searched ';'
153
| delete_statement_positioned ';'
154
| update_statement_searched ';'
155
| update_statement_positioned ';'
156
| open_cursor_statement ';'
157
| fetch_statement ';'
158
| close_cursor_statement ';'
159
| commit_statement ';'
160
| rollback_statement ';'
166
statement { $$ = que_node_list_add_last(NULL, $1); }
167
| statement_list statement
168
{ $$ = que_node_list_add_last($1, $2); }
172
PARS_ID_TOKEN { $$ = $1;}
173
| function_name '(' exp_list ')'
174
{ $$ = pars_func($1, $3); }
175
| PARS_INT_LIT { $$ = $1;}
176
| PARS_FLOAT_LIT { $$ = $1;}
177
| PARS_STR_LIT { $$ = $1;}
178
| PARS_FIXBINARY_LIT { $$ = $1;}
179
| PARS_BLOB_LIT { $$ = $1;}
180
| PARS_NULL_LIT { $$ = $1;}
181
| PARS_SQL_TOKEN { $$ = $1;}
182
| exp '+' exp { $$ = pars_op('+', $1, $3); }
183
| exp '-' exp { $$ = pars_op('-', $1, $3); }
184
| exp '*' exp { $$ = pars_op('*', $1, $3); }
185
| exp '/' exp { $$ = pars_op('/', $1, $3); }
186
| '-' exp %prec NEG { $$ = pars_op('-', $2, NULL); }
187
| '(' exp ')' { $$ = $2; }
188
| exp '=' exp { $$ = pars_op('=', $1, $3); }
189
| exp '<' exp { $$ = pars_op('<', $1, $3); }
190
| exp '>' exp { $$ = pars_op('>', $1, $3); }
191
| exp PARS_GE_TOKEN exp { $$ = pars_op(PARS_GE_TOKEN, $1, $3); }
192
| exp PARS_LE_TOKEN exp { $$ = pars_op(PARS_LE_TOKEN, $1, $3); }
193
| exp PARS_NE_TOKEN exp { $$ = pars_op(PARS_NE_TOKEN, $1, $3); }
194
| exp PARS_AND_TOKEN exp{ $$ = pars_op(PARS_AND_TOKEN, $1, $3); }
195
| exp PARS_OR_TOKEN exp { $$ = pars_op(PARS_OR_TOKEN, $1, $3); }
196
| PARS_NOT_TOKEN exp { $$ = pars_op(PARS_NOT_TOKEN, $2, NULL); }
197
| PARS_ID_TOKEN '%' PARS_NOTFOUND_TOKEN
198
{ $$ = pars_op(PARS_NOTFOUND_TOKEN, $1, NULL); }
199
| PARS_SQL_TOKEN '%' PARS_NOTFOUND_TOKEN
200
{ $$ = pars_op(PARS_NOTFOUND_TOKEN, $1, NULL); }
204
PARS_TO_CHAR_TOKEN { $$ = &pars_to_char_token; }
205
| PARS_TO_NUMBER_TOKEN { $$ = &pars_to_number_token; }
206
| PARS_TO_BINARY_TOKEN { $$ = &pars_to_binary_token; }
207
| PARS_BINARY_TO_NUMBER_TOKEN
208
{ $$ = &pars_binary_to_number_token; }
209
| PARS_SUBSTR_TOKEN { $$ = &pars_substr_token; }
210
| PARS_CONCAT_TOKEN { $$ = &pars_concat_token; }
211
| PARS_INSTR_TOKEN { $$ = &pars_instr_token; }
212
| PARS_LENGTH_TOKEN { $$ = &pars_length_token; }
213
| PARS_SYSDATE_TOKEN { $$ = &pars_sysdate_token; }
214
| PARS_RND_TOKEN { $$ = &pars_rnd_token; }
215
| PARS_RND_STR_TOKEN { $$ = &pars_rnd_str_token; }
221
| question_mark_list ',' '?'
224
stored_procedure_call:
225
'{' PARS_ID_TOKEN '(' question_mark_list ')' '}'
226
{ $$ = pars_stored_procedure_call($2); }
229
predefined_procedure_call:
230
predefined_procedure_name '(' exp_list ')'
231
{ $$ = pars_procedure_call($1, $3); }
234
predefined_procedure_name:
235
PARS_REPLSTR_TOKEN { $$ = &pars_replstr_token; }
236
| PARS_PRINTF_TOKEN { $$ = &pars_printf_token; }
237
| PARS_ASSERT_TOKEN { $$ = &pars_assert_token; }
241
PARS_ID_TOKEN '(' ')' { $$ = $1; }
245
PARS_ID_TOKEN { $$ = que_node_list_add_last(NULL, $1); }
246
| table_list ',' PARS_ID_TOKEN
247
{ $$ = que_node_list_add_last($1, $3); }
251
/* Nothing */ { $$ = NULL; }
252
| PARS_ID_TOKEN { $$ = que_node_list_add_last(NULL, $1); }
253
| variable_list ',' PARS_ID_TOKEN
254
{ $$ = que_node_list_add_last($1, $3); }
258
/* Nothing */ { $$ = NULL; }
259
| exp { $$ = que_node_list_add_last(NULL, $1);}
260
| exp_list ',' exp { $$ = que_node_list_add_last($1, $3); }
265
| PARS_COUNT_TOKEN '(' '*' ')'
266
{ $$ = pars_func(&pars_count_token,
267
que_node_list_add_last(NULL,
269
pars_sym_tab_global, 1))); }
270
| PARS_COUNT_TOKEN '(' PARS_DISTINCT_TOKEN PARS_ID_TOKEN ')'
271
{ $$ = pars_func(&pars_count_token,
272
que_node_list_add_last(NULL,
273
pars_func(&pars_distinct_token,
274
que_node_list_add_last(
276
| PARS_SUM_TOKEN '(' exp ')'
277
{ $$ = pars_func(&pars_sum_token,
278
que_node_list_add_last(NULL,
283
/* Nothing */ { $$ = NULL; }
284
| select_item { $$ = que_node_list_add_last(NULL, $1); }
285
| select_item_list ',' select_item
286
{ $$ = que_node_list_add_last($1, $3); }
290
'*' { $$ = pars_select_list(&pars_star_denoter,
292
| select_item_list PARS_INTO_TOKEN variable_list
293
{ $$ = pars_select_list($1, $3); }
294
| select_item_list { $$ = pars_select_list($1, NULL); }
298
/* Nothing */ { $$ = NULL; }
299
| PARS_WHERE_TOKEN exp { $$ = $2; }
303
/* Nothing */ { $$ = NULL; }
304
| PARS_FOR_TOKEN PARS_UPDATE_TOKEN
305
{ $$ = &pars_update_token; }
309
/* Nothing */ { $$ = NULL; }
310
| PARS_LOCK_TOKEN PARS_IN_TOKEN PARS_SHARE_TOKEN PARS_MODE_TOKEN
311
{ $$ = &pars_share_token; }
315
/* Nothing */ { $$ = &pars_asc_token; }
316
| PARS_ASC_TOKEN { $$ = &pars_asc_token; }
317
| PARS_DESC_TOKEN { $$ = &pars_desc_token; }
321
/* Nothing */ { $$ = NULL; }
322
| PARS_ORDER_TOKEN PARS_BY_TOKEN PARS_ID_TOKEN order_direction
323
{ $$ = pars_order_by($3, $4); }
327
PARS_SELECT_TOKEN select_list
328
PARS_FROM_TOKEN table_list
332
order_by_clause { $$ = pars_select_statement($2, $4, $5,
336
insert_statement_start:
337
PARS_INSERT_TOKEN PARS_INTO_TOKEN
338
PARS_ID_TOKEN { $$ = $3; }
342
insert_statement_start PARS_VALUES_TOKEN '(' exp_list ')'
343
{ $$ = pars_insert_statement($1, $4, NULL); }
344
| insert_statement_start select_statement
345
{ $$ = pars_insert_statement($1, NULL, $2); }
349
PARS_ID_TOKEN '=' exp { $$ = pars_column_assignment($1, $3); }
352
column_assignment_list:
353
column_assignment { $$ = que_node_list_add_last(NULL, $1); }
354
| column_assignment_list ',' column_assignment
355
{ $$ = que_node_list_add_last($1, $3); }
360
PARS_CURRENT_TOKEN PARS_OF_TOKEN
361
PARS_ID_TOKEN { $$ = $4; }
364
update_statement_start:
365
PARS_UPDATE_TOKEN PARS_ID_TOKEN
367
column_assignment_list { $$ = pars_update_statement_start(FALSE,
371
update_statement_searched:
372
update_statement_start
373
search_condition { $$ = pars_update_statement($1, NULL, $2); }
376
update_statement_positioned:
377
update_statement_start
378
cursor_positioned { $$ = pars_update_statement($1, $2, NULL); }
381
delete_statement_start:
382
PARS_DELETE_TOKEN PARS_FROM_TOKEN
383
PARS_ID_TOKEN { $$ = pars_update_statement_start(TRUE,
387
delete_statement_searched:
388
delete_statement_start
389
search_condition { $$ = pars_update_statement($1, NULL, $2); }
392
delete_statement_positioned:
393
delete_statement_start
394
cursor_positioned { $$ = pars_update_statement($1, $2, NULL); }
397
row_printf_statement:
398
PARS_ROW_PRINTF_TOKEN select_statement
399
{ $$ = pars_row_printf_statement($2); }
402
assignment_statement:
403
PARS_ID_TOKEN PARS_ASSIGN_TOKEN exp
404
{ $$ = pars_assignment_statement($1, $3); }
409
exp PARS_THEN_TOKEN statement_list
410
{ $$ = pars_elsif_element($2, $4); }
414
elsif_element { $$ = que_node_list_add_last(NULL, $1); }
415
| elsif_list elsif_element
416
{ $$ = que_node_list_add_last($1, $2); }
420
/* Nothing */ { $$ = NULL; }
421
| PARS_ELSE_TOKEN statement_list
423
| elsif_list { $$ = $1; }
427
PARS_IF_TOKEN exp PARS_THEN_TOKEN statement_list
429
PARS_END_TOKEN PARS_IF_TOKEN
430
{ $$ = pars_if_statement($2, $4, $5); }
434
PARS_WHILE_TOKEN exp PARS_LOOP_TOKEN statement_list
435
PARS_END_TOKEN PARS_LOOP_TOKEN
436
{ $$ = pars_while_statement($2, $4); }
440
PARS_FOR_TOKEN PARS_ID_TOKEN PARS_IN_TOKEN
441
exp PARS_DDOT_TOKEN exp
442
PARS_LOOP_TOKEN statement_list
443
PARS_END_TOKEN PARS_LOOP_TOKEN
444
{ $$ = pars_for_statement($2, $4, $6, $8); }
448
PARS_EXIT_TOKEN { $$ = pars_exit_statement(); }
452
PARS_RETURN_TOKEN { $$ = pars_return_statement(); }
455
open_cursor_statement:
456
PARS_OPEN_TOKEN PARS_ID_TOKEN
457
{ $$ = pars_open_statement(
458
ROW_SEL_OPEN_CURSOR, $2); }
461
close_cursor_statement:
462
PARS_CLOSE_TOKEN PARS_ID_TOKEN
463
{ $$ = pars_open_statement(
464
ROW_SEL_CLOSE_CURSOR, $2); }
468
PARS_FETCH_TOKEN PARS_ID_TOKEN PARS_INTO_TOKEN variable_list
469
{ $$ = pars_fetch_statement($2, $4, NULL); }
470
| PARS_FETCH_TOKEN PARS_ID_TOKEN PARS_INTO_TOKEN user_function_call
471
{ $$ = pars_fetch_statement($2, NULL, $4); }
475
PARS_ID_TOKEN type_name opt_column_len opt_unsigned opt_not_null
476
{ $$ = pars_column_def($1, $2, $3, $4, $5); }
480
column_def { $$ = que_node_list_add_last(NULL, $1); }
481
| column_def_list ',' column_def
482
{ $$ = que_node_list_add_last($1, $3); }
486
/* Nothing */ { $$ = NULL; }
487
| '(' PARS_INT_LIT ')'
492
/* Nothing */ { $$ = NULL; }
493
| PARS_UNSIGNED_TOKEN
494
{ $$ = &pars_int_token;
495
/* pass any non-NULL pointer */ }
499
/* Nothing */ { $$ = NULL; }
500
| PARS_NOT_TOKEN PARS_NULL_LIT
501
{ $$ = &pars_int_token;
502
/* pass any non-NULL pointer */ }
506
/* Nothing */ { $$ = NULL; }
507
| PARS_DOES_NOT_FIT_IN_MEM_TOKEN
508
{ $$ = &pars_int_token;
509
/* pass any non-NULL pointer */ }
513
PARS_CREATE_TOKEN PARS_TABLE_TOKEN
514
PARS_ID_TOKEN '(' column_def_list ')'
515
not_fit_in_memory { $$ = pars_create_table($3, $5, $7); }
519
PARS_ID_TOKEN { $$ = que_node_list_add_last(NULL, $1); }
520
| column_list ',' PARS_ID_TOKEN
521
{ $$ = que_node_list_add_last($1, $3); }
525
/* Nothing */ { $$ = NULL; }
526
| PARS_UNIQUE_TOKEN { $$ = &pars_unique_token; }
530
/* Nothing */ { $$ = NULL; }
531
| PARS_CLUSTERED_TOKEN { $$ = &pars_clustered_token; }
535
PARS_CREATE_TOKEN unique_def
538
PARS_ID_TOKEN PARS_ON_TOKEN PARS_ID_TOKEN
539
'(' column_list ')' { $$ = pars_create_index($2, $3, $5, $7, $9); }
543
PARS_COMMIT_TOKEN PARS_WORK_TOKEN
544
{ $$ = pars_commit_statement(); }
548
PARS_ROLLBACK_TOKEN PARS_WORK_TOKEN
549
{ $$ = pars_rollback_statement(); }
553
PARS_INT_TOKEN { $$ = &pars_int_token; }
554
| PARS_INTEGER_TOKEN { $$ = &pars_int_token; }
555
| PARS_CHAR_TOKEN { $$ = &pars_char_token; }
556
| PARS_BINARY_TOKEN { $$ = &pars_binary_token; }
557
| PARS_BLOB_TOKEN { $$ = &pars_blob_token; }
560
parameter_declaration:
561
PARS_ID_TOKEN PARS_IN_TOKEN type_name
562
{ $$ = pars_parameter_declaration($1,
564
| PARS_ID_TOKEN PARS_OUT_TOKEN type_name
565
{ $$ = pars_parameter_declaration($1,
569
parameter_declaration_list:
570
/* Nothing */ { $$ = NULL; }
571
| parameter_declaration { $$ = que_node_list_add_last(NULL, $1); }
572
| parameter_declaration_list ',' parameter_declaration
573
{ $$ = que_node_list_add_last($1, $3); }
576
variable_declaration:
577
PARS_ID_TOKEN type_name ';'
578
{ $$ = pars_variable_declaration($1, $2); }
581
variable_declaration_list:
583
| variable_declaration
584
| variable_declaration_list variable_declaration
588
PARS_DECLARE_TOKEN PARS_CURSOR_TOKEN PARS_ID_TOKEN
589
PARS_IS_TOKEN select_statement ';'
590
{ $$ = pars_cursor_declaration($3, $5); }
593
function_declaration:
594
PARS_DECLARE_TOKEN PARS_FUNCTION_TOKEN PARS_ID_TOKEN ';'
595
{ $$ = pars_function_declaration($3); }
600
| function_declaration
606
| declaration_list declaration
609
procedure_definition:
610
PARS_PROCEDURE_TOKEN PARS_ID_TOKEN '(' parameter_declaration_list ')'
612
variable_declaration_list
616
PARS_END_TOKEN { $$ = pars_procedure_definition($2, $4,