home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / bootstrap / bootparse.y next >
Encoding:
Lex Description  |  1992-08-27  |  6.1 KB  |  366 lines

  1. %{
  2. /* ----------------------------------------------------------------
  3.  *   FILE
  4.  *    backendparse.y
  5.  *
  6.  *   DESCRIPTION
  7.  *    yacc parser grammer for the "backend" initialization
  8.  *    program.  uses backendscan.lex and backendsup.c support
  9.  *    routines.
  10.  *
  11.  *   NOTES
  12.  *
  13.  * ----------------------------------------------------------------
  14.  */
  15. static    char ami_parser_y[] = 
  16.  "$Header: /private/postgres/src/bootstrap/RCS/bootparse.y,v 1.9 1992/03/02 20:59:34 mer Exp $";
  17.  
  18. #include "access/heapam.h"
  19. #include "support/bkint.h"
  20. #include "tmp/portal.h" 
  21. #include "storage/smgr.h" 
  22. #include "nodes/pg_lisp.h"
  23.  
  24. #undef BOOTSTRAP
  25. #include "y.tab.h"
  26.  
  27. #define TRUE 1
  28. #define FALSE 0
  29.  
  30. #define DO_QUERY(query) { StartTransactionCommand();\
  31.               query;\
  32.               CommitTransactionCommand();\
  33.               if (!Quiet) { EMITPROMPT; }\
  34.             }
  35.  
  36. #define DO_START { StartTransactionCommand();\
  37.          }
  38.  
  39. #define DO_END   { CommitTransactionCommand();\
  40.            if (!Quiet) { EMITPROMPT; }\
  41.            fflush(stdout); \
  42.          }
  43.  
  44. int num_tuples_read = 0;
  45. extern int DebugMode;
  46. extern int Quiet;
  47. static OID objectid;
  48.  
  49. %}
  50.  
  51. %token OPEN XCLOSE XCREATE P_RELN INSERT_TUPLE QUIT
  52. %token ID STRING FLOAT INT XDEFINE MACRO INDEX ON USING
  53. %token COMMA COLON EQUALS LPAREN RPAREN AS XIN XTO
  54. %token XDESTROY XRENAME RELATION ATTR ADD
  55. %token DISPLAY OBJ_ID SHOW BOOTSTRAP NULLVAL
  56. %start TopLevel
  57.  
  58. %nonassoc low
  59. %nonassoc high
  60.  
  61. %%
  62.  
  63. TopLevel:
  64.       Queries
  65.     |
  66.     ;
  67.  
  68. Queries:
  69.       Query
  70.     | Queries Query
  71.     ;
  72.  
  73. Query :
  74.         OpenStmt
  75.     | CloseStmt 
  76.     | PrintStmt
  77.     | CreateStmt
  78.     | DestroyStmt
  79.     | InsertStmt 
  80.     | QuitStmt
  81.     | DefineIndexStmt
  82.     | RenameRelnStmt
  83.     | RenameAttrStmt
  84.     | DisplayStmt
  85.     | MacroDefStmt
  86.     ;
  87.  
  88. OpenStmt: 
  89.       OPEN ident
  90.         { 
  91.             DO_START;
  92.             boot_openrel(LexIDStr($2));
  93.             DO_END; 
  94.         }    
  95.     | OPEN LPAREN typelist RPAREN AS ident
  96.         { 
  97.             DO_START;
  98.             createrel(LexIDStr($6));
  99.             DO_END;
  100.         }
  101.     ;
  102.  
  103. CloseStmt:
  104.       XCLOSE ident %prec low
  105.         {
  106.             DO_START;
  107.             closerel(LexIDStr($2));
  108.             DO_END;
  109.         }
  110.     | XCLOSE %prec high
  111.         {
  112.             DO_START;
  113.             closerel(NULL);
  114.             DO_END;
  115.         }
  116.     ;
  117.  
  118. PrintStmt:
  119.           P_RELN
  120.         {
  121.             DO_START;
  122.             printrel();
  123.             DO_END;
  124.         }
  125.     ;
  126.  
  127. CreateStmt:
  128.       XCREATE optbootstrap ident LPAREN 
  129.         { 
  130.             DO_START; 
  131.             numattr=(int)0;
  132.         }
  133.       typelist 
  134.         { 
  135.             DO_END;
  136.         }
  137.       RPAREN 
  138.         { 
  139.             DO_START; 
  140.             if ($2) {
  141.             extern Relation reldesc;
  142.  
  143.             if (reldesc) {
  144.                 puts("create bootstrap: Warning, open relation");
  145.                 puts("exists, closing first");
  146.                 closerel(NULL);
  147.             }
  148.             if (DebugMode)
  149.                 puts("creating bootstrap relation");
  150.             reldesc = heap_creatr(LexIDStr($3),
  151.                           numattr,
  152.                           DEFAULT_SMGR,
  153.                           attrtypes);
  154.             if (DebugMode)
  155.                 puts("bootstrap relation created ok");
  156.             } else {
  157.                 heap_create(LexIDStr($3),
  158.                     'n',
  159.                     numattr,
  160.                     DEFAULT_SMGR,
  161.                     attrtypes);
  162.             }
  163.             DO_END;
  164.             if (DebugMode)
  165.             puts("Commit End");
  166.         }
  167.     ;
  168.  
  169. DestroyStmt:
  170.       XDESTROY ident
  171.         { DO_START; heap_destroy(LexIDStr($2)); DO_END;}
  172.     ;
  173.  
  174. InsertStmt:
  175.       INSERT_TUPLE optoideq        /* $1 $2 $3 */
  176.         { 
  177.             DO_START;
  178.             if (DebugMode)
  179.                 printf("tuple %d<", $2);
  180.             num_tuples_read = 0;
  181.         }
  182.       LPAREN  tuplelist RPAREN    /* $4 $5 $6 */
  183.           {
  184.             HeapTuple tuple;
  185.             if (num_tuples_read != numattr)
  186.                 elog(WARN,"incorrect number of values for tuple");
  187.             if (reldesc == (Relation)NULL) {
  188.                 elog(WARN,"must OPEN RELATION before INSERT\n");
  189.                 err();
  190.             }
  191.             if (DebugMode)
  192.             puts("Insert Begin");
  193.             objectid = $2;
  194.             InsertOneTuple(objectid);
  195.             if (DebugMode)
  196.             puts("Insert End");
  197.             DO_END;
  198.             if (DebugMode)
  199.             puts("Transaction End");
  200.         } 
  201.     ;
  202.  
  203. QuitStmt:
  204.       QUIT
  205.         {
  206.           StartTransactionCommand();
  207.           StartPortalAllocMode(DefaultAllocMode, 0);
  208.           cleanup();
  209.         }
  210.     ;
  211.  
  212. DefineIndexStmt:
  213.       XDEFINE INDEX ident ON ident USING ident LPAREN index_params RPAREN
  214.         {
  215.           List params;
  216.  
  217.           DO_START;
  218.  
  219.           params = nappend1(LispNil, (List)$9);
  220.           defineindex(LexIDStr($5), 
  221.                   LexIDStr($3), 
  222.                   LexIDStr($7),
  223.                   params);
  224.           DO_END;
  225.         }
  226.     ;
  227.  
  228. index_params:
  229.     index_on ident
  230.         {
  231.           $$ = (YYSTYPE)nappend1(LispNil, (List)$1);
  232.           nappend1((List)$$, lispString(LexIDStr($2)));
  233.         }
  234.  
  235. index_on:
  236.       ident
  237.         {
  238.           $$ = (YYSTYPE)lispString(LexIDStr($1));
  239.         }
  240.     | ident LPAREN arg_list RPAREN
  241.         {
  242.           $$ = (YYSTYPE)nappend1(LispNil, lispString(LexIDStr($1)));
  243.           rplacd((List)$$, (List)$3);
  244.         }
  245.  
  246. arg_list:
  247.       ident
  248.         {
  249.           $$ = (YYSTYPE)nappend1(LispNil, lispString(LexIDStr($1)));
  250.         }
  251.     | arg_list COMMA ident
  252.         {
  253.           $$ = (YYSTYPE)nappend1((List)$1, lispString(LexIDStr($3)));
  254.         }
  255.  
  256. RenameRelnStmt:
  257.       XRENAME RELATION ident AS ident
  258.         {
  259.             DO_START;
  260.             renamerel(LexIDStr($3), LexIDStr($5));
  261.             DO_END;
  262.         }
  263.     ;
  264.  
  265. RenameAttrStmt:
  266.       XRENAME ATTR ident AS ident XIN ident
  267.         { DO_START;
  268.           renameatt(LexIDStr($7), LexIDStr($3), LexIDStr($5));
  269.           DO_END;
  270.         }
  271.     ;
  272.  
  273. DisplayStmt:
  274.       DisplayMacro
  275.     | DisplayReln
  276.     ;
  277.  
  278. DisplayMacro:
  279.       DISPLAY MACRO 
  280.         { 
  281.           DO_START;
  282.           printmacros(); 
  283.           DO_END;
  284.         }
  285.     ;
  286.  
  287. DisplayReln:
  288.       DISPLAY RELATION
  289.         {
  290.           DO_START;
  291.           /* pg_relation is now called pg_class -cim 2/26/90 */
  292.           boot_openrel("pg_class");
  293.           printrel();
  294.           closerel("pg_class");
  295.           DO_END;
  296.         }
  297.     | SHOW
  298.         {
  299.           DO_START;
  300.           printrel();
  301.           DO_END;
  302.         }
  303.     ;
  304.  
  305. MacroDefStmt:
  306.       XDEFINE MACRO ident EQUALS ident
  307.         { /* for now, simple subst only */
  308.           DO_START;
  309.           DefineMacro($3,$5);
  310.           DO_END;
  311.         }
  312.     ;
  313.  
  314. optbootstrap:
  315.         BOOTSTRAP    { $$ = 1; }
  316.     |          { $$ = 0; }
  317.     ;
  318.  
  319. typelist:
  320.       typething
  321.     | typelist COMMA typething
  322.     ;
  323.  
  324. typething:
  325.       ident EQUALS ident
  326.         { 
  327.            char name[16],type[16];
  328.            if(++numattr > MAXATTR)
  329.             elog(FATAL,"Too many attributes\n");
  330.            DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
  331.            if (DebugMode)
  332.                printf("\n");
  333.         }
  334.     ;
  335.  
  336. optoideq:
  337.         OBJ_ID EQUALS ident { $$ = atol(LexIDStr($3));         }
  338.     |            { extern OID newoid(); $$ = newoid();    }
  339.     ;
  340.  
  341. tuplelist:
  342.        tuple
  343.     |  tuplelist tuple
  344.     |  tuplelist COMMA tuple
  345.     ;
  346.  
  347. tuple:
  348.       ident    { InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
  349.     | const    { InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
  350.     | NULLVAL
  351.         { InsertOneNull(num_tuples_read++); }
  352.     ;
  353.   
  354. ident :
  355.       ID    { $$=yylval; }
  356.     | MACRO    { $$=yylval; }
  357.     ;
  358.  
  359. const :
  360.       FLOAT    { $$=yylval; }
  361.     | INT    { $$=yylval; }
  362.     ;
  363. %%
  364.  
  365.  
  366.