1
%{ /*** C/C++ Declarations ***/
3
//////////////////////////////////////////////////////////////////////////
5
// pgScript - PostgreSQL Tools
6
// RCS-ID: $Id: pgsParser.yy,v 1.6 2008/08/10 22:11:29 pgunittest Exp $
7
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
8
// This software is released under the BSD Licence
10
//////////////////////////////////////////////////////////////////////////
12
#include "pgscript/pgScript.h"
13
#include "pgscript/statements/pgsStatements.h"
14
#include "pgscript/expressions/pgsExpressions.h"
15
#include "pgscript/objects/pgsObjects.h"
16
#include "pgscript/utilities/pgsContext.h"
20
/*** YACC/Bison declarations ***/
22
/* Require bison 2.3 or later */
25
/* Start symbol is named "start" */
26
%start translation_unit
28
/* Write out a header file containing the token defines */
31
/* Use newer C++ skeleton file */
34
/* Namespace to enclose parser in */
35
%name-prefix="pgscript"
37
/* Set the parser's class identifier */
38
%define "parser_class_name" "pgsParser"
40
/* Keep track of the current position within the input */
44
// Initialize the initial location object
45
@$.begin.filename = @$.end.filename;
48
/* The driver is passed by reference to the parser and to the scanner. This
49
* provides a simple but effective pure interface, not relying on global
51
%parse-param { class pgsDriver & driver }
53
/* Verbose error messages */
56
%token PGS_END 0 "END OF FILE"
58
%token PGS_WHILE "WHILE"
59
%token PGS_BREAK "BREAK"
60
%token PGS_RETURN "RETURN"
61
%token PGS_CONTINUE "CONTINUE"
63
%token PGS_ELSE "ELSE"
64
%token PGS_WAITFOR "WAITFOR"
67
%token PGS_OPEN "BEGIN (BLOCK)"
68
%token PGS_CLOSE "END (BLOCK)"
70
%token PGS_ASSERT "ASSERT"
71
%token PGS_PRINT "PRINT"
74
%token PGS_CNT_COLUMNS "COLUMNS"
75
%token PGS_CNT_LINES "LINES"
76
%token PGS_TRIM "TRIM"
77
%token PGS_RM_LINE "RMLINE"
78
%token PGS_CAST "CAST"
80
%token PGS_RECORD "RECORD"
82
%token PGS_INTEGER "INTEGER"
83
%token PGS_REAL "REAL"
84
%token PGS_STRING "STRING"
85
%token PGS_REGEX "REGEX"
86
%token PGS_FILE "FILE"
87
%token PGS_DATE "DATE"
88
%token PGS_TIME "TIME"
89
%token PGS_DATE_TIME "DATETIME"
90
%token PGS_REFERENCE "REFERENCE"
97
%token PGS_AND_OP "AND"
99
%token PGS_NOT_OP "NOT"
101
%token PGS_UNKNOWN "character"
107
const wxString * str;
109
pgsExpression * expr;
111
pgsStmtList * stmt_list;
114
%token PGS_SET_ASSIGN "SET @VARIABLE"
115
%token PGS_DECLARE_ASSGN "DECLARE @VARIABLE"
117
%token<str> PGS_ABORT "ABORT"
118
%token<str> PGS_ALTER "ALTER"
119
%token<str> PGS_ANALYZE "ANALYZE"
120
%token<str> PGS_BEGIN "BEGIN"
121
%token<str> PGS_CHECKPOINT "CHECKPOINT"
122
%token<str> PGS_CLOSE_ST "CLOSE"
123
%token<str> PGS_CLUSTER "CLUSTER"
124
%token<str> PGS_COMMENT "COMMENT"
125
%token<str> PGS_COMMIT "COMMIT"
126
%token<str> PGS_COPY "COPY"
127
%token<str> PGS_CREATE "CREATE"
128
%token<str> PGS_DEALLOCATE "DEALLOCATE"
129
%token<str> PGS_DECLARE "DECLARE"
130
%token<str> PGS_DELETE "DELETE"
131
%token<str> PGS_DISCARD "DISCARD"
132
%token<str> PGS_DROP "DROP"
133
%token<str> PGS_END_ST "END"
134
%token<str> PGS_EXECUTE "EXECUTE"
135
%token<str> PGS_EXPLAIN "EXPLAIN"
136
%token<str> PGS_FETCH "FETCH"
137
%token<str> PGS_GRANT "GRANT"
138
%token<str> PGS_INSERT "INSERT"
139
%token<str> PGS_LISTEN "LISTEN"
140
%token<str> PGS_LOAD "LOAD"
141
%token<str> PGS_LOCK "LOCK"
142
%token<str> PGS_MOVE "MOVE"
143
%token<str> PGS_NOTIFY "NOTIFY"
144
%token<str> PGS_PREPARE "PREPARE"
145
%token<str> PGS_REASSIGN "REASSIGN"
146
%token<str> PGS_REINDEX "REINDEX"
147
%token<str> PGS_RELEASE "RELEASE"
148
%token<str> PGS_RESET "RESET"
149
%token<str> PGS_REVOKE "REVOKE"
150
%token<str> PGS_ROLLBACK "ROLLBACK"
151
%token<str> PGS_SAVEPOINT "SAVEPOINT"
152
%token<str> PGS_SELECT "SELECT"
153
%token<str> PGS_SET "SET"
154
%token<str> PGS_SHOW "SHOW"
155
%token<str> PGS_START "START"
156
%token<str> PGS_TRUNCATE "TRUNCATE"
157
%token<str> PGS_UNLISTEN "UNLISTEN"
158
%token<str> PGS_UPDATE "UPDATE"
159
%token<str> PGS_VACUUM "VACUUM"
160
%token<str> PGS_VALUES "VALUES"
162
%token<str> PGS_IDENTIFIER "IDENTIFIER"
163
%token<str> PGS_VAL_INT "INTEGER VALUE"
164
%token<str> PGS_VAL_REAL "REAL VALUE"
165
%token<str> PGS_VAL_STR "STRING VALUE"
167
%destructor { pdelete($$); } PGS_ABORT
168
%destructor { pdelete($$); } PGS_ALTER
169
%destructor { pdelete($$); } PGS_ANALYZE
170
%destructor { pdelete($$); } PGS_BEGIN
171
%destructor { pdelete($$); } PGS_CHECKPOINT
172
%destructor { pdelete($$); } PGS_CLOSE_ST
173
%destructor { pdelete($$); } PGS_CLUSTER
174
%destructor { pdelete($$); } PGS_COMMENT
175
%destructor { pdelete($$); } PGS_COMMIT
176
%destructor { pdelete($$); } PGS_COPY
177
%destructor { pdelete($$); } PGS_CREATE
178
%destructor { pdelete($$); } PGS_DEALLOCATE
179
%destructor { pdelete($$); } PGS_DECLARE
180
%destructor { pdelete($$); } PGS_DELETE
181
%destructor { pdelete($$); } PGS_DISCARD
182
%destructor { pdelete($$); } PGS_DROP
183
%destructor { pdelete($$); } PGS_END_ST
184
%destructor { pdelete($$); } PGS_EXECUTE
185
%destructor { pdelete($$); } PGS_EXPLAIN
186
%destructor { pdelete($$); } PGS_FETCH
187
%destructor { pdelete($$); } PGS_GRANT
188
%destructor { pdelete($$); } PGS_INSERT
189
%destructor { pdelete($$); } PGS_LISTEN
190
%destructor { pdelete($$); } PGS_LOAD
191
%destructor { pdelete($$); } PGS_LOCK
192
%destructor { pdelete($$); } PGS_MOVE
193
%destructor { pdelete($$); } PGS_NOTIFY
194
%destructor { pdelete($$); } PGS_PREPARE
195
%destructor { pdelete($$); } PGS_REASSIGN
196
%destructor { pdelete($$); } PGS_REINDEX
197
%destructor { pdelete($$); } PGS_RELEASE
198
%destructor { pdelete($$); } PGS_RESET
199
%destructor { pdelete($$); } PGS_REVOKE
200
%destructor { pdelete($$); } PGS_ROLLBACK
201
%destructor { pdelete($$); } PGS_SAVEPOINT
202
%destructor { pdelete($$); } PGS_SELECT
203
%destructor { pdelete($$); } PGS_SET
204
%destructor { pdelete($$); } PGS_SHOW
205
%destructor { pdelete($$); } PGS_START
206
%destructor { pdelete($$); } PGS_TRUNCATE
207
%destructor { pdelete($$); } PGS_UNLISTEN
208
%destructor { pdelete($$); } PGS_UPDATE
209
%destructor { pdelete($$); } PGS_VACUUM
210
%destructor { pdelete($$); } PGS_VALUES
212
%destructor { pdelete($$); } PGS_IDENTIFIER
213
%destructor { pdelete($$); } PGS_VAL_INT
214
%destructor { pdelete($$); } PGS_VAL_REAL
215
%destructor { pdelete($$); } PGS_VAL_STR
217
%type<expr> postfix_expression
218
%type<expr> unary_expression
219
%type<expr> cast_expression
220
%type<expr> multiplicative_expression
221
%type<expr> additive_expression
222
%type<expr> relational_expression
223
%type<expr> equality_expression
224
%type<expr> logical_and_expression
225
%type<expr> logical_or_expression
226
%type<expr> expression
227
%type<expr> random_generator
228
%type<expr> sql_expression
231
%type<integer> type_name
233
%type<stmt> statement
235
%type<stmt> compound_statement
236
%type<stmt> sql_statement
237
%type<stmt> selection_statement
238
%type<stmt> iteration_statement
239
%type<stmt> procedure_statement
240
%type<stmt> jump_statement
241
%type<stmt> declaration_statement
242
%type<stmt> assign_statement
244
%type<stmt_list> declaration_list
245
%type<stmt_list> assign_list
246
%type<stmt> declaration_element
247
%type<stmt> assign_element
249
%type<stmt_list> statement_list
253
#include "pgscript/utilities/pgsDriver.h"
254
#include "pgscript/utilities/pgsScanner.h"
256
/* This "connects" the bison parser in the driver to the flex scanner class
257
* object. It defines the yylex() function call to pull the next token from the
258
* current lexer object of the driver context. */
260
#define yylex driver.lexer->lex
264
%% /*** Grammar Rules ***/
267
: PGS_IDENTIFIER '[' expression ']' '[' expression ']'
269
$$ = pnew pgsIdentRecord(*($1), $3, $6);
271
driver.context.pop_var(); driver.context.pop_var(); // $3 & $6
272
driver.context.push_var($$);
274
| PGS_IDENTIFIER '[' expression ']'
276
$$ = pnew pgsIdentRecord(*($1), $3);
278
driver.context.pop_var(); // $3
279
driver.context.push_var($$);
281
| PGS_CNT_LINES '(' PGS_IDENTIFIER ')'
283
$$ = pnew pgsLines(*($3));
285
driver.context.push_var($$);
287
| PGS_CNT_COLUMNS '(' PGS_IDENTIFIER ')'
289
$$ = pnew pgsColumns(*($3));
291
driver.context.push_var($$);
293
| PGS_TRIM '(' expression ')'
295
$$ = pnew pgsTrim($3);
296
driver.context.pop_var(); // $3
297
driver.context.push_var($$); // assert
301
$$ = pnew pgsIdent(*($1));
303
driver.context.push_var($$);
307
$$ = pnew pgsNumber(*($1), pgsInt);
309
driver.context.push_var($$);
313
$$ = pnew pgsNumber(*($1), pgsReal);
315
driver.context.push_var($$);
319
$$ = pnew pgsString(*($1));
321
driver.context.push_var($$);
323
| '(' PGS_SELECT ')' {
324
$$ = pnew pgsExecute(*($2), &driver.context.m_cout,
327
driver.context.push_var($$); // SQL Expression statement
329
| random_generator { $$ = $1; }
330
| '(' expression ')' {
331
$$ = pnew pgsParenthesis($2);
332
driver.context.pop_var(); // $2
333
driver.context.push_var($$);
338
: postfix_expression { $$ = $1; }
339
| '+' cast_expression { $$ = $2; }
340
| '-' cast_expression {
341
$$ = pnew pgsNegate($2);
342
driver.context.pop_var(); // $2
343
driver.context.push_var($$);
345
| PGS_NOT_OP cast_expression
347
$$ = pnew pgsNot($2);
348
driver.context.pop_var(); // $2
349
driver.context.push_var($$);
354
: unary_expression { $$ = $1; }
355
| PGS_CAST '(' cast_expression PGS_AS type_name ')'
357
$$ = pnew pgsCast($5, $3);
358
driver.context.pop_var(); // $3
359
driver.context.push_var($$);
364
: PGS_INTEGER { $$ = pgscript::pgsParser::token::PGS_INTEGER; }
365
| PGS_REAL { $$ = pgscript::pgsParser::token::PGS_REAL; }
366
| PGS_STRING { $$ = pgscript::pgsParser::token::PGS_STRING; }
367
| PGS_RECORD { $$ = pgscript::pgsParser::token::PGS_RECORD; }
370
multiplicative_expression
371
: cast_expression { $$ = $1; }
372
| multiplicative_expression '*' cast_expression
374
$$ = pnew pgsTimes($1, $3);
375
driver.context.pop_var();
376
driver.context.pop_var(); // $1 & $3
377
driver.context.push_var($$);
379
| multiplicative_expression '/' cast_expression
381
$$ = pnew pgsOver($1, $3);
382
driver.context.pop_var();
383
driver.context.pop_var(); // $1 & $3
384
driver.context.push_var($$);
386
| multiplicative_expression '%' cast_expression
388
$$ = pnew pgsModulo($1, $3);
389
driver.context.pop_var();
390
driver.context.pop_var(); // $1 & $3
391
driver.context.push_var($$);
396
: multiplicative_expression { $$ = $1; }
397
| additive_expression '+' multiplicative_expression
399
$$ = pnew pgsPlus($1, $3);
400
driver.context.pop_var();
401
driver.context.pop_var(); // $1 & $3
402
driver.context.push_var($$);
404
| additive_expression '-' multiplicative_expression
406
$$ = pnew pgsMinus($1, $3);
407
driver.context.pop_var();
408
driver.context.pop_var(); // $1 & $3
409
driver.context.push_var($$);
413
relational_expression
414
: additive_expression { $$ = $1; }
415
| relational_expression '<' additive_expression
417
$$ = pnew pgsLower($1, $3);
418
driver.context.pop_var();
419
driver.context.pop_var(); // $1 & $3
420
driver.context.push_var($$);
422
| relational_expression '>' additive_expression
424
$$ = pnew pgsGreater($1, $3);
425
driver.context.pop_var();
426
driver.context.pop_var(); // $1 & $3
427
driver.context.push_var($$);
429
| relational_expression PGS_LE_OP additive_expression
431
$$ = pnew pgsLowerEqual($1, $3);
432
driver.context.pop_var();
433
driver.context.pop_var(); // $1 & $3
434
driver.context.push_var($$);
436
| relational_expression PGS_GE_OP additive_expression
438
$$ = pnew pgsGreaterEqual($1, $3);
439
driver.context.pop_var();
440
driver.context.pop_var(); // $1 & $3
441
driver.context.push_var($$);
446
: relational_expression { $$ = $1; }
447
| equality_expression PGS_EQ_OP relational_expression
449
$$ = pnew pgsEqual($1, $3);
450
driver.context.pop_var();
451
driver.context.pop_var(); // $1 & $3
452
driver.context.push_var($$);
454
| equality_expression PGS_AE_OP relational_expression
456
$$ = pnew pgsEqual($1, $3, false);
457
driver.context.pop_var();
458
driver.context.pop_var(); // $1 & $3
459
driver.context.push_var($$);
461
| equality_expression PGS_NE_OP relational_expression
463
$$ = pnew pgsDifferent($1, $3);
464
driver.context.pop_var();
465
driver.context.pop_var(); // $1 & $3
466
driver.context.push_var($$);
470
logical_and_expression
471
: equality_expression { $$ = $1; }
472
| logical_and_expression PGS_AND_OP equality_expression
474
$$ = pnew pgsAnd($1, $3);
475
driver.context.pop_var();
476
driver.context.pop_var(); // $1 & $3
477
driver.context.push_var($$);
481
logical_or_expression
482
: logical_and_expression { $$ = $1; }
483
| logical_or_expression PGS_OR_OP logical_and_expression
485
$$ = pnew pgsOr($1, $3);
486
driver.context.pop_var();
487
driver.context.pop_var(); // $1 & $3
488
driver.context.push_var($$);
493
: logical_or_expression {
494
wxLogScriptVerbose(wxT("%s"), $1->value().c_str());
500
: PGS_INTEGER '(' expression ',' expression ')'
502
$$ = pnew pgsGenInt($3, $5, driver.context.zero(),
503
driver.context.seed());
504
driver.context.pop_var(); driver.context.pop_var();
505
driver.context.pop_var(); driver.context.pop_var();
506
driver.context.push_var($$);
508
| PGS_INTEGER '(' expression ',' expression ',' expression ')'
510
$$ = pnew pgsGenInt($3, $5, $7, driver.context.seed());
511
driver.context.pop_var(); driver.context.pop_var();
512
driver.context.pop_var(); driver.context.pop_var();
513
driver.context.push_var($$);
515
| PGS_INTEGER '(' expression ',' expression ',' expression ',' expression ')'
517
$$ = pnew pgsGenInt($3, $5, $7, $9);
518
driver.context.pop_var(); driver.context.pop_var();
519
driver.context.pop_var(); driver.context.pop_var();
520
driver.context.push_var($$);
522
| PGS_REAL '(' expression ',' expression ',' expression ')'
524
$$ = pnew pgsGenReal($3, $5, $7, driver.context.zero(),
525
driver.context.seed());
526
driver.context.pop_var(); driver.context.pop_var();
527
driver.context.pop_var(); driver.context.pop_var();
528
driver.context.pop_var();
529
driver.context.push_var($$);
531
| PGS_REAL '(' expression ',' expression ',' expression ',' expression ')'
533
$$ = pnew pgsGenReal($3, $5, $7, $9, driver.context.seed());
534
driver.context.pop_var(); driver.context.pop_var();
535
driver.context.pop_var(); driver.context.pop_var();
536
driver.context.pop_var();
537
driver.context.push_var($$);
539
| PGS_REAL '(' expression ',' expression ',' expression ',' expression ',' expression ')'
541
$$ = pnew pgsGenReal($3, $5, $7, $9, $11);
542
driver.context.pop_var(); driver.context.pop_var();
543
driver.context.pop_var(); driver.context.pop_var();
544
driver.context.pop_var();
545
driver.context.push_var($$);
547
| PGS_STRING '(' expression ',' expression ')'
549
$$ = pnew pgsGenString($3, $5, driver.context.one(),
550
driver.context.seed());
551
driver.context.pop_var(); driver.context.pop_var();
552
driver.context.pop_var(); driver.context.pop_var();
553
driver.context.push_var($$);
555
| PGS_STRING '(' expression ',' expression ',' expression ')'
557
$$ = pnew pgsGenString($3, $5, $7, driver.context.seed());
558
driver.context.pop_var(); driver.context.pop_var();
559
driver.context.pop_var(); driver.context.pop_var();
560
driver.context.push_var($$);
562
| PGS_STRING '(' expression ',' expression ',' expression ',' expression ')'
564
$$ = pnew pgsGenString($3, $5, $7, $9);
565
driver.context.pop_var(); driver.context.pop_var();
566
driver.context.pop_var(); driver.context.pop_var();
567
driver.context.push_var($$);
569
| PGS_REGEX '(' expression ')'
571
$$ = pnew pgsGenRegex($3, driver.context.seed());
572
driver.context.pop_var(); driver.context.pop_var();
573
driver.context.push_var($$);
575
| PGS_REGEX '(' expression ',' expression ')'
577
$$ = pnew pgsGenRegex($3, $5);
578
driver.context.pop_var(); driver.context.pop_var();
579
driver.context.push_var($$);
581
| PGS_FILE '(' expression ')'
583
$$ = pnew pgsGenDictionary($3, driver.context.zero(),
584
driver.context.seed(), driver.context.encoding());
585
driver.context.pop_var(); driver.context.pop_var();
586
driver.context.pop_var(); driver.context.pop_var();
587
driver.context.push_var($$);
589
| PGS_FILE '(' expression ',' expression ')'
591
$$ = pnew pgsGenDictionary($3, $5, driver.context.seed(),
592
driver.context.encoding());
593
driver.context.pop_var(); driver.context.pop_var();
594
driver.context.pop_var(); driver.context.pop_var();
595
driver.context.push_var($$);
597
| PGS_FILE '(' expression ',' expression ',' expression ')'
599
$$ = pnew pgsGenDictionary($3, $5, $7, driver.context.encoding());
600
driver.context.pop_var(); driver.context.pop_var();
601
driver.context.pop_var(); driver.context.pop_var();
602
driver.context.push_var($$);
604
| PGS_FILE '(' expression ',' expression ',' expression ',' expression ')'
606
$$ = pnew pgsGenDictionary($3, $5, $7, $9);
607
driver.context.pop_var(); driver.context.pop_var();
608
driver.context.pop_var(); driver.context.pop_var();
609
driver.context.push_var($$);
611
| PGS_DATE '(' expression ',' expression ')'
613
$$ = pnew pgsGenDate($3, $5, driver.context.zero(),
614
driver.context.seed());
615
driver.context.pop_var(); driver.context.pop_var();
616
driver.context.pop_var(); driver.context.pop_var();
617
driver.context.push_var($$);
619
| PGS_DATE '(' expression ',' expression ',' expression ')'
621
$$ = pnew pgsGenDate($3, $5, $7, driver.context.seed());
622
driver.context.pop_var(); driver.context.pop_var();
623
driver.context.pop_var(); driver.context.pop_var();
624
driver.context.push_var($$);
626
| PGS_DATE '(' expression ',' expression ',' expression ',' expression ')'
628
$$ = pnew pgsGenDate($3, $5, $7, $9);
629
driver.context.pop_var(); driver.context.pop_var();
630
driver.context.pop_var(); driver.context.pop_var();
631
driver.context.push_var($$);
633
| PGS_TIME '(' expression ',' expression ')'
635
$$ = pnew pgsGenTime($3, $5, driver.context.zero(),
636
driver.context.seed());
637
driver.context.pop_var(); driver.context.pop_var();
638
driver.context.pop_var(); driver.context.pop_var();
639
driver.context.push_var($$);
641
| PGS_TIME '(' expression ',' expression ',' expression ')'
643
$$ = pnew pgsGenTime($3, $5, $7, driver.context.seed());
644
driver.context.pop_var(); driver.context.pop_var();
645
driver.context.pop_var(); driver.context.pop_var();
646
driver.context.push_var($$);
648
| PGS_TIME '(' expression ',' expression ',' expression ',' expression ')'
650
$$ = pnew pgsGenTime($3, $5, $7, $9);
651
driver.context.pop_var(); driver.context.pop_var();
652
driver.context.pop_var(); driver.context.pop_var();
653
driver.context.push_var($$);
655
| PGS_DATE_TIME '(' expression ',' expression ')'
657
$$ = pnew pgsGenDateTime($3, $5, driver.context.zero(),
658
driver.context.seed());
659
driver.context.pop_var(); driver.context.pop_var();
660
driver.context.pop_var(); driver.context.pop_var();
661
driver.context.push_var($$);
663
| PGS_DATE_TIME '(' expression ',' expression ',' expression ')'
665
$$ = pnew pgsGenDateTime($3, $5, $7, driver.context.seed());
666
driver.context.pop_var(); driver.context.pop_var();
667
driver.context.pop_var(); driver.context.pop_var();
668
driver.context.push_var($$);
670
| PGS_DATE_TIME '(' expression ',' expression ',' expression ',' expression ')'
672
$$ = pnew pgsGenDateTime($3, $5, $7, $9);
673
driver.context.pop_var(); driver.context.pop_var();
674
driver.context.pop_var(); driver.context.pop_var();
675
driver.context.push_var($$);
677
| PGS_REFERENCE '(' expression ',' expression ')'
679
$$ = pnew pgsGenReference($3, $5, driver.context.zero(),
680
driver.context.seed(), &(driver.thread));
681
driver.context.pop_var(); driver.context.pop_var();
682
driver.context.pop_var(); driver.context.pop_var();
683
driver.context.push_var($$);
685
| PGS_REFERENCE '(' expression ',' expression ',' expression ')'
687
$$ = pnew pgsGenReference($3, $5, $7, driver.context.seed(),
689
driver.context.pop_var(); driver.context.pop_var();
690
driver.context.pop_var(); driver.context.pop_var();
691
driver.context.push_var($$);
693
| PGS_REFERENCE '(' expression ',' expression ',' expression ',' expression ')'
695
$$ = pnew pgsGenReference($3, $5, $7, $9, &(driver.thread));
696
driver.context.pop_var(); driver.context.pop_var();
697
driver.context.pop_var(); driver.context.pop_var();
698
driver.context.push_var($$);
703
: compound_statement { $$ = $1; }
704
| selection_statement { $$ = $1; }
705
| iteration_statement { $$ = $1; }
706
| sql_statement ';' { $$ = $1; }
707
| procedure_statement ';' { $$ = $1; }
708
| jump_statement ';' { $$ = $1; }
709
| declaration_statement ';' { $$ = $1; }
710
| assign_statement ';' { $$ = $1; }
715
driver.context.pop_stmt(); // $1
716
$$ = driver.context.stmt_list(&(driver.thread));
719
| statement_list statement {
720
driver.context.pop_stmt(); // $2
727
: PGS_OPEN PGS_CLOSE {
728
wxLogScriptVerbose(wxT("BEGIN END"));
729
$$ = driver.context.stmt_list(&(driver.thread));
731
| PGS_OPEN statement_list PGS_CLOSE
733
wxLogScriptVerbose(wxT("BEGIN ... END"));
740
wxLogScriptVerbose(wxT("%s"), $1->value().c_str());
741
$$ = pnew pgsExpressionStmt($1, &(driver.thread));
742
driver.context.pop_var(); // $1
743
driver.context.push_stmt($$); // pgsExpressionStmt
744
$$->set_position(yyloc.begin.line);
750
$$ = pnew pgsExecute(*($1), &driver.context.m_cout,
753
driver.context.push_var($$); // pgsExecute
758
: PGS_ABORT { $$ = $1; }
759
| PGS_ALTER { $$ = $1; }
760
| PGS_ANALYZE { $$ = $1; }
761
| PGS_BEGIN { $$ = $1; }
762
| PGS_CHECKPOINT { $$ = $1; }
763
| PGS_CLOSE_ST { $$ = $1; }
764
| PGS_CLUSTER { $$ = $1; }
765
| PGS_COMMENT { $$ = $1; }
766
| PGS_COMMIT { $$ = $1; }
767
| PGS_COPY { $$ = $1; }
768
| PGS_CREATE { $$ = $1; }
769
| PGS_DEALLOCATE { $$ = $1; }
770
| PGS_DECLARE { $$ = $1; }
771
| PGS_DELETE { $$ = $1; }
772
| PGS_DISCARD { $$ = $1; }
773
| PGS_DROP { $$ = $1; }
774
| PGS_END_ST { $$ = $1; }
775
| PGS_EXECUTE { $$ = $1; }
776
| PGS_EXPLAIN { $$ = $1; }
777
| PGS_FETCH { $$ = $1; }
778
| PGS_GRANT { $$ = $1; }
779
| PGS_INSERT { $$ = $1; }
780
| PGS_LISTEN { $$ = $1; }
781
| PGS_LOAD { $$ = $1; }
782
| PGS_LOCK { $$ = $1; }
783
| PGS_MOVE { $$ = $1; }
784
| PGS_NOTIFY { $$ = $1; }
785
| PGS_PREPARE { $$ = $1; }
786
| PGS_REASSIGN { $$ = $1; }
787
| PGS_REINDEX { $$ = $1; }
788
| PGS_RELEASE { $$ = $1; }
789
| PGS_RESET { $$ = $1; }
790
| PGS_REVOKE { $$ = $1; }
791
| PGS_ROLLBACK { $$ = $1; }
792
| PGS_SAVEPOINT { $$ = $1; }
793
| PGS_SELECT { $$ = $1; }
794
| PGS_SET { $$ = $1; }
795
| PGS_SHOW { $$ = $1; }
796
| PGS_START { $$ = $1; }
797
| PGS_TRUNCATE { $$ = $1; }
798
| PGS_UNLISTEN { $$ = $1; }
799
| PGS_UPDATE { $$ = $1; }
800
| PGS_VACUUM { $$ = $1; }
801
| PGS_VALUES { $$ = $1; }
804
declaration_statement
805
: PGS_DECLARE_ASSGN declaration_list
812
: declaration_element {
813
driver.context.pop_stmt(); // $1
814
$$ = driver.context.stmt_list(&(driver.thread));
818
| declaration_list ',' declaration_element
820
driver.context.pop_stmt(); // $3
828
wxLogScriptVerbose(wxT("DECLARE %s"), $1->c_str());
830
$$ = pnew pgsExpressionStmt(pnew pgsAssign(*($1),
831
pnew pgsString(wxT(""))), &(driver.thread));
832
driver.context.push_stmt($$); // pgsExpressionStmt
833
$$->set_position(yyloc.begin.line);
837
| PGS_IDENTIFIER '{' record_declaration_list '}'
839
wxLogScriptVerbose(wxT("DECLARE %s"), $1->c_str());
841
$$ = pnew pgsDeclareRecordStmt(*($1), driver.context.columns(),
843
driver.context.push_stmt($$); // pgsDeclareRecordStmt
844
$$->set_position(yyloc.begin.line);
846
driver.context.clear_columns();
852
: PGS_SET_ASSIGN assign_list
860
driver.context.pop_stmt(); // $1
861
$$ = driver.context.stmt_list(&(driver.thread));
864
| assign_list ',' assign_element
866
driver.context.pop_stmt(); // $3
873
: PGS_IDENTIFIER PGS_EQ_OP expression
875
wxLogScriptVerbose(wxT("SET %s = %s"), $1->c_str(),
876
$3->value().c_str());
878
$$ = pnew pgsExpressionStmt(pnew pgsAssign(*($1), $3),
880
driver.context.pop_var(); // $3
881
driver.context.push_stmt($$); // pgsExpressionStmt
882
$$->set_position(yyloc.begin.line);
886
| PGS_IDENTIFIER '[' expression ']' '[' expression ']' PGS_EQ_OP expression
888
wxLogScriptVerbose(wxT("SET %s[%s][%s] = %s"),
889
$1->c_str(), $3->value().c_str(),
890
$6->value().c_str(), $9->value().c_str());
892
$$ = pnew pgsExpressionStmt(pnew pgsAssignToRecord(*($1),
893
$3, $6, $9), &(driver.thread));
894
driver.context.pop_var(); driver.context.pop_var();
895
driver.context.pop_var(); // $3 & $6 & $9
896
driver.context.push_stmt($$); // pgsExpressionStmt
897
$$->set_position(yyloc.begin.line);
901
| PGS_IDENTIFIER PGS_EQ_OP sql_expression
903
wxLogScriptVerbose(wxT("SET %s = %s"), $1->c_str(),
904
$3->value().c_str());
906
$$ = pnew pgsExpressionStmt(pnew pgsAssign(*($1), $3),
908
driver.context.pop_var(); // $3
909
driver.context.push_stmt($$); // pgsExpressionStmt
910
$$->set_position(yyloc.begin.line);
917
: PGS_IF expression statement %prec PGS_ELSE
919
wxLogScriptVerbose(wxT("IF %s"), $2->value().c_str());
921
$$ = pnew pgsIfStmt($2, $3, driver.context
922
.stmt_list(&(driver.thread)), &(driver.thread));
923
driver.context.pop_var(); // $2
924
driver.context.pop_stmt(); // $3
925
driver.context.pop_stmt(); // stmt_list
926
driver.context.push_stmt($$); // pgsIfStmt
927
$$->set_position(yyloc.begin.line);
929
| PGS_IF expression statement PGS_ELSE statement
931
wxLogScriptVerbose(wxT("IF %s"), $2->value().c_str());
933
$$ = pnew pgsIfStmt($2, $3, $5, &(driver.thread));
934
driver.context.pop_var(); // $2
935
driver.context.pop_stmt(); // $3
936
driver.context.pop_stmt(); // $5
937
driver.context.push_stmt($$); // pgsIfStmt
938
$$->set_position(yyloc.begin.line);
943
: PGS_WHILE expression statement
945
wxLogScriptVerbose(wxT("WHILE %s"), $2->value().c_str());
947
$$ = pnew pgsWhileStmt($2, $3, &(driver.thread));
948
driver.context.pop_var(); // $2
949
driver.context.pop_stmt(); // $3
950
driver.context.push_stmt($$); // pgsWhileStmt
951
$$->set_position(yyloc.begin.line);
957
wxLogScriptVerbose(wxT("BREAK"));
959
$$ = pnew pgsBreakStmt(&(driver.thread));
960
driver.context.push_stmt($$); // pgsBreakStmt
961
$$->set_position(yyloc.begin.line);
964
wxLogScriptVerbose(wxT("RETURN"));
966
$$ = pnew pgsBreakStmt(&(driver.thread));
967
driver.context.push_stmt($$); // pgsBreakStmt
968
$$->set_position(yyloc.begin.line);
971
wxLogScriptVerbose(wxT("CONTINUE"));
973
$$ = pnew pgsContinueStmt(&(driver.thread));
974
driver.context.push_stmt($$); // pgsContinueStmt
975
$$->set_position(yyloc.begin.line);
980
: PGS_PRINT expression
982
wxLogScriptVerbose(wxT("PRINT %s"), $2->value().c_str());
984
$$ = pnew pgsPrintStmt($2, driver.context.m_cout,
986
driver.context.pop_var(); // $2
987
driver.context.push_stmt($$); // pgsPrintStmt
988
$$->set_position(yyloc.begin.line);
990
| PGS_ASSERT expression
992
wxLogScriptVerbose(wxT("ASSERT %s"), $2->value().c_str());
994
$$ = pnew pgsAssertStmt($2, &(driver.thread));
995
driver.context.pop_var(); // $2
996
driver.context.push_stmt($$); // pgsAssertStmt
997
$$->set_position(yyloc.begin.line);
999
| PGS_RM_LINE '(' PGS_IDENTIFIER '[' expression ']' ')'
1001
wxLogScriptVerbose(wxT("RMLINE %s[%s]"), $3->c_str(),
1002
$5->value().c_str());
1004
$$ = pnew pgsExpressionStmt(pnew pgsRemoveLine(*($3), $5),
1006
driver.context.pop_var(); // $5
1007
driver.context.push_stmt($$); // pgsExpressionStmt
1008
$$->set_position(yyloc.begin.line);
1014
record_declaration_list
1016
driver.context.add_column(*$1);
1019
| record_declaration_list ',' PGS_IDENTIFIER
1021
driver.context.add_column(*$3);
1028
| statement_list PGS_END {
1029
driver.program.eval($1);
1031
driver.context.pop_stmt();
1032
pdelete($1); // delete root statement $1
1036
%% /*** Additional Code ***/
1038
void pgscript::pgsParser::error(const pgsParser::location_type & l,
1039
const std::string & m)
1041
wxLogScriptVerbose(wxT("EXPR STACK SIZE = %u"), driver.context.size_vars());
1042
wxLogScriptVerbose(wxT("STMT STACK SIZE = %u"), driver.context.size_stmts());
1043
driver.context.clear_stacks();
1044
driver.error(l, wxString(m.c_str(), wxConvUTF8));