1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
|
%{ /*** C/C++ Declarations ***/
//////////////////////////////////////////////////////////////////////////
//
// pgScript - PostgreSQL Tools
//
// Copyright (C) 2002 - 2012, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////////////////
#include "pgscript/pgScript.h"
#include "pgscript/statements/pgsStatements.h"
#include "pgscript/expressions/pgsExpressions.h"
#include "pgscript/objects/pgsObjects.h"
#include "pgscript/utilities/pgsContext.h"
%}
/*** YACC/Bison declarations ***/
/* Require bison 2.3 or later */
%require "2.3"
/* Start symbol is named "start" */
%start translation_unit
/* Write out a header file containing the token defines */
%defines
/* Use newer C++ skeleton file */
%skeleton "lalr1.cc"
/* Namespace to enclose parser in */
%name-prefix="pgscript"
/* Set the parser's class identifier */
%define "parser_class_name" "pgsParser"
/* Keep track of the current position within the input */
%locations
%initial-action
{
// Initialize the initial location object
@$.begin.filename = @$.end.filename;
};
/* The driver is passed by reference to the parser and to the scanner. This
* provides a simple but effective pure interface, not relying on global
* variables. */
%parse-param { class pgsDriver & driver }
/* Verbose error messages */
%error-verbose
%token PGS_END 0 "END OF FILE"
%token PGS_WHILE "WHILE"
%token PGS_BREAK "BREAK"
%token PGS_RETURN "RETURN"
%token PGS_CONTINUE "CONTINUE"
%token PGS_IF "IF"
%token PGS_ELSE "ELSE"
%token PGS_WAITFOR "WAITFOR"
%token PGS_AS "AS"
%token PGS_OPEN "BEGIN (BLOCK)"
%token PGS_CLOSE "END (BLOCK)"
%token PGS_ASSERT "ASSERT"
%token PGS_PRINT "PRINT"
%token PGS_LOG "LOG"
%token PGS_CNT_COLUMNS "COLUMNS"
%token PGS_CNT_LINES "LINES"
%token PGS_TRIM "TRIM"
%token PGS_RM_LINE "RMLINE"
%token PGS_CAST "CAST"
%token PGS_RECORD "RECORD"
%token PGS_INTEGER "INTEGER"
%token PGS_REAL "REAL"
%token PGS_STRING "STRING"
%token PGS_REGEX "REGEX"
%token PGS_FILE "FILE"
%token PGS_DATE "DATE"
%token PGS_TIME "TIME"
%token PGS_DATE_TIME "DATETIME"
%token PGS_REFERENCE "REFERENCE"
%token PGS_LE_OP "<="
%token PGS_GE_OP ">="
%token PGS_EQ_OP "="
%token PGS_AE_OP "~="
%token PGS_NE_OP "<>"
%token PGS_AND_OP "AND"
%token PGS_OR_OP "OR"
%token PGS_NOT_OP "NOT"
%token PGS_UNKNOWN "character"
%right PGS_ELSE
%union
{
const wxString * str;
int integer;
pgsExpression * expr;
pgsStmt * stmt;
pgsStmtList * stmt_list;
}
%token PGS_SET_ASSIGN "SET @VARIABLE"
%token PGS_DECLARE_ASSGN "DECLARE @VARIABLE"
%token<str> PGS_ABORT "ABORT"
%token<str> PGS_ALTER "ALTER"
%token<str> PGS_ANALYZE "ANALYZE"
%token<str> PGS_BEGIN "BEGIN"
%token<str> PGS_CHECKPOINT "CHECKPOINT"
%token<str> PGS_CLOSE_ST "CLOSE"
%token<str> PGS_CLUSTER "CLUSTER"
%token<str> PGS_COMMENT "COMMENT"
%token<str> PGS_COMMIT "COMMIT"
%token<str> PGS_COPY "COPY"
%token<str> PGS_CREATE "CREATE"
%token<str> PGS_DEALLOCATE "DEALLOCATE"
%token<str> PGS_DECLARE "DECLARE"
%token<str> PGS_DELETE "DELETE"
%token<str> PGS_DISCARD "DISCARD"
%token<str> PGS_DROP "DROP"
%token<str> PGS_END_ST "END"
%token<str> PGS_EXECUTE "EXECUTE"
%token<str> PGS_EXPLAIN "EXPLAIN"
%token<str> PGS_FETCH "FETCH"
%token<str> PGS_GRANT "GRANT"
%token<str> PGS_INSERT "INSERT"
%token<str> PGS_LISTEN "LISTEN"
%token<str> PGS_LOAD "LOAD"
%token<str> PGS_LOCK "LOCK"
%token<str> PGS_MOVE "MOVE"
%token<str> PGS_NOTIFY "NOTIFY"
%token<str> PGS_PREPARE "PREPARE"
%token<str> PGS_REASSIGN "REASSIGN"
%token<str> PGS_REINDEX "REINDEX"
%token<str> PGS_RELEASE "RELEASE"
%token<str> PGS_RESET "RESET"
%token<str> PGS_REVOKE "REVOKE"
%token<str> PGS_ROLLBACK "ROLLBACK"
%token<str> PGS_SAVEPOINT "SAVEPOINT"
%token<str> PGS_SELECT "SELECT"
%token<str> PGS_SET "SET"
%token<str> PGS_SHOW "SHOW"
%token<str> PGS_START "START"
%token<str> PGS_TRUNCATE "TRUNCATE"
%token<str> PGS_UNLISTEN "UNLISTEN"
%token<str> PGS_UPDATE "UPDATE"
%token<str> PGS_VACUUM "VACUUM"
%token<str> PGS_VALUES "VALUES"
%token<str> PGS_IDENTIFIER "IDENTIFIER"
%token<str> PGS_VAL_INT "INTEGER VALUE"
%token<str> PGS_VAL_REAL "REAL VALUE"
%token<str> PGS_VAL_STR "STRING VALUE"
%destructor { pdelete($$); } PGS_ABORT
%destructor { pdelete($$); } PGS_ALTER
%destructor { pdelete($$); } PGS_ANALYZE
%destructor { pdelete($$); } PGS_BEGIN
%destructor { pdelete($$); } PGS_CHECKPOINT
%destructor { pdelete($$); } PGS_CLOSE_ST
%destructor { pdelete($$); } PGS_CLUSTER
%destructor { pdelete($$); } PGS_COMMENT
%destructor { pdelete($$); } PGS_COMMIT
%destructor { pdelete($$); } PGS_COPY
%destructor { pdelete($$); } PGS_CREATE
%destructor { pdelete($$); } PGS_DEALLOCATE
%destructor { pdelete($$); } PGS_DECLARE
%destructor { pdelete($$); } PGS_DELETE
%destructor { pdelete($$); } PGS_DISCARD
%destructor { pdelete($$); } PGS_DROP
%destructor { pdelete($$); } PGS_END_ST
%destructor { pdelete($$); } PGS_EXECUTE
%destructor { pdelete($$); } PGS_EXPLAIN
%destructor { pdelete($$); } PGS_FETCH
%destructor { pdelete($$); } PGS_GRANT
%destructor { pdelete($$); } PGS_INSERT
%destructor { pdelete($$); } PGS_LISTEN
%destructor { pdelete($$); } PGS_LOAD
%destructor { pdelete($$); } PGS_LOCK
%destructor { pdelete($$); } PGS_MOVE
%destructor { pdelete($$); } PGS_NOTIFY
%destructor { pdelete($$); } PGS_PREPARE
%destructor { pdelete($$); } PGS_REASSIGN
%destructor { pdelete($$); } PGS_REINDEX
%destructor { pdelete($$); } PGS_RELEASE
%destructor { pdelete($$); } PGS_RESET
%destructor { pdelete($$); } PGS_REVOKE
%destructor { pdelete($$); } PGS_ROLLBACK
%destructor { pdelete($$); } PGS_SAVEPOINT
%destructor { pdelete($$); } PGS_SELECT
%destructor { pdelete($$); } PGS_SET
%destructor { pdelete($$); } PGS_SHOW
%destructor { pdelete($$); } PGS_START
%destructor { pdelete($$); } PGS_TRUNCATE
%destructor { pdelete($$); } PGS_UNLISTEN
%destructor { pdelete($$); } PGS_UPDATE
%destructor { pdelete($$); } PGS_VACUUM
%destructor { pdelete($$); } PGS_VALUES
%destructor { pdelete($$); } PGS_IDENTIFIER
%destructor { pdelete($$); } PGS_VAL_INT
%destructor { pdelete($$); } PGS_VAL_REAL
%destructor { pdelete($$); } PGS_VAL_STR
%type<expr> postfix_expression
%type<expr> unary_expression
%type<expr> cast_expression
%type<expr> multiplicative_expression
%type<expr> additive_expression
%type<expr> relational_expression
%type<expr> equality_expression
%type<expr> logical_and_expression
%type<expr> logical_or_expression
%type<expr> expression
%type<expr> random_generator
%type<expr> sql_expression
%type<str> sql_query
%type<integer> type_name
%type<stmt> statement
%type<stmt> compound_statement
%type<stmt> sql_statement
%type<stmt> selection_statement
%type<stmt> iteration_statement
%type<stmt> procedure_statement
%type<stmt> jump_statement
%type<stmt> declaration_statement
%type<stmt> assign_statement
%type<stmt_list> declaration_list
%type<stmt_list> assign_list
%type<stmt> declaration_element
%type<stmt> assign_element
%type<stmt_list> statement_list
%{
#include "pgscript/utilities/pgsDriver.h"
#include "pgscript/utilities/pgsScanner.h"
/* This "connects" the bison parser in the driver to the flex scanner class
* object. It defines the yylex() function call to pull the next token from the
* current lexer object of the driver context. */
#undef yylex
#define yylex driver.lexer->lex
%}
%% /*** Grammar Rules ***/
postfix_expression
: PGS_IDENTIFIER '[' expression ']' '[' expression ']'
{
$$ = pnew pgsIdentRecord(*($1), $3, $6);
pdelete($1);
driver.context.pop_var(); driver.context.pop_var(); // $3 & $6
driver.context.push_var($$);
}
| PGS_IDENTIFIER '[' expression ']'
{
$$ = pnew pgsIdentRecord(*($1), $3);
pdelete($1);
driver.context.pop_var(); // $3
driver.context.push_var($$);
}
| PGS_CNT_LINES '(' PGS_IDENTIFIER ')'
{
$$ = pnew pgsLines(*($3));
pdelete($3);
driver.context.push_var($$);
}
| PGS_CNT_COLUMNS '(' PGS_IDENTIFIER ')'
{
$$ = pnew pgsColumns(*($3));
pdelete($3);
driver.context.push_var($$);
}
| PGS_TRIM '(' expression ')'
{
$$ = pnew pgsTrim($3);
driver.context.pop_var(); // $3
driver.context.push_var($$); // assert
}
| PGS_IDENTIFIER
{
$$ = pnew pgsIdent(*($1));
pdelete($1);
driver.context.push_var($$);
}
| PGS_VAL_INT
{
$$ = pnew pgsNumber(*($1), pgsInt);
pdelete($1);
driver.context.push_var($$);
}
| PGS_VAL_REAL
{
$$ = pnew pgsNumber(*($1), pgsReal);
pdelete($1);
driver.context.push_var($$);
}
| PGS_VAL_STR
{
$$ = pnew pgsString(*($1));
pdelete($1);
driver.context.push_var($$);
}
| '(' PGS_SELECT ')' {
$$ = pnew pgsExecute(*($2), &driver.context.m_cout,
&(driver.thread));
pdelete($2);
driver.context.push_var($$); // SQL Expression statement
}
| random_generator { $$ = $1; }
| '(' expression ')' {
$$ = pnew pgsParenthesis($2);
driver.context.pop_var(); // $2
driver.context.push_var($$);
}
;
unary_expression
: postfix_expression { $$ = $1; }
| '+' cast_expression { $$ = $2; }
| '-' cast_expression {
$$ = pnew pgsNegate($2);
driver.context.pop_var(); // $2
driver.context.push_var($$);
}
| PGS_NOT_OP cast_expression
{
$$ = pnew pgsNot($2);
driver.context.pop_var(); // $2
driver.context.push_var($$);
}
;
cast_expression
: unary_expression { $$ = $1; }
| PGS_CAST '(' cast_expression PGS_AS type_name ')'
{
$$ = pnew pgsCast($5, $3);
driver.context.pop_var(); // $3
driver.context.push_var($$);
}
;
type_name
: PGS_INTEGER { $$ = pgscript::pgsParser::token::PGS_INTEGER; }
| PGS_REAL { $$ = pgscript::pgsParser::token::PGS_REAL; }
| PGS_STRING { $$ = pgscript::pgsParser::token::PGS_STRING; }
| PGS_RECORD { $$ = pgscript::pgsParser::token::PGS_RECORD; }
;
multiplicative_expression
: cast_expression { $$ = $1; }
| multiplicative_expression '*' cast_expression
{
$$ = pnew pgsTimes($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
| multiplicative_expression '/' cast_expression
{
$$ = pnew pgsOver($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
| multiplicative_expression '%' cast_expression
{
$$ = pnew pgsModulo($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
;
additive_expression
: multiplicative_expression { $$ = $1; }
| additive_expression '+' multiplicative_expression
{
$$ = pnew pgsPlus($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
| additive_expression '-' multiplicative_expression
{
$$ = pnew pgsMinus($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
;
relational_expression
: additive_expression { $$ = $1; }
| relational_expression '<' additive_expression
{
$$ = pnew pgsLower($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
| relational_expression '>' additive_expression
{
$$ = pnew pgsGreater($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
| relational_expression PGS_LE_OP additive_expression
{
$$ = pnew pgsLowerEqual($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
| relational_expression PGS_GE_OP additive_expression
{
$$ = pnew pgsGreaterEqual($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
;
equality_expression
: relational_expression { $$ = $1; }
| equality_expression PGS_EQ_OP relational_expression
{
$$ = pnew pgsEqual($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
| equality_expression PGS_AE_OP relational_expression
{
$$ = pnew pgsEqual($1, $3, false);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
| equality_expression PGS_NE_OP relational_expression
{
$$ = pnew pgsDifferent($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
;
logical_and_expression
: equality_expression { $$ = $1; }
| logical_and_expression PGS_AND_OP equality_expression
{
$$ = pnew pgsAnd($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
;
logical_or_expression
: logical_and_expression { $$ = $1; }
| logical_or_expression PGS_OR_OP logical_and_expression
{
$$ = pnew pgsOr($1, $3);
driver.context.pop_var();
driver.context.pop_var(); // $1 & $3
driver.context.push_var($$);
}
;
expression
: logical_or_expression {
wxLogScriptVerbose(wxT("%s"), $1->value().c_str());
$$ = $1;
}
;
random_generator
: PGS_INTEGER '(' expression ',' expression ')'
{
$$ = pnew pgsGenInt($3, $5, driver.context.zero(),
driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_INTEGER '(' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenInt($3, $5, $7, driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_INTEGER '(' expression ',' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenInt($3, $5, $7, $9);
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_REAL '(' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenReal($3, $5, $7, driver.context.zero(),
driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_REAL '(' expression ',' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenReal($3, $5, $7, $9, driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_REAL '(' expression ',' expression ',' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenReal($3, $5, $7, $9, $11);
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_STRING '(' expression ',' expression ')'
{
$$ = pnew pgsGenString($3, $5, driver.context.one(),
driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_STRING '(' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenString($3, $5, $7, driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_STRING '(' expression ',' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenString($3, $5, $7, $9);
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_REGEX '(' expression ')'
{
$$ = pnew pgsGenRegex($3, driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_REGEX '(' expression ',' expression ')'
{
$$ = pnew pgsGenRegex($3, $5);
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_FILE '(' expression ')'
{
$$ = pnew pgsGenDictionary($3, driver.context.zero(),
driver.context.seed(), driver.context.encoding());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_FILE '(' expression ',' expression ')'
{
$$ = pnew pgsGenDictionary($3, $5, driver.context.seed(),
driver.context.encoding());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_FILE '(' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenDictionary($3, $5, $7, driver.context.encoding());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_FILE '(' expression ',' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenDictionary($3, $5, $7, $9);
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_DATE '(' expression ',' expression ')'
{
$$ = pnew pgsGenDate($3, $5, driver.context.zero(),
driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_DATE '(' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenDate($3, $5, $7, driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_DATE '(' expression ',' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenDate($3, $5, $7, $9);
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_TIME '(' expression ',' expression ')'
{
$$ = pnew pgsGenTime($3, $5, driver.context.zero(),
driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_TIME '(' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenTime($3, $5, $7, driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_TIME '(' expression ',' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenTime($3, $5, $7, $9);
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_DATE_TIME '(' expression ',' expression ')'
{
$$ = pnew pgsGenDateTime($3, $5, driver.context.zero(),
driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_DATE_TIME '(' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenDateTime($3, $5, $7, driver.context.seed());
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_DATE_TIME '(' expression ',' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenDateTime($3, $5, $7, $9);
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_REFERENCE '(' expression ',' expression ')'
{
$$ = pnew pgsGenReference($3, $5, driver.context.zero(),
driver.context.seed(), &(driver.thread));
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_REFERENCE '(' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenReference($3, $5, $7, driver.context.seed(),
&(driver.thread));
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
| PGS_REFERENCE '(' expression ',' expression ',' expression ',' expression ')'
{
$$ = pnew pgsGenReference($3, $5, $7, $9, &(driver.thread));
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); driver.context.pop_var();
driver.context.push_var($$);
}
;
statement
: compound_statement { $$ = $1; }
| selection_statement { $$ = $1; }
| iteration_statement { $$ = $1; }
| sql_statement ';' { $$ = $1; }
| procedure_statement ';' { $$ = $1; }
| jump_statement ';' { $$ = $1; }
| declaration_statement ';' { $$ = $1; }
| assign_statement ';' { $$ = $1; }
;
statement_list
: statement {
driver.context.pop_stmt(); // $1
$$ = driver.context.stmt_list(&(driver.thread));
$$->insert_back($1);
}
| statement_list statement {
driver.context.pop_stmt(); // $2
$$ = $1;
$$->insert_back($2);
}
;
compound_statement
: PGS_OPEN PGS_CLOSE {
wxLogScriptVerbose(wxT("BEGIN END"));
$$ = driver.context.stmt_list(&(driver.thread));
}
| PGS_OPEN statement_list PGS_CLOSE
{
wxLogScriptVerbose(wxT("BEGIN ... END"));
$$ = $2;
}
;
sql_statement
: sql_expression {
wxLogScriptVerbose(wxT("%s"), $1->value().c_str());
$$ = pnew pgsExpressionStmt($1, &(driver.thread));
driver.context.pop_var(); // $1
driver.context.push_stmt($$); // pgsExpressionStmt
$$->set_position(yyloc.begin.line);
}
;
sql_expression
: sql_query {
$$ = pnew pgsExecute(*($1), &driver.context.m_cout,
&(driver.thread));
pdelete($1);
driver.context.push_var($$); // pgsExecute
}
;
sql_query
: PGS_ABORT { $$ = $1; }
| PGS_ALTER { $$ = $1; }
| PGS_ANALYZE { $$ = $1; }
| PGS_BEGIN { $$ = $1; }
| PGS_CHECKPOINT { $$ = $1; }
| PGS_CLOSE_ST { $$ = $1; }
| PGS_CLUSTER { $$ = $1; }
| PGS_COMMENT { $$ = $1; }
| PGS_COMMIT { $$ = $1; }
| PGS_COPY { $$ = $1; }
| PGS_CREATE { $$ = $1; }
| PGS_DEALLOCATE { $$ = $1; }
| PGS_DECLARE { $$ = $1; }
| PGS_DELETE { $$ = $1; }
| PGS_DISCARD { $$ = $1; }
| PGS_DROP { $$ = $1; }
| PGS_END_ST { $$ = $1; }
| PGS_EXECUTE { $$ = $1; }
| PGS_EXPLAIN { $$ = $1; }
| PGS_FETCH { $$ = $1; }
| PGS_GRANT { $$ = $1; }
| PGS_INSERT { $$ = $1; }
| PGS_LISTEN { $$ = $1; }
| PGS_LOAD { $$ = $1; }
| PGS_LOCK { $$ = $1; }
| PGS_MOVE { $$ = $1; }
| PGS_NOTIFY { $$ = $1; }
| PGS_PREPARE { $$ = $1; }
| PGS_REASSIGN { $$ = $1; }
| PGS_REINDEX { $$ = $1; }
| PGS_RELEASE { $$ = $1; }
| PGS_RESET { $$ = $1; }
| PGS_REVOKE { $$ = $1; }
| PGS_ROLLBACK { $$ = $1; }
| PGS_SAVEPOINT { $$ = $1; }
| PGS_SELECT { $$ = $1; }
| PGS_SET { $$ = $1; }
| PGS_SHOW { $$ = $1; }
| PGS_START { $$ = $1; }
| PGS_TRUNCATE { $$ = $1; }
| PGS_UNLISTEN { $$ = $1; }
| PGS_UPDATE { $$ = $1; }
| PGS_VACUUM { $$ = $1; }
| PGS_VALUES { $$ = $1; }
;
declaration_statement
: PGS_DECLARE_ASSGN declaration_list
{
$$ = $2;
}
;
declaration_list
: declaration_element {
driver.context.pop_stmt(); // $1
$$ = driver.context.stmt_list(&(driver.thread));
$$->insert_back($1);
}
| declaration_list ',' declaration_element
{
driver.context.pop_stmt(); // $3
$$ = $1;
$$->insert_back($3);
}
;
declaration_element
: PGS_IDENTIFIER {
wxLogScriptVerbose(wxT("DECLARE %s"), $1->c_str());
$$ = pnew pgsExpressionStmt(pnew pgsAssign(*($1),
pnew pgsString(wxT(""))), &(driver.thread));
driver.context.push_stmt($$); // pgsExpressionStmt
$$->set_position(yyloc.begin.line);
pdelete($1);
}
| PGS_IDENTIFIER '{' record_declaration_list '}'
{
wxLogScriptVerbose(wxT("DECLARE %s"), $1->c_str());
$$ = pnew pgsDeclareRecordStmt(*($1), driver.context.columns(),
&(driver.thread));
driver.context.push_stmt($$); // pgsDeclareRecordStmt
$$->set_position(yyloc.begin.line);
driver.context.clear_columns();
pdelete($1);
}
;
assign_statement
: PGS_SET_ASSIGN assign_list
{
$$ = $2;
}
;
assign_list
: assign_element {
driver.context.pop_stmt(); // $1
$$ = driver.context.stmt_list(&(driver.thread));
$$->insert_back($1);
}
| assign_list ',' assign_element
{
driver.context.pop_stmt(); // $3
$$ = $1;
$$->insert_back($3);
}
;
assign_element
: PGS_IDENTIFIER PGS_EQ_OP expression
{
wxLogScriptVerbose(wxT("SET %s = %s"), $1->c_str(),
$3->value().c_str());
$$ = pnew pgsExpressionStmt(pnew pgsAssign(*($1), $3),
&(driver.thread));
driver.context.pop_var(); // $3
driver.context.push_stmt($$); // pgsExpressionStmt
$$->set_position(yyloc.begin.line);
pdelete($1);
}
| PGS_IDENTIFIER '[' expression ']' '[' expression ']' PGS_EQ_OP expression
{
wxLogScriptVerbose(wxT("SET %s[%s][%s] = %s"),
$1->c_str(), $3->value().c_str(),
$6->value().c_str(), $9->value().c_str());
$$ = pnew pgsExpressionStmt(pnew pgsAssignToRecord(*($1),
$3, $6, $9), &(driver.thread));
driver.context.pop_var(); driver.context.pop_var();
driver.context.pop_var(); // $3 & $6 & $9
driver.context.push_stmt($$); // pgsExpressionStmt
$$->set_position(yyloc.begin.line);
pdelete($1);
}
| PGS_IDENTIFIER PGS_EQ_OP sql_expression
{
wxLogScriptVerbose(wxT("SET %s = %s"), $1->c_str(),
$3->value().c_str());
$$ = pnew pgsExpressionStmt(pnew pgsAssign(*($1), $3),
&(driver.thread));
driver.context.pop_var(); // $3
driver.context.push_stmt($$); // pgsExpressionStmt
$$->set_position(yyloc.begin.line);
pdelete($1);
}
;
selection_statement
: PGS_IF expression statement %prec PGS_ELSE
{
wxLogScriptVerbose(wxT("IF %s"), $2->value().c_str());
$$ = pnew pgsIfStmt($2, $3, driver.context
.stmt_list(&(driver.thread)), &(driver.thread));
driver.context.pop_var(); // $2
driver.context.pop_stmt(); // $3
driver.context.pop_stmt(); // stmt_list
driver.context.push_stmt($$); // pgsIfStmt
$$->set_position(yyloc.begin.line);
}
| PGS_IF expression statement PGS_ELSE statement
{
wxLogScriptVerbose(wxT("IF %s"), $2->value().c_str());
$$ = pnew pgsIfStmt($2, $3, $5, &(driver.thread));
driver.context.pop_var(); // $2
driver.context.pop_stmt(); // $3
driver.context.pop_stmt(); // $5
driver.context.push_stmt($$); // pgsIfStmt
$$->set_position(yyloc.begin.line);
}
;
iteration_statement
: PGS_WHILE expression statement
{
wxLogScriptVerbose(wxT("WHILE %s"), $2->value().c_str());
$$ = pnew pgsWhileStmt($2, $3, &(driver.thread));
driver.context.pop_var(); // $2
driver.context.pop_stmt(); // $3
driver.context.push_stmt($$); // pgsWhileStmt
$$->set_position(yyloc.begin.line);
}
;
jump_statement
: PGS_BREAK {
wxLogScriptVerbose(wxT("BREAK"));
$$ = pnew pgsBreakStmt(&(driver.thread));
driver.context.push_stmt($$); // pgsBreakStmt
$$->set_position(yyloc.begin.line);
}
| PGS_RETURN {
wxLogScriptVerbose(wxT("RETURN"));
$$ = pnew pgsBreakStmt(&(driver.thread));
driver.context.push_stmt($$); // pgsBreakStmt
$$->set_position(yyloc.begin.line);
}
| PGS_CONTINUE {
wxLogScriptVerbose(wxT("CONTINUE"));
$$ = pnew pgsContinueStmt(&(driver.thread));
driver.context.push_stmt($$); // pgsContinueStmt
$$->set_position(yyloc.begin.line);
}
;
procedure_statement
: PGS_PRINT expression
{
wxLogScriptVerbose(wxT("PRINT %s"), $2->value().c_str());
$$ = pnew pgsPrintStmt($2, driver.context.m_cout,
&(driver.thread));
driver.context.pop_var(); // $2
driver.context.push_stmt($$); // pgsPrintStmt
$$->set_position(yyloc.begin.line);
}
| PGS_ASSERT expression
{
wxLogScriptVerbose(wxT("ASSERT %s"), $2->value().c_str());
$$ = pnew pgsAssertStmt($2, &(driver.thread));
driver.context.pop_var(); // $2
driver.context.push_stmt($$); // pgsAssertStmt
$$->set_position(yyloc.begin.line);
}
| PGS_RM_LINE '(' PGS_IDENTIFIER '[' expression ']' ')'
{
wxLogScriptVerbose(wxT("RMLINE %s[%s]"), $3->c_str(),
$5->value().c_str());
$$ = pnew pgsExpressionStmt(pnew pgsRemoveLine(*($3), $5),
&(driver.thread));
driver.context.pop_var(); // $5
driver.context.push_stmt($$); // pgsExpressionStmt
$$->set_position(yyloc.begin.line);
pdelete($3);
}
;
record_declaration_list
: PGS_IDENTIFIER {
driver.context.add_column(*$1);
pdelete($1);
}
| record_declaration_list ',' PGS_IDENTIFIER
{
driver.context.add_column(*$3);
pdelete($3);
}
;
translation_unit
: PGS_END
| statement_list PGS_END {
driver.program.eval($1);
driver.context.pop_stmt();
pdelete($1); // delete root statement $1
}
;
%% /*** Additional Code ***/
void pgscript::pgsParser::error(const pgsParser::location_type & l,
const std::string & m)
{
wxLogScriptVerbose(wxT("EXPR STACK SIZE = %u"), driver.context.size_vars());
wxLogScriptVerbose(wxT("STMT STACK SIZE = %u"), driver.context.size_stmts());
driver.context.clear_stacks();
driver.error(l, wxString(m.c_str(), wxConvUTF8));
}
|