~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/pgscript/pgsParser.yy

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{ /*** C/C++ Declarations ***/
 
2
        
 
3
//////////////////////////////////////////////////////////////////////////
 
4
//
 
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
 
9
//
 
10
//////////////////////////////////////////////////////////////////////////
 
11
 
 
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"
 
17
 
 
18
%}
 
19
 
 
20
/*** YACC/Bison declarations ***/
 
21
 
 
22
/* Require bison 2.3 or later */
 
23
%require "2.3"
 
24
 
 
25
/* Start symbol is named "start" */
 
26
%start translation_unit
 
27
 
 
28
/* Write out a header file containing the token defines */
 
29
%defines
 
30
 
 
31
/* Use newer C++ skeleton file */
 
32
%skeleton "lalr1.cc"
 
33
 
 
34
/* Namespace to enclose parser in */
 
35
%name-prefix="pgscript"
 
36
 
 
37
/* Set the parser's class identifier */
 
38
%define "parser_class_name" "pgsParser"
 
39
 
 
40
/* Keep track of the current position within the input */
 
41
%locations
 
42
%initial-action
 
43
{
 
44
        // Initialize the initial location object
 
45
        @$.begin.filename = @$.end.filename;
 
46
};
 
47
 
 
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
 
50
 * variables. */
 
51
%parse-param { class pgsDriver & driver }
 
52
 
 
53
/* Verbose error messages */
 
54
%error-verbose
 
55
 
 
56
%token PGS_END  0                       "END OF FILE"
 
57
 
 
58
%token PGS_WHILE                        "WHILE"
 
59
%token PGS_BREAK                        "BREAK"
 
60
%token PGS_RETURN                       "RETURN"
 
61
%token PGS_CONTINUE                     "CONTINUE"
 
62
%token PGS_IF                           "IF"
 
63
%token PGS_ELSE                         "ELSE"
 
64
%token PGS_WAITFOR                      "WAITFOR"
 
65
%token PGS_AS                           "AS"
 
66
 
 
67
%token PGS_OPEN                         "BEGIN (BLOCK)"
 
68
%token PGS_CLOSE                        "END (BLOCK)"
 
69
 
 
70
%token PGS_ASSERT                       "ASSERT"
 
71
%token PGS_PRINT                        "PRINT"
 
72
%token PGS_LOG                          "LOG"
 
73
 
 
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"
 
79
 
 
80
%token PGS_RECORD                       "RECORD"
 
81
 
 
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"
 
91
 
 
92
%token PGS_LE_OP                        "<="
 
93
%token PGS_GE_OP                        ">="
 
94
%token PGS_EQ_OP                        "="
 
95
%token PGS_AE_OP                        "~="
 
96
%token PGS_NE_OP                        "<>"
 
97
%token PGS_AND_OP                       "AND"
 
98
%token PGS_OR_OP                        "OR"
 
99
%token PGS_NOT_OP                       "NOT"
 
100
 
 
101
%token PGS_UNKNOWN                      "character"
 
102
 
 
103
%right PGS_ELSE
 
104
 
 
105
%union
 
106
{
 
107
        const wxString * str;
 
108
        int integer;
 
109
        pgsExpression * expr;
 
110
        pgsStmt * stmt;
 
111
        pgsStmtList * stmt_list;
 
112
}
 
113
 
 
114
%token PGS_SET_ASSIGN           "SET @VARIABLE"
 
115
%token PGS_DECLARE_ASSGN        "DECLARE @VARIABLE"
 
116
 
 
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"
 
161
 
 
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"
 
166
 
 
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
 
211
 
 
212
%destructor { pdelete($$); } PGS_IDENTIFIER
 
213
%destructor { pdelete($$); } PGS_VAL_INT
 
214
%destructor { pdelete($$); } PGS_VAL_REAL
 
215
%destructor { pdelete($$); } PGS_VAL_STR
 
216
 
 
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
 
229
 
 
230
%type<str> sql_query
 
231
%type<integer> type_name
 
232
 
 
233
%type<stmt> statement
 
234
 
 
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
 
243
 
 
244
%type<stmt_list> declaration_list
 
245
%type<stmt_list> assign_list
 
246
%type<stmt> declaration_element
 
247
%type<stmt> assign_element
 
248
 
 
249
%type<stmt_list> statement_list
 
250
 
 
251
%{
 
252
 
 
253
#include "pgscript/utilities/pgsDriver.h"
 
254
#include "pgscript/utilities/pgsScanner.h"
 
255
 
 
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. */
 
259
#undef  yylex
 
260
#define yylex driver.lexer->lex
 
261
 
 
262
%}
 
263
 
 
264
%% /*** Grammar Rules ***/
 
265
        
 
266
postfix_expression
 
267
        : PGS_IDENTIFIER '[' expression ']' '[' expression ']'
 
268
                                                                {
 
269
                                                                        $$ = pnew pgsIdentRecord(*($1), $3, $6);
 
270
                                                                        pdelete($1);
 
271
                                                                        driver.context.pop_var(); driver.context.pop_var(); // $3 & $6
 
272
                                                                        driver.context.push_var($$);
 
273
                                                                }
 
274
        | PGS_IDENTIFIER '[' expression ']'
 
275
                                                                {
 
276
                                                                        $$ = pnew pgsIdentRecord(*($1), $3);
 
277
                                                                        pdelete($1);
 
278
                                                                        driver.context.pop_var(); // $3
 
279
                                                                        driver.context.push_var($$);
 
280
                                                                }
 
281
        | PGS_CNT_LINES '(' PGS_IDENTIFIER ')'
 
282
                                                                {
 
283
                                                                        $$ = pnew pgsLines(*($3));
 
284
                                                                        pdelete($3);
 
285
                                                                        driver.context.push_var($$);
 
286
                                                                }
 
287
        | PGS_CNT_COLUMNS '(' PGS_IDENTIFIER ')'
 
288
                                                                {
 
289
                                                                        $$ = pnew pgsColumns(*($3));
 
290
                                                                        pdelete($3);
 
291
                                                                        driver.context.push_var($$);
 
292
                                                                }
 
293
        | PGS_TRIM '(' expression ')'
 
294
                                                                {
 
295
                                                                        $$ = pnew pgsTrim($3);
 
296
                                                                        driver.context.pop_var(); // $3
 
297
                                                                        driver.context.push_var($$); // assert
 
298
                                                                }
 
299
        | PGS_IDENTIFIER
 
300
                                                                {
 
301
                                                                        $$ = pnew pgsIdent(*($1));
 
302
                                                                        pdelete($1);
 
303
                                                                        driver.context.push_var($$);
 
304
                                                                }
 
305
        | PGS_VAL_INT
 
306
                                                                {
 
307
                                                                        $$ = pnew pgsNumber(*($1), pgsInt);
 
308
                                                                        pdelete($1);
 
309
                                                                        driver.context.push_var($$);
 
310
                                                                }
 
311
        | PGS_VAL_REAL
 
312
                                                                {
 
313
                                                                        $$ = pnew pgsNumber(*($1), pgsReal);
 
314
                                                                        pdelete($1);
 
315
                                                                        driver.context.push_var($$);
 
316
                                                                }
 
317
        | PGS_VAL_STR
 
318
                                                                {
 
319
                                                                        $$ = pnew pgsString(*($1));
 
320
                                                                        pdelete($1);
 
321
                                                                        driver.context.push_var($$);
 
322
                                                                }
 
323
        | '(' PGS_SELECT ')'            {
 
324
                                                                        $$ = pnew pgsExecute(*($2), &driver.context.m_cout,
 
325
                                                                                        &(driver.thread));
 
326
                                                                        pdelete($2);
 
327
                                                                        driver.context.push_var($$); // SQL Expression statement
 
328
                                                                }
 
329
        | random_generator                      { $$ = $1; }
 
330
        | '(' expression ')'            {
 
331
                                                                        $$ = pnew pgsParenthesis($2);
 
332
                                                                        driver.context.pop_var(); // $2
 
333
                                                                        driver.context.push_var($$);
 
334
                                                                }
 
335
        ;
 
336
 
 
337
unary_expression
 
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($$);
 
344
                                                                }
 
345
        | PGS_NOT_OP cast_expression
 
346
                                                                {
 
347
                                                                        $$ = pnew pgsNot($2);
 
348
                                                                        driver.context.pop_var(); // $2
 
349
                                                                        driver.context.push_var($$);
 
350
                                                                }
 
351
        ;
 
352
 
 
353
cast_expression
 
354
        : unary_expression                      { $$ = $1; }
 
355
        | PGS_CAST '(' cast_expression PGS_AS type_name ')'
 
356
                                                                {
 
357
                                                                        $$ = pnew pgsCast($5, $3);
 
358
                                                                        driver.context.pop_var(); // $3
 
359
                                                                        driver.context.push_var($$);
 
360
                                                                }
 
361
        ;       
 
362
 
 
363
type_name
 
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; }
 
368
        ;
 
369
        
 
370
multiplicative_expression
 
371
        : cast_expression                       { $$ = $1; }
 
372
        | multiplicative_expression '*' cast_expression
 
373
                                                                {
 
374
                                                                        $$ = pnew pgsTimes($1, $3);
 
375
                                                                        driver.context.pop_var();
 
376
                                                                        driver.context.pop_var(); // $1 & $3
 
377
                                                                        driver.context.push_var($$);
 
378
                                                                }
 
379
        | multiplicative_expression '/' cast_expression
 
380
                                                                {
 
381
                                                                        $$ = pnew pgsOver($1, $3);
 
382
                                                                        driver.context.pop_var();
 
383
                                                                        driver.context.pop_var(); // $1 & $3
 
384
                                                                        driver.context.push_var($$);
 
385
                                                                }
 
386
        | multiplicative_expression '%' cast_expression
 
387
                                                                {
 
388
                                                                        $$ = pnew pgsModulo($1, $3);
 
389
                                                                        driver.context.pop_var();
 
390
                                                                        driver.context.pop_var(); // $1 & $3
 
391
                                                                        driver.context.push_var($$);
 
392
                                                                }
 
393
        ;
 
394
        
 
395
additive_expression
 
396
        : multiplicative_expression     { $$ = $1; }
 
397
        | additive_expression '+' multiplicative_expression
 
398
                                                                {
 
399
                                                                        $$ = pnew pgsPlus($1, $3);
 
400
                                                                        driver.context.pop_var();
 
401
                                                                        driver.context.pop_var(); // $1 & $3
 
402
                                                                        driver.context.push_var($$);
 
403
                                                                }
 
404
        | additive_expression '-' multiplicative_expression
 
405
                                                                {
 
406
                                                                        $$ = pnew pgsMinus($1, $3);
 
407
                                                                        driver.context.pop_var();
 
408
                                                                        driver.context.pop_var(); // $1 & $3
 
409
                                                                        driver.context.push_var($$);
 
410
                                                                }
 
411
        ;
 
412
 
 
413
relational_expression
 
414
        : additive_expression           { $$ = $1; }
 
415
        | relational_expression '<' additive_expression
 
416
                                                                {
 
417
                                                                        $$ = pnew pgsLower($1, $3);
 
418
                                                                        driver.context.pop_var();
 
419
                                                                        driver.context.pop_var(); // $1 & $3
 
420
                                                                        driver.context.push_var($$);
 
421
                                                                }
 
422
        | relational_expression '>' additive_expression
 
423
                                                                {
 
424
                                                                        $$ = pnew pgsGreater($1, $3);
 
425
                                                                        driver.context.pop_var();
 
426
                                                                        driver.context.pop_var(); // $1 & $3
 
427
                                                                        driver.context.push_var($$);
 
428
                                                                }
 
429
        | relational_expression PGS_LE_OP additive_expression
 
430
                                                                {
 
431
                                                                        $$ = pnew pgsLowerEqual($1, $3);
 
432
                                                                        driver.context.pop_var();
 
433
                                                                        driver.context.pop_var(); // $1 & $3
 
434
                                                                        driver.context.push_var($$);
 
435
                                                                }
 
436
        | relational_expression PGS_GE_OP additive_expression
 
437
                                                                {
 
438
                                                                        $$ = pnew pgsGreaterEqual($1, $3);
 
439
                                                                        driver.context.pop_var();
 
440
                                                                        driver.context.pop_var(); // $1 & $3
 
441
                                                                        driver.context.push_var($$);
 
442
                                                                }
 
443
        ;
 
444
 
 
445
equality_expression
 
446
        : relational_expression         { $$ = $1; }
 
447
        | equality_expression PGS_EQ_OP relational_expression
 
448
                                                                {
 
449
                                                                        $$ = pnew pgsEqual($1, $3);
 
450
                                                                        driver.context.pop_var();
 
451
                                                                        driver.context.pop_var(); // $1 & $3
 
452
                                                                        driver.context.push_var($$);
 
453
                                                                }
 
454
        | equality_expression PGS_AE_OP relational_expression
 
455
                                                                {
 
456
                                                                        $$ = pnew pgsEqual($1, $3, false);
 
457
                                                                        driver.context.pop_var();
 
458
                                                                        driver.context.pop_var(); // $1 & $3
 
459
                                                                        driver.context.push_var($$);
 
460
                                                                }
 
461
        | equality_expression PGS_NE_OP relational_expression
 
462
                                                                {
 
463
                                                                        $$ = pnew pgsDifferent($1, $3);
 
464
                                                                        driver.context.pop_var();
 
465
                                                                        driver.context.pop_var(); // $1 & $3
 
466
                                                                        driver.context.push_var($$);
 
467
                                                                }
 
468
        ;
 
469
 
 
470
logical_and_expression
 
471
        : equality_expression           { $$ = $1; }
 
472
        | logical_and_expression PGS_AND_OP equality_expression
 
473
                                                                {
 
474
                                                                        $$ = pnew pgsAnd($1, $3);
 
475
                                                                        driver.context.pop_var();
 
476
                                                                        driver.context.pop_var(); // $1 & $3
 
477
                                                                        driver.context.push_var($$);
 
478
                                                                }
 
479
        ;
 
480
 
 
481
logical_or_expression
 
482
        : logical_and_expression        { $$ = $1; }
 
483
        | logical_or_expression PGS_OR_OP logical_and_expression
 
484
                                                                {
 
485
                                                                        $$ = pnew pgsOr($1, $3);
 
486
                                                                        driver.context.pop_var();
 
487
                                                                        driver.context.pop_var(); // $1 & $3
 
488
                                                                        driver.context.push_var($$);
 
489
                                                                }
 
490
        ;
 
491
 
 
492
expression
 
493
        : logical_or_expression         {
 
494
                                                                        wxLogScriptVerbose(wxT("%s"), $1->value().c_str());
 
495
                                                                        $$ = $1;
 
496
                                                                }
 
497
        ;
 
498
        
 
499
random_generator
 
500
        : PGS_INTEGER '(' expression ',' expression ')' 
 
501
                                                                {
 
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($$);
 
507
                                                                }
 
508
        | PGS_INTEGER '(' expression ',' expression ',' expression ')'
 
509
                                                                {
 
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($$);
 
514
                                                                }
 
515
        | PGS_INTEGER '(' expression ',' expression ',' expression ',' expression ')'
 
516
                                                                {
 
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($$);
 
521
                                                                }
 
522
        | PGS_REAL '(' expression ',' expression ',' expression ')'
 
523
                                                                {
 
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($$);
 
530
                                                                }
 
531
        | PGS_REAL '(' expression ',' expression ',' expression ',' expression ')'
 
532
                                                                {
 
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($$);
 
538
                                                                }
 
539
        | PGS_REAL '(' expression ',' expression ',' expression ',' expression ',' expression ')'
 
540
                                                                {
 
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($$);
 
546
                                                                }
 
547
        | PGS_STRING '(' expression ',' expression ')'
 
548
                                                                {
 
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($$);
 
554
                                                                }
 
555
        | PGS_STRING '(' expression ',' expression ',' expression ')'
 
556
                                                                {
 
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($$);
 
561
                                                                }
 
562
        | PGS_STRING '(' expression ',' expression ',' expression ',' expression ')'
 
563
                                                                {
 
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($$);
 
568
                                                                }
 
569
        | PGS_REGEX '(' expression ')'
 
570
                                                                {
 
571
                                                                        $$ = pnew pgsGenRegex($3, driver.context.seed());
 
572
                                                                        driver.context.pop_var(); driver.context.pop_var();
 
573
                                                                        driver.context.push_var($$);
 
574
                                                                }
 
575
        | PGS_REGEX '(' expression ',' expression ')'
 
576
                                                                {
 
577
                                                                        $$ = pnew pgsGenRegex($3, $5);
 
578
                                                                        driver.context.pop_var(); driver.context.pop_var();
 
579
                                                                        driver.context.push_var($$);
 
580
                                                                }
 
581
        | PGS_FILE '(' expression ')'
 
582
                                                                {
 
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($$);
 
588
                                                                }
 
589
        | PGS_FILE '(' expression ',' expression ')'
 
590
                                                                {
 
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($$);
 
596
                                                                }
 
597
        | PGS_FILE '(' expression ',' expression ',' expression ')'
 
598
                                                                {
 
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($$);
 
603
                                                                }
 
604
        | PGS_FILE '(' expression ',' expression ',' expression ',' expression ')'
 
605
                                                                {
 
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($$);
 
610
                                                                }
 
611
        | PGS_DATE '(' expression ',' expression ')'
 
612
                                                                {
 
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($$);
 
618
                                                                }
 
619
        | PGS_DATE '(' expression ',' expression ',' expression ')'
 
620
                                                                {
 
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($$);
 
625
                                                                }
 
626
        | PGS_DATE '(' expression ',' expression ',' expression ',' expression ')'
 
627
                                                                {
 
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($$);
 
632
                                                                }
 
633
        | PGS_TIME '(' expression ',' expression ')'
 
634
                                                                {
 
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($$);
 
640
                                                                }
 
641
        | PGS_TIME '(' expression ',' expression ',' expression ')'
 
642
                                                                {
 
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($$);
 
647
                                                                }
 
648
        | PGS_TIME '(' expression ',' expression ',' expression ',' expression ')'
 
649
                                                                {
 
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($$);
 
654
                                                                }
 
655
        | PGS_DATE_TIME '(' expression ',' expression ')'
 
656
                                                                {
 
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($$);
 
662
                                                                }
 
663
        | PGS_DATE_TIME '(' expression ',' expression ',' expression ')'
 
664
                                                                {
 
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($$);
 
669
                                                                }
 
670
        | PGS_DATE_TIME '(' expression ',' expression ',' expression ',' expression ')'
 
671
                                                                {
 
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($$);
 
676
                                                                }
 
677
        | PGS_REFERENCE '(' expression ',' expression ')'
 
678
                                                                {
 
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($$);
 
684
                                                                }
 
685
        | PGS_REFERENCE '(' expression ',' expression ',' expression ')'
 
686
                                                                {
 
687
                                                                        $$ = pnew pgsGenReference($3, $5, $7, driver.context.seed(),
 
688
                                                                                        &(driver.thread));
 
689
                                                                        driver.context.pop_var(); driver.context.pop_var();
 
690
                                                                        driver.context.pop_var(); driver.context.pop_var();
 
691
                                                                        driver.context.push_var($$);
 
692
                                                                }
 
693
        | PGS_REFERENCE '(' expression ',' expression ',' expression ',' expression ')'
 
694
                                                                {
 
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($$);
 
699
                                                                }
 
700
        ;
 
701
 
 
702
statement
 
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; }
 
711
        ;
 
712
 
 
713
statement_list
 
714
        : statement                                     {
 
715
                                                                        driver.context.pop_stmt(); // $1
 
716
                                                                        $$ = driver.context.stmt_list(&(driver.thread));
 
717
                                                                        $$->insert_back($1);
 
718
                                                                }
 
719
        | statement_list statement      {
 
720
                                                                        driver.context.pop_stmt(); // $2
 
721
                                                                        $$ = $1;                                                
 
722
                                                                        $$->insert_back($2);
 
723
                                                                }
 
724
        ;
 
725
        
 
726
compound_statement
 
727
        : PGS_OPEN PGS_CLOSE            {
 
728
                                                                        wxLogScriptVerbose(wxT("BEGIN END"));
 
729
                                                                        $$ = driver.context.stmt_list(&(driver.thread));
 
730
                                                                }
 
731
        | PGS_OPEN statement_list PGS_CLOSE
 
732
                                                                {
 
733
                                                                        wxLogScriptVerbose(wxT("BEGIN ... END"));
 
734
                                                                        $$ = $2;
 
735
                                                                }
 
736
        ;
 
737
        
 
738
sql_statement
 
739
        : sql_expression                        {
 
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);
 
745
                                                                }
 
746
        ;
 
747
        
 
748
sql_expression
 
749
        : sql_query                             {
 
750
                                                                        $$ = pnew pgsExecute(*($1), &driver.context.m_cout,
 
751
                                                                                        &(driver.thread));
 
752
                                                                        pdelete($1);
 
753
                                                                        driver.context.push_var($$); // pgsExecute
 
754
                                                                }
 
755
        ;
 
756
        
 
757
sql_query
 
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; }
 
802
        ;
 
803
        
 
804
declaration_statement
 
805
        : PGS_DECLARE_ASSGN declaration_list
 
806
                                                                {
 
807
                                                                        $$ = $2;
 
808
                                                                }
 
809
        ;
 
810
        
 
811
declaration_list
 
812
        : declaration_element           {
 
813
                                                                        driver.context.pop_stmt(); // $1
 
814
                                                                        $$ = driver.context.stmt_list(&(driver.thread));
 
815
                                                                        $$->insert_back($1);
 
816
 
 
817
                                                                }
 
818
        | declaration_list ',' declaration_element
 
819
                                                                {
 
820
                                                                        driver.context.pop_stmt(); // $3
 
821
                                                                        $$ = $1;
 
822
                                                                        $$->insert_back($3);
 
823
                                                                }
 
824
        ;
 
825
        
 
826
declaration_element
 
827
        : PGS_IDENTIFIER                        {
 
828
                                                                        wxLogScriptVerbose(wxT("DECLARE %s"), $1->c_str());
 
829
                                                                        
 
830
                                                                        $$ = pnew pgsExpressionStmt(pnew pgsAssign(*($1),
 
831
                                                                                        pnew pgsString(wxT(""))), &(driver.thread));
 
832
                                                                        driver.context.push_stmt($$); // pgsExpressionStmt
 
833
                                                                        $$->set_position(yyloc.begin.line);
 
834
                                                                        
 
835
                                                                        pdelete($1);
 
836
                                                                }
 
837
        |  PGS_IDENTIFIER '{' record_declaration_list '}'
 
838
                                                                {
 
839
                                                                        wxLogScriptVerbose(wxT("DECLARE %s"), $1->c_str());
 
840
                                                                        
 
841
                                                                        $$ = pnew pgsDeclareRecordStmt(*($1), driver.context.columns(),
 
842
                                                                                        &(driver.thread));
 
843
                                                                        driver.context.push_stmt($$); // pgsDeclareRecordStmt
 
844
                                                                        $$->set_position(yyloc.begin.line);
 
845
                                                                        
 
846
                                                                        driver.context.clear_columns();
 
847
                                                                        pdelete($1);
 
848
                                                                }
 
849
        ;
 
850
 
 
851
assign_statement
 
852
        : PGS_SET_ASSIGN assign_list
 
853
                                                                {
 
854
                                                                        $$ = $2;
 
855
                                                                }
 
856
        ;
 
857
 
 
858
assign_list
 
859
        : assign_element                        {
 
860
                                                                        driver.context.pop_stmt(); // $1
 
861
                                                                        $$ = driver.context.stmt_list(&(driver.thread));
 
862
                                                                        $$->insert_back($1);
 
863
                                                                }
 
864
        | assign_list ',' assign_element
 
865
                                                                {
 
866
                                                                        driver.context.pop_stmt(); // $3
 
867
                                                                        $$ = $1;
 
868
                                                                        $$->insert_back($3);
 
869
                                                                }
 
870
        ;
 
871
 
 
872
assign_element
 
873
        : PGS_IDENTIFIER PGS_EQ_OP expression
 
874
                                                                {
 
875
                                                                        wxLogScriptVerbose(wxT("SET %s = %s"), $1->c_str(),
 
876
                                                                                        $3->value().c_str());
 
877
                                                                        
 
878
                                                                        $$ = pnew pgsExpressionStmt(pnew pgsAssign(*($1), $3),
 
879
                                                                                        &(driver.thread));
 
880
                                                                        driver.context.pop_var(); // $3
 
881
                                                                        driver.context.push_stmt($$); // pgsExpressionStmt
 
882
                                                                        $$->set_position(yyloc.begin.line);
 
883
                                                                        
 
884
                                                                        pdelete($1);
 
885
                                                                }
 
886
        | PGS_IDENTIFIER '[' expression ']' '[' expression ']' PGS_EQ_OP expression
 
887
                                                                {
 
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());
 
891
                                                                        
 
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);
 
898
                                                                        
 
899
                                                                        pdelete($1);
 
900
                                                                }
 
901
        | PGS_IDENTIFIER PGS_EQ_OP sql_expression
 
902
                                                                {
 
903
                                                                        wxLogScriptVerbose(wxT("SET %s = %s"), $1->c_str(),
 
904
                                                                                        $3->value().c_str());
 
905
                                                                        
 
906
                                                                        $$ = pnew pgsExpressionStmt(pnew pgsAssign(*($1), $3),
 
907
                                                                                        &(driver.thread));
 
908
                                                                        driver.context.pop_var(); // $3
 
909
                                                                        driver.context.push_stmt($$); // pgsExpressionStmt
 
910
                                                                        $$->set_position(yyloc.begin.line);
 
911
                                                                        
 
912
                                                                        pdelete($1);
 
913
                                                                }
 
914
        ;
 
915
 
 
916
selection_statement
 
917
        : PGS_IF expression statement %prec PGS_ELSE
 
918
                                                                {
 
919
                                                                        wxLogScriptVerbose(wxT("IF %s"), $2->value().c_str());
 
920
                                                                        
 
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);
 
928
                                                                }
 
929
        | PGS_IF expression statement PGS_ELSE statement
 
930
                                                                {
 
931
                                                                        wxLogScriptVerbose(wxT("IF %s"), $2->value().c_str());
 
932
                                                                        
 
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);
 
939
                                                                }
 
940
        ;
 
941
 
 
942
iteration_statement
 
943
        : PGS_WHILE expression statement
 
944
                                                                {
 
945
                                                                        wxLogScriptVerbose(wxT("WHILE %s"), $2->value().c_str());
 
946
                                                                        
 
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);
 
952
                                                                }
 
953
        ;
 
954
        
 
955
jump_statement
 
956
        : PGS_BREAK                                     {
 
957
                                                                        wxLogScriptVerbose(wxT("BREAK"));
 
958
                                                                        
 
959
                                                                        $$ = pnew pgsBreakStmt(&(driver.thread));
 
960
                                                                        driver.context.push_stmt($$); // pgsBreakStmt
 
961
                                                                        $$->set_position(yyloc.begin.line);
 
962
                                                                }
 
963
        | PGS_RETURN                            {
 
964
                                                                        wxLogScriptVerbose(wxT("RETURN"));
 
965
                                                                        
 
966
                                                                        $$ = pnew pgsBreakStmt(&(driver.thread));
 
967
                                                                        driver.context.push_stmt($$); // pgsBreakStmt
 
968
                                                                        $$->set_position(yyloc.begin.line);
 
969
                                                                }
 
970
        | PGS_CONTINUE                          {
 
971
                                                                        wxLogScriptVerbose(wxT("CONTINUE"));
 
972
                                                                        
 
973
                                                                        $$ = pnew pgsContinueStmt(&(driver.thread));
 
974
                                                                        driver.context.push_stmt($$); // pgsContinueStmt
 
975
                                                                        $$->set_position(yyloc.begin.line);
 
976
                                                                }
 
977
        ;
 
978
        
 
979
procedure_statement
 
980
        : PGS_PRINT expression
 
981
                                                                {
 
982
                                                                        wxLogScriptVerbose(wxT("PRINT %s"), $2->value().c_str());
 
983
                                                                        
 
984
                                                                        $$ = pnew pgsPrintStmt($2, driver.context.m_cout,
 
985
                                                                                        &(driver.thread));
 
986
                                                                        driver.context.pop_var(); // $2
 
987
                                                                        driver.context.push_stmt($$); // pgsPrintStmt
 
988
                                                                        $$->set_position(yyloc.begin.line);
 
989
                                                                }
 
990
        | PGS_ASSERT expression
 
991
                                                                {
 
992
                                                                        wxLogScriptVerbose(wxT("ASSERT %s"), $2->value().c_str());
 
993
                                                                        
 
994
                                                                        $$ = pnew pgsAssertStmt($2, &(driver.thread));
 
995
                                                                        driver.context.pop_var(); // $2
 
996
                                                                        driver.context.push_stmt($$); // pgsAssertStmt
 
997
                                                                        $$->set_position(yyloc.begin.line);
 
998
                                                                }
 
999
        | PGS_RM_LINE '(' PGS_IDENTIFIER '[' expression ']' ')'
 
1000
                                                                {
 
1001
                                                                        wxLogScriptVerbose(wxT("RMLINE %s[%s]"), $3->c_str(),
 
1002
                                                                                        $5->value().c_str());
 
1003
                                                                        
 
1004
                                                                        $$ = pnew pgsExpressionStmt(pnew pgsRemoveLine(*($3), $5),
 
1005
                                                                                        &(driver.thread));
 
1006
                                                                        driver.context.pop_var(); // $5
 
1007
                                                                        driver.context.push_stmt($$); // pgsExpressionStmt
 
1008
                                                                        $$->set_position(yyloc.begin.line);
 
1009
                                                                        
 
1010
                                                                        pdelete($3);
 
1011
                                                                }
 
1012
        ;
 
1013
        
 
1014
record_declaration_list
 
1015
        : PGS_IDENTIFIER                        {
 
1016
                                                                        driver.context.add_column(*$1);
 
1017
                                                                        pdelete($1);
 
1018
                                                                }
 
1019
        | record_declaration_list ',' PGS_IDENTIFIER
 
1020
                                                                {
 
1021
                                                                        driver.context.add_column(*$3);
 
1022
                                                                        pdelete($3);
 
1023
                                                                }
 
1024
        ;
 
1025
 
 
1026
translation_unit
 
1027
        : PGS_END
 
1028
        | statement_list PGS_END        {
 
1029
                                                                        driver.program.eval($1);
 
1030
                                                                        
 
1031
                                                                        driver.context.pop_stmt();
 
1032
                                                                        pdelete($1); // delete root statement $1
 
1033
                                                                }
 
1034
        ;
 
1035
 
 
1036
%% /*** Additional Code ***/
 
1037
 
 
1038
void pgscript::pgsParser::error(const pgsParser::location_type & l,
 
1039
                const std::string & m)
 
1040
{
 
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));
 
1045
}