1: 
   2: /*
   3: **  GRAMMAR.Y
   4: **
   5: **	This file contains a grammar for ingres parsing.  It is setup
   6: **	for the (7-31-78) version of yacc.
   7: **
   8: **	Use:
   9: **		to use for non-distributed ingres:
  10: **			grep -v "DDD" > grammar.y
  11: **
  12: **	Trace Flags:
  13: **		Grammar.y ~~ 38, 39
  14: */
  15: 
  16: %{
  17: /* SCANNER/PARSER GLOBALS & TABLES */
  18: # include   <ingres.h>
  19: # include   <aux.h>
  20: # include   <tree.h>
  21: # include   <symbol.h>
  22: # include   <pv.h>
  23: # include   "parser.h"
  24: # include   <sccs.h>
  25: # include   <errors.h>
  26: 
  27: SCCSID(@(#)grammar.y	8.4	3/2/85)
  28: 
  29: # ifdef     xPTR1
  30: # define    YYDEBUG
  31: # endif
  32: 
  33: int             i;
  34: struct atstash          *aptr;
  35: char                permbuf[3];
  36: /* space for two names, their null bytes and the seperator */
  37: char                modbuf[(2 * (MAXNAME + 1)) + 1];
  38: static char         hqmbuf[2];
  39: 
  40: extern DESC         Reldesc;
  41: extern int          Opflag;
  42: extern QTREE            *Lastree;
  43: extern QTREE            *Tidnode;
  44: extern int          Rsdmno;
  45: extern int          Resrng;
  46: extern int          Qrymod;
  47: extern int          Permcomd;
  48: extern char         *Trname;
  49: extern int          Qlflag;
  50: extern struct atstash       Faketid;
  51: extern char         *Tuple;
  52: extern TID          tid;
  53: 
  54: # ifdef DISTRIB
  55: extern struct atstash       Fakesid;
  56: # endif
  57: 
  58: extern char         *Indexname;
  59: 
  60: extern QTREE            *tree();
  61: extern QTREE            *tlprepend();
  62: extern QTREE            *addresdom();
  63: extern QTREE            *xdot();
  64: extern QTREE            *norml();
  65: extern struct atstash       *attlookup();
  66: extern int          rngent();
  67: extern int          rnglook();
  68: extern PARRNG           Parrng[];
  69: extern STRKEEPER        *substring(),*endvals();
  70: %}
  71: 
  72: /* NEW BEGIN-END THINGS */
  73: %start      program
  74: 
  75: /* UNION YYSTYPE DEFINED */
  76: %union
  77: {
  78:     int             type_type;  /* OPERATOR TYPES ETC. */
  79:     QTREE               *tree_type;
  80:     int             rng_type;
  81:     char                char_type;
  82:     int             int_type;
  83:     short               *I2_type;
  84:     long                *I4_type;
  85:     float               *F4_type;
  86:     double              *F8_type;
  87:     char                *string_type;
  88:     STRKEEPER           *substr_type;
  89: }
  90: 
  91: /* COMMANDS */
  92: %token      APPEND  COPY    CREATE  DELETE  DESTROY HELP    INDEX   MODIFY
  93: %token      PRINT   RANGE   REPLACE RETRIEVE    SAVE
  94: %token      DEFINE  PERMIT  VIEW    INTEGRITY
  95: %token      DELIM   USE UNUSE
  96: /*DDD*/%token   DISTRIBUTE
  97: 
  98: /* 'NOISE' WORDS */
  99: %token      ALL BY  FROM    IN  INTO    UNIQUE  AT
 100: %token      IS  OF  ON  ONTO    TO  UNTIL   WHERE
 101: /*DDD*/%token   DISTRD
 102: 
 103: /* CONSTANTS */
 104: %token      NAME    SCONST  I2CONST I4CONST F4CONST F8CONST
 105: 
 106: /* PUNCTUATION */
 107: %token      COMMA   LPAREN  PERIOD  RPAREN  COLON   BGNCMNT ENDCMNT
 108: %token      LBRAC   RBRAC   DOLLAR  PCT
 109: 
 110: /* UNARY ARITHMETIC OPERATORS */
 111: %token      UAOP
 112: 
 113: /* BINARY ARITHMETIC OPERATORS */
 114: %token      BAOP    BAOPH
 115: 
 116: /* BOUNDS OPERATORS */
 117: %token      BDOP
 118: 
 119: /* EQUALITY OPERATORS */
 120: %token      EOP
 121: 
 122: /* LOGICAL OPERATORS */
 123: %token      LBOP    LUOP
 124: 
 125: /* FUNCTIONAL OPERATORS */
 126: %token      FOP FBOP
 127: 
 128: /* AGGREGATE OPERATORS */
 129: %token      AGOP
 130: 
 131: /* TYPES FOR INGRES TOKENS */
 132: %type   <type_type> IS
 133: %type   <string_type>   NAME    SCONST
 134: %type   <I2_type>   I2CONST
 135: %type   <I4_type>   I4CONST
 136: %type   <F4_type>   F4CONST
 137: %type   <F8_type>   F8CONST
 138: %type   <type_type> UAOP
 139: %type   <type_type> BAOP    BAOPH
 140: %type   <type_type> BDOP
 141: %type   <type_type> EOP
 142: %type   <type_type> LBOP    LUOP
 143: %type   <type_type> FOP FBOP
 144: %type   <type_type> AGOP
 145: %type   <char_type> LPAREN  RPAREN  LBRAC   RBRAC  PCT
 146: 
 147: /* TYPES FOR INGRES NON-TERMINALS */
 148: %type   <tree_type> permtarg    permtlist   permtlelm
 149: /*DDD*/%type    <tree_type> distribute  distcrits   dcriterion
 150: %type   <tree_type> tlclause    tlist   tlelm
 151: %type   <tree_type> qualclause  qual    clause  afcn    aggrfcn
 152: %type   <type_type> relop
 153: %type   <tree_type> domseq  targdom attrib
 154: %type   <rng_type>  var
 155: %type   <tree_type> attribfcn
 156: %type   <type_type> uop
 157: %type   <string_type>   alias
 158: %type   <substr_type>   subelm  stringpart  grpelm  nameprt
 159: %type   <char_type> leftclose   rightclose
 160: 
 161: /* DEFINE ASCENDING PRECEDENCE FOR OPERATORS */
 162: %left       LBOP
 163: %left       LUOP
 164: %left       UAOP
 165: %left       BAOP
 166: %left       BAOPH
 167: %nonassoc   unaryop
 168: 
 169: %%
 170: program:    program stmnt =
 171:         {
 172: #			ifdef   xPTR1
 173:             tTfp(38, 0, "*** [program stmnt] parsed.\n");
 174: #			endif
 175: 
 176:             if (endquelst(Opflag) < 0)
 177:                 return (-1);
 178:         }
 179:     |   stmnt =
 180:         {
 181: #			ifdef   xPTR1
 182:             tTfp(38, 1, "*** [stmnt] parsed.\n");
 183: #			endif
 184: 
 185:             if (endquelst(Opflag) < 0)
 186:                 return (-1);
 187:         }
 188:     |
 189:         {
 190: #			ifdef   xPTR1
 191:             tTfp(38, 2, "*** [(NULL)] parsed.\n");
 192: #			endif
 193:         }
 194: ;
 195: stmnt:      append
 196:     |   copy
 197:     |   create
 198:     |   delete
 199:     |   destroy
 200: /*DDD*/ |   distribute
 201:     |   help
 202:     |   index
 203:     |   integrity
 204:     |   modify
 205:     |   permit
 206:     |   print
 207:     |   range
 208:     |   replace
 209:     |   retrieve
 210:     |   save
 211:     |   view
 212:     |   use
 213:     |   unuse
 214:     |   delim
 215:     |   error
 216:         {
 217: #			ifdef   xPTR1
 218:             tTfp(38, 0, "*** [error] parsed.\n");
 219: #			endif
 220:         }
 221: 
 222: ;
 223: range:      rngstmnt OF NAME IS NAME =
 224:         {
 225:             if ((i = openr(&Reldesc, OR_RELTID, $5)) < 0)
 226:                 syserr("relname: error in openr '%d'", i);
 227:             if (i > 0)
 228:             {
 229:                 /* invalid relation name */
 230:                 par_error(RNGEXIST, WARN, $5, 0);
 231:                 YYERROR;
 232:             }
 233:             else
 234:                 rngent(R_EXTERNAL, $3, &Reldesc);
 235:         }
 236: ;
 237: rngstmnt:   RANGE =
 238:         {
 239:             Opflag = mdRANGE;
 240:         }
 241: ;
 242: append:     apstmnt apto relation tlclause qualclause =
 243:         {
 244:             /* make root node */
 245:             Lastree = tree($4, $5, ROOT, sizeof(struct rootnode), 1);
 246:         }
 247: ;
 248: apstmnt:    APPEND =
 249:         {
 250:             Opflag = mdAPP;
 251:         }
 252: ;
 253: apto:       INTO
 254:     |   ONTO
 255:     |   TO
 256:     |   ON
 257:     |   ;
 258: ;
 259: delete:     delstmnt delwd relation qualclause =
 260:         {
 261:             /* make root node for delete, with a TIDNODE at leftmost */
 262:             Lastree = tree(tree(NULL, Tidnode, RESDOM, sizeof(struct resdomnode), NULL), $4, ROOT, sizeof(struct rootnode), 1);
 263:         }
 264: ;
 265: delstmnt:   DELETE =
 266:         {
 267:             Opflag = mdDEL;
 268:         }
 269: ;
 270: delwd:      IN
 271:     |   ON
 272:     |   FROM
 273:     |   ;
 274: ;
 275: replace:    repstmnt repkwd relation tlclause qualclause =
 276:         {
 277:             /* make root node for replace */
 278:             Lastree = tree($4, $5, ROOT, sizeof(struct rootnode), 1);
 279:         }
 280: ;
 281: repstmnt:   REPLACE =
 282:         {
 283:             Opflag = mdREPL;
 284:         }
 285: ;
 286: repkwd:     INTO
 287:     |   IN
 288:     |   ON
 289:     |   ;
 290: ;
 291: retrieve:   retstmnt retclause tlclause qualclause =
 292:         {
 293:             /* make root node for retrieve */
 294:             Lastree = tree($3, $4, ROOT, sizeof(struct rootnode), 1);
 295:         }
 296: ;
 297: retstmnt:   RETRIEVE =
 298:         {
 299:             Opflag = mdRETR;
 300:         }
 301: ;
 302: retclause:  retkwd relation =
 303:         {
 304:             /* set up pipe block and save relname for create */
 305: #			ifdef   xPTR2
 306:             tTfp(38, 4, "retclause: Rsdmno %d", Rsdmno);
 307: #			endif
 308:             Rsdmno = 0;
 309:             setp(PV_STR, "0");  /* relstat = nil */
 310:             setp(PV_STR, trim_relname(Parrng[Resrng].vardesc.reldum.relid));
 311:         }
 312:     |   =
 313:         {
 314:             /* no result relation, output to terminal */
 315:             Rsdmno = 0;
 316:             Resrng = -1;
 317:         }
 318:     |   UNIQUE =
 319:         {
 320:             Opflag = mdRET_UNI;
 321:             Rsdmno = 0;
 322:             Resrng = -1;
 323:         }
 324: ;
 325: retkwd:     INTO
 326:     |   TO
 327:     |   ;
 328: ;
 329: 
 330: delim:      DEFINE DELIM NAME LPAREN NAME COMMA SCONST RPAREN =
 331:         {
 332:             Opflag = mdSTOP;
 333:             if ((i = openr(&Reldesc, OR_WRITE, "rdelim")) < 0)
 334:                 syserr("relname: error in openr '%d'", i);
 335:             if (i > 0)
 336:             {
 337:                 /* invalid relation name */
 338:                 par_error(RNGEXIST, WARN, "rdelim", 0);
 339:                 YYERROR;
 340:             }
 341:             else
 342:             {
 343:                 if (( i = make_tuples(&Reldesc, $3, $5, $7)) < 0)
 344:                 {
 345:                     closer(&Reldesc);
 346:                     par_error(BADBNF, WARN, "rdelim", 0);
 347:                 }
 348:             }
 349:             closer(&Reldesc);
 350:         }
 351: ;
 352: use:        USE NAME =
 353:         {
 354:             Opflag = mdSTOP;
 355:             if ((i = openr(&Reldesc, OR_WRITE, "rdelim")) < 0)
 356:                 syserr("relname: error in openr '%d'", i);
 357:             if (i > 0)
 358:             {
 359:                 /* invalid relation name */
 360:                 par_error(RNGEXIST, WARN, "rdelim", 0);
 361:                 YYERROR;
 362:             }
 363:             else
 364:             {
 365:                 if ((i = make_list(&Reldesc, $2)) < 0)
 366:                 {
 367:                     closer(&Reldesc);
 368:                     par_error(DELEXIST, WARN, 0);
 369:                 }
 370:             }
 371:             closer(&Reldesc);
 372:         }
 373: ;
 374: unuse:      UNUSE NAME =
 375:         {
 376:             Opflag = mdSTOP;
 377:             if ( i = shrink_list($2) < 0)
 378:             {
 379:                 par_error(NOGRP,WARN,0);
 380:             }
 381:         }
 382: ;
 383: 
 384: view:       viewclause tlclause qualclause =
 385:         {
 386:             Lastree = tree($2, $3, ROOT, sizeof(struct rootnode), 1);
 387:         }
 388: ;
 389: viewclause: viewstmnt relation =
 390:         {
 391:             Rsdmno = 0;
 392:             setp(PV_STR, "0040");   /* relstat = S_VIEW */
 393:             setp(PV_STR, trim_relname(Parrng[Resrng].vardesc.reldum.relid));
 394:         }
 395: ;
 396: viewstmnt:  DEFINE VIEW =
 397:         {
 398:             Opflag = mdVIEW;
 399:             if (!Qrymod)
 400:             {
 401:                 /* no qrymod in database */
 402:                 par_error(NOQRYMOD, WARN, 0);
 403:             }
 404:         }
 405: ;
 406: permit:     permstmnt permlist permrel permtarg permwho permplace permtd qualclause =
 407:         {
 408:             Lastree = tree($4, $8, ROOT, sizeof(struct rootnode), 1);
 409:         }
 410: ;
 411: permstmnt:  DEFINE PERMIT =
 412:         {
 413:             Opflag = mdPROT;
 414:             if (!Qrymod)
 415:             {
 416:                 /* no qrymod in database */
 417:                 par_error(NOQRYMOD, WARN, 0);
 418:             }
 419:         }
 420: ;
 421: permlist:   permxlist
 422:     |   permlist COMMA permxlist
 423: ;
 424: permxlist:  ALL =
 425:         {
 426:             permcom(-1);    /* means 'all' commands */
 427:         }
 428:     |   RETRIEVE =
 429:         {
 430:             permcom(mdRETR);
 431:         }
 432:     |   DELETE =
 433:         {
 434:             permcom(mdDEL);
 435:         }
 436:     |   APPEND =
 437:         {
 438:             permcom(mdAPP);
 439:         }
 440:     |   REPLACE =
 441:         {
 442:             permcom(mdREPL);
 443:         }
 444: ;
 445: permrel:    permword relation =
 446:         {
 447:             /* put command vector into list now since this always happens */
 448:             setp(PV_INT, Permcomd);
 449:             Permcomd = 0;       /* reset command map */
 450:             setp(PV_STR, trim_relname(Parrng[Resrng].vardesc.reldum.relid));
 451:             bmove(Parrng[Resrng].vardesc.reldum.relowner, permbuf, 2);
 452:             permbuf[2] = 0;
 453:             setp(PV_STR, permbuf);
 454:         }
 455: ;
 456: permword:   ON
 457:     |   OF
 458:     |   TO
 459: ;
 460: permtarg:   LPAREN permtlist RPAREN =
 461:         {
 462:             $$ = $2;
 463:         }
 464:     |   =
 465:         {
 466:             $$ = NULL;
 467:         }
 468: ;
 469: permtlist:  permtlelm
 470:     |   permtlist COMMA permtlelm =
 471:         {
 472:             /*
 473: 			** attach bulk of permit tl to leftmost node of new elem
 474: 			*/
 475:             if (!Err_current)
 476:                 $$ = tlprepend($1, $3);
 477:         }
 478: ;
 479: permtlelm:  NAME =
 480:         {
 481:             /* Resrng is set by the "relation" production */
 482:             if (!Err_current)
 483:             {
 484:                 Trname = $1;
 485:                 aptr = attlookup(Resrng, Trname);
 486:                 $$ = tree(NULL, NULL, VAR, sizeof(struct varnode), Resrng, aptr);
 487:                 $$ = addresdom(NULL, $$);
 488:             }
 489:         }
 490: ;
 491: permwho:    TO NAME =
 492:         {
 493:             setp(PV_STR, $2);
 494:         }
 495:     |   TO ALL =
 496:         {
 497:             setp(PV_STR, "all");
 498:         }
 499: ;
 500: permplace:  AT NAME =
 501:         {
 502:             setp(PV_STR, $2);
 503:         }
 504:     |   AT ALL =
 505:         {
 506:             setp(PV_STR, "all");
 507:         }
 508:     |   =
 509:         {
 510:             setp(PV_STR, "all");        /* default is all */
 511:         }
 512: ;
 513: permtd:     permtime permday
 514:     |   permdeftime permday
 515:     |   permtime permdefday
 516:     |   permdeftime permdefday
 517: ;
 518: permdeftime:    =
 519:         {
 520:             setp(PV_INT, 0);
 521:             setp(PV_INT, 1440);
 522:         }
 523: ;
 524: permdefday: =
 525:         {
 526:             setp(PV_STR, "sun");
 527:             setp(PV_STR, "sat");
 528:         }
 529: ;
 530: permtime:   FROM I2CONST COLON I2CONST TO I2CONST COLON I2CONST =
 531:         {
 532:             setp(PV_INT, timeofday($2, $4));
 533:             setp(PV_INT, timeofday($6, $8));
 534:         }
 535: ;
 536: permday:    ON NAME TO NAME =
 537:         {
 538:             setp(PV_STR, $2);
 539:             setp(PV_STR, $4);
 540:         }
 541: ;
 542: integrity:  integstmnt integnoise relation integis qual =
 543:         {
 544:             Lastree = tree(NULL, norml($5), ROOT, sizeof(struct rootnode), 1);
 545:             Qlflag--;   /* turn off here */
 546:         }
 547: ;
 548: integstmnt: DEFINE INTEGRITY =
 549:         {
 550:             Opflag = mdINTEG;
 551:             Qlflag++;   /* OK to turn on here because integrity doesn't have a targ list */
 552:             if (!Qrymod)
 553:             {
 554:                 /* no qrymod in database */
 555:                 par_error(NOQRYMOD, WARN, 0);
 556:             }
 557:         }
 558: ;
 559: integnoise: ON
 560:     |   ONTO
 561:     |   IN
 562:     |   OF
 563:     |   /* null */
 564: ;
 565: integis:    IS
 566:     |   /* null*/
 567: ;
 568: /*DDD*/distribute:  diststmnt relation AT distcrits =
 569: /*DDD*/     {
 570: /*DDD*/         if (!Err_current)
 571: /*DDD*/         {
 572: /*DDD*/             $$ = tree(NULL, NULL, QLEND, 0);
 573: /*DDD*/             Lastree = tree($4, $$, ROOT, sizeof(struct rootnode), 1);
 574: /*DDD*/         }
 575: /*DDD*/     }
 576: /*DDD*/;
 577: /*DDD*/diststmnt:   DISTRIBUTE =
 578: /*DDD*/             Opflag = mdDISTRIB;
 579: /*DDD*/;
 580: /*DDD*/distcrits:   dcriterion =
 581: /*DDD*/     {
 582: /*DDD*/         $$ = $1;
 583: /*DDD*/     }
 584: /*DDD*/ |   distcrits dcriterion =
 585: /*DDD*/     {
 586: /*DDD*/         $$ = tlprepend($1, $2);
 587: /*DDD*/     }
 588: /*DDD*/;
 589: /*DDD*/dcriterion:  NAME where qual =
 590: /*DDD*/     {
 591: /*DDD*/         Qlflag--;
 592: /*DDD*/         syserr("Warning this node may be the wrong size\n");
 593: /*DDD*/         if (!Err_current)
 594: /*DDD*/             $$ = tree(NULL, norml($3), SITE, 2, $1);
 595: /*DDD*/     }
 596: /*DDD*/;
 597: relation:   NAME =
 598:         {
 599: #			ifdef   xPTR2
 600:             tTfp(38, 3, "res rel name/var: '%s'\n", $1);
 601: #			endif
 602:             switch (Opflag)
 603:             {
 604:               case mdRETR:
 605:               case mdVIEW:
 606:                 /* result better not be a rel name */
 607:                 if ((i = openr(&Reldesc, OR_RELTID, $1)) < 0)
 608:                     syserr("relation: err openr '%d'", i);
 609:                 if (i == 0)
 610:                 {
 611:                     /* reln exists */
 612:                     if (bequal(Reldesc.reldum.relowner, Usercode, UCODE_SZ))
 613:                     {
 614:                         /* same owner, can't duplicate name */
 615:                         par_error(RESEXIST, WARN, $1, 0);
 616:                         YYERROR;
 617:                     }
 618:                     else if (!Err_current)
 619:                     {
 620:                         /* owned by dba -- purge range table */
 621:                         rngdel($1);
 622:                     }
 623:                 }
 624:                 if (!Err_current)
 625:                 {
 626:                     bmove(Usercode, Reldesc.reldum.relowner, UCODE_SZ);
 627:                     pmove($1, Reldesc.reldum.relid, MAXNAME, ' ');
 628:                     Resrng = rngent(R_INTERNAL, "", &Reldesc);
 629:                 }
 630:                 break;
 631: 
 632:               case mdAPP:
 633:                 /* result is a rel name */
 634:                 if (!Err_current)
 635:                 {
 636:                     Resrng = rnglook($1, LOOKREL);
 637:                     if (Resrng < 0)
 638:                     {
 639:                         if ((i = openr(&Reldesc, OR_RELTID, $1)) < 0)
 640:                             syserr("relation: err openr '%d'", i);
 641:                         if (i)
 642:                         {
 643:                             /* invalid relation name */
 644:                             par_error(RESAPPEX, WARN, $1, 0);
 645:                             YYERROR;
 646:                         }
 647:                         Resrng = rngent(R_INTERNAL, "", &Reldesc);
 648:                     }
 649:                     else
 650:                         ctlmod_decl(Resrng);
 651:                     checkupd(Resrng);
 652:                 }
 653:                 break;
 654: 
 655:               case mdPROT:
 656:               case mdINTEG:
 657: #			  ifdef DISTRIB
 658:               case mdDISTRIB:
 659: #			  endif
 660:                 /* the result is a tuple variable */
 661:                 Resrng = rnglook($1, LOOKVAR);
 662:                 if (Resrng < 0)
 663:                 {
 664:                     /* variable not declared */
 665:                     par_error(NOVBLE, WARN, $1, 0);
 666:                     YYERROR;
 667:                 }
 668:                 else
 669:                     ctlmod_decl(Resrng);
 670:                 break;
 671: 
 672:               case mdREPL:
 673:               case mdDEL:
 674:                 /* the result is a tuple variable */
 675:                 Resrng = rnglook($1, LOOKVAR);
 676:                 if (Resrng < 0)
 677:                     /* variable not declared */
 678:                 {
 679:                     par_error(NOVBLE, WARN, $1, 0);
 680:                     YYERROR;
 681:                 }
 682:                 else
 683:                     ctlmod_decl(Resrng);
 684: 
 685:                 checkupd(Resrng);
 686:                 Tidnode = tree(NULL, NULL, VAR, sizeof(struct varnode), Resrng, &Faketid);
 687:                 break;
 688:               default:
 689:                 ;
 690:             }
 691:         }
 692: ;
 693: tlclause:   LPAREN tlist RPAREN =
 694:         {
 695:             $$ = $2;
 696: 
 697:             /*
 698: 			** replace must have tid node as left branch
 699: 			**	(so does delete but it doesn't have a targ list)
 700: 			*/
 701:             if (Opflag == mdREPL && !Err_current)
 702:             {
 703:                 $$ = tlprepend(tree(NULL, Tidnode, RESDOM, sizeof(struct resdomnode), 0), $$);
 704:             }
 705:         }
 706: ;
 707: tlist:      tlelm
 708:     |   tlist COMMA tlelm =
 709:         {
 710:             /*
 711: 			** attach bulk of targ list to leftmost node
 712: 			** of new element
 713: 			*/
 714:             if (!Err_current)
 715:                 $$ = tlprepend($1, $3);
 716:         }
 717: ;
 718: tlelm:      NAME is afcn =
 719:         {
 720:             Trname = $1;
 721:             /* make a new resdom entry for targ list */
 722:             if (!Err_current)
 723:                 $$ = addresdom(NULL, $3);
 724:         }
 725:     |   attrib =
 726:         {
 727:         /* makes a new resdom entry for targ list */
 728:             if (!Err_current)
 729:                 $$ = addresdom(NULL, $1);
 730:         }
 731:     |   var PERIOD ALL =
 732:         {
 733:             if (Opflag == mdREPL)
 734:             {
 735:                 /* ALL not defined for REPLACE */
 736:                 par_error(REPALL, WARN,
 737:                     trim_relname(Qt.qt_rangev[$1].rngvdesc->relvname), 0);
 738:                 YYERROR;
 739:             }
 740:             /* makes set of new resdom entries for targ list */
 741:             else if (!Err_current)
 742:                 $$ = xdot($1);
 743:         }
 744: ;
 745: is:     IS
 746:     |   BY
 747: ;
 748: qualclause: where qual =
 749:         {
 750:             $$ = norml($2);
 751:             Qlflag--;
 752:             if (Opflag == mdREPL)
 753:                 qualindex();
 754:         }
 755:     |   =
 756:         {
 757:             /* null qualification */
 758:             if (Opflag == mdREPL)
 759:                 qualindex();
 760:             $$ = norml(NULL);
 761:         }
 762: ;
 763: where:      WHERE =
 764:         {
 765:             Qlflag++;
 766:         }
 767: ;
 768: qual:       LPAREN qual RPAREN =
 769:         {
 770:             $$ = $2;
 771:         }
 772:     |   LUOP qual =
 773:         {
 774:             $$ = tree(NULL, $2, UOP, 2, $1);
 775:         }
 776:     |   qual LBOP qual =
 777:         {
 778:             $$ = tree($1, $3, $2, sizeof (struct rootnode) -2, 0);
 779:         }
 780:     |   clause
 781: ;
 782: clause:     afcn relop afcn =
 783:         {
 784:             $$ = tree($1, $3, BOP, 2, $2);
 785:         }
 786: ;
 787: relop:      EOP
 788:     |   IS
 789:     |   BDOP
 790: ;
 791: afcn:       aggrfcn
 792:     |   attribfcn
 793:     |   afcn BAOPH afcn =
 794:         {
 795:             $$ = tree($1, $3, BOP, 2, $2);
 796:         }
 797:     |   afcn BAOP afcn =
 798:         {
 799:             $$ = tree($1, $3, BOP, 2, $2);
 800:         }
 801:     |   afcn UAOP afcn =
 802:         {
 803:             $$ = tree($1, $3, BOP, 2, $2);
 804:         }
 805:     |   LPAREN afcn RPAREN =
 806:         {
 807:             $$ = $2;
 808:         }
 809:     |   uop afcn    %prec unaryop   =
 810:         {
 811:             $$ = tree(NULL, $2, UOP, 2, $1);
 812:         }
 813:     |   FOP LPAREN afcn RPAREN =
 814:         {
 815:             $$ = tree($3, NULL, UOP, 2, $1);
 816:         }
 817:     |   FBOP LPAREN afcn COMMA afcn RPAREN =
 818:         {
 819:             $$ = tree($3, $5, BOP, 2, $1);
 820:         }
 821: ;
 822: aggrfcn:    AGOP LPAREN afcn BY domseq qualclause RPAREN =
 823:         {
 824: #			ifdef   xPTR2
 825:             tTfp(39, 0, "agg func\n");
 826: #			endif
 827:             windup($5);
 828:             $$ = tree(tree($5, tree(NULL, $3, AOP, 6, $1), BYHEAD, sizeof(struct resdomnode), 0), $6, AGHEAD, sizeof(struct rootnode), 0);
 829:             tlprepend(tree(NULL, NULL, TREE, 0), $$);
 830:         }
 831:     |   AGOP LPAREN afcn qualclause RPAREN =
 832:         {
 833:             $$ = tree(tree(NULL, $3, AOP, 6, $1), $4,  AGHEAD, sizeof(struct rootnode), 0);
 834:         }
 835: ;
 836: domseq:     targdom
 837:     |   domseq COMMA targdom =
 838:         {
 839:             $$ = tlprepend($1, $3);
 840:         }
 841: ;
 842: targdom:    afcn =
 843:         {
 844:             $$ = tree(NULL, $1, RESDOM, sizeof(struct resdomnode), Rsdmno);
 845:         }
 846: ;
 847: nameprt:    NAME =
 848:         {
 849:             $$ = substring($1,1);
 850:         }
 851:     |   SCONST =
 852:         {
 853:             $$ = substring($1,0);
 854:         }
 855: ;
 856: subelm:     DOLLAR =
 857:         {
 858:             $$ = substring(NULL,0);
 859:         }
 860:     |   nameprt DOLLAR =
 861:         {
 862:             $1->flag[0] |= 2;
 863:             $$ = $1;
 864:         }
 865:     |   nameprt =
 866:         {
 867:             $$ = $1;
 868:         }
 869:     |   I2CONST subelm =
 870:         {
 871:             setnumber($2,$1);
 872:             $$ = $2;
 873:         }
 874: ;
 875: grpelm:     subelm COMMA subelm =
 876:         {
 877:             groupstrings($1,$3);
 878:             $$ = $1;
 879:         }
 880: ;
 881: leftclose:  PCT =
 882:         {
 883:             $$ = $1;
 884:         }
 885:     |   LPAREN =
 886:         {
 887:             $$ = $1;
 888:         }
 889: ;
 890: rightclose: PCT =
 891:         {
 892:             $$ = $1;
 893:         }
 894:     |   RPAREN =
 895:         {
 896:             $$ = $1;
 897:         }
 898: ;
 899: stringpart: leftclose subelm rightclose =
 900:         {
 901:             $$ = endvals($2,$1,$3);
 902:         }
 903:     |   leftclose grpelm rightclose =
 904:         {
 905:             $$ = endvals($2,$1,$3);
 906:         }
 907: ;
 908: attrib:     var PERIOD NAME =
 909:         {
 910: #			ifdef   xPTR2
 911:             tTfp(39, 1, "attrib %12s.%12s found\n",
 912:             Qt.qt_rangev[$1].rngvdesc->relvname, $3);
 913: #			endif
 914: 
 915:             /* remember attribute name */
 916:             Trname = $3;
 917: 
 918:             /* look up attribute */
 919:             aptr = attlookup($1, Trname);
 920:             $$ = tree(NULL, NULL, VAR, sizeof(struct varnode), $1, aptr);
 921:         }
 922:     |       attrib stringpart =
 923:         {
 924:             $1->sym.value.sym_var.varstr = $2;
 925:             $$ = $1;
 926:         }
 927: ;
 928: var:        NAME =
 929:         {
 930:             $$ = rnglook($1, LOOKVAR);
 931:             if ($$ < 0)
 932:             {
 933:                 /* variable not declared */
 934:                 par_error(NOVBLE, WARN, $1, 0);
 935:                 YYERROR;
 936:             }
 937:             else
 938:                 ctlmod_decl($$);
 939:         }
 940: ;
 941: attribfcn:  I2CONST =
 942:         {
 943:             $$ = tree(NULL, NULL, INT, 2, $1);
 944:         }
 945:     |   I4CONST =
 946:         {
 947:             $$ = tree(NULL, NULL, INT, 4, $1);
 948:         }
 949:     |   F4CONST =
 950:         {
 951:             $$ = tree(NULL, NULL, FLOAT, 4, $1);
 952:         }
 953:     |   F8CONST =
 954:         {
 955:             $$ = tree(NULL, NULL, FLOAT, 8, $1);
 956:         }
 957:     |   SCONST =
 958:         {
 959:             patmat($1);
 960:             $$ = tree(NULL, NULL, CHAR, length($1), $1);
 961:         }
 962:     |   NAME =
 963:         {
 964:             $$ = tree(NULL, NULL, COP, 2, $1);
 965:         }
 966:     |   attrib
 967: ;
 968: uop:        UAOP    %prec unaryop   =
 969:         {
 970:             if ($1 == opADD)
 971:                 $$ = opPLUS;
 972:             else
 973:                 if ($1 == opSUB)
 974:                     $$ = opMINUS;
 975:         }
 976: ;
 977: copy:       copstmnt alias LPAREN coparam RPAREN keywd SCONST =
 978:         {
 979: #			ifdef   xPTR2
 980:             tTfp(39, 3, "copy %12s,%12s\n", $2, $7);
 981: #			endif
 982: 
 983:             setp(PV_STR, $7);
 984:         }
 985: ;
 986: copstmnt:   COPY =
 987:         {
 988:             Opflag = mdCOPY;
 989:         }
 990: ;
 991: coparam:    cospecs
 992:     |   ;
 993: ;
 994: cospecs:    alias is coent
 995:     |   cospecs COMMA alias is coent
 996: ;
 997: coent:      alias
 998:     |   SCONST =
 999:         {
1000:             setp(PV_STR, $1);
1001:         }
1002: ;
1003: alias:      NAME =
1004:         {
1005:             if (!Err_current)
1006:             {
1007:                 setp(PV_STR, $1);
1008:                 if (Opflag == mdDESTROY || Opflag == mdCREATE
1009: #					ifdef DISTRIB
1010:                     || Opflag == mdDCREATE
1011: #					endif
1012:                                 )
1013:                     rngdel($1);
1014:             }
1015:         }
1016: ;
1017: specs:      alias is alias
1018:     |   specs COMMA alias is alias
1019: ;
1020: keywd:      INTO =
1021:         {
1022:             setp(PV_STR, "\0");
1023:             setp(PV_STR, "i");
1024:         }
1025:     |   FROM =
1026:         {
1027:             setp(PV_STR, "\0");
1028:             setp(PV_STR, "f");
1029:         }
1030: ;
1031: create:     crestmnt alias LPAREN specs RPAREN
1032: ;
1033: crestmnt:   CREATE =
1034:         {
1035:             Opflag = mdCREATE;
1036: 
1037:             /* set up parameters for regular create */
1038:             setp(PV_STR, "0");      /* relstat = nil */
1039:         }
1040: /*DDD*/ |   CREATE DISTRD =
1041: /*DDD*/     {
1042: /*DDD*/         Opflag = mdDCREATE;
1043: /*DDD*/
1044: /*DDD*/         /* setup parameters for distributed create */
1045: /*DDD*/         setp(PV_STR, "U");
1046: /*DDD*/         setp(PV_STR, "");
1047: /*DDD*/         setp(PV_STR, "01000");  /* relstat = S_DISTRIBUTED */
1048: /*DDD*/     }
1049: ;
1050: destroy:    destmnt keys
1051:     |   destqm destlist
1052:     |   destmnt DELIM NAME =
1053:         {
1054:             Opflag = mdSTOP;
1055:             if ((i = openr(&Reldesc, OR_WRITE, "rdelim")) < 0)
1056:                 syserr("relname: error in openr '%d'", i);
1057:             if (i > 0)
1058:             {
1059:                 /* invalid relation name */
1060:                 par_error(RNGEXIST, WARN, "rdelim", 0);
1061:                 YYERROR;
1062:             }
1063:             else
1064:             {
1065:                 if ( i = destroy_delim(&Reldesc, $3) < 0)
1066:                 {
1067:                     closer(&Reldesc);
1068:                     par_error(DELEXIST, WARN, "rdelim",0);
1069:                 }
1070:             }
1071:             closer(&Reldesc);
1072:         }
1073: ;
1074: destmnt:    DESTROY =
1075:         {
1076:             Opflag = mdDESTROY;
1077:         }
1078: ;
1079: destqm:     destmnt INTEGRITY NAME =
1080:         {
1081:             Opflag = mdREMQM;
1082:             if (!Qrymod)
1083:                 /* no qrymod in database */
1084:                 par_error(NOQRYMOD, WARN, 0);
1085:             setp(PV_STR, "6");
1086:             setp(PV_STR, $3);
1087:         }
1088:     |   destmnt PERMIT NAME =
1089:         {
1090:             Opflag = mdREMQM;
1091:             if (!Qrymod)
1092:                 /* no qrymod in database */
1093:                 par_error(NOQRYMOD, WARN, 0);
1094:             setp(PV_STR, "5");
1095:             setp(PV_STR, $3);
1096:         }
1097: ;
1098: destlist:   I2CONST =
1099:         {
1100:             i = iocv(*($1));
1101:             setp(PV_STR, i);
1102:         }
1103:     |   destlist COMMA I2CONST =
1104:         {
1105:             i = iocv(*($3));
1106:             setp(PV_STR, i);
1107:         }
1108:     |   ALL
1109: ;
1110: help:       helstmnt hlist
1111:     |   helstmnt =
1112:         {
1113:             setp(PV_INT, RELIST);   /* all relns */
1114:         }
1115:     |   helqmstmnt hqmlist
1116:     |   heldelstmnt =
1117:         {
1118:             setp(PV_INT, ALLDELLIST);   /* all delims */
1119:         }
1120:     |   heldelstmnt dlist
1121: ;
1122: helstmnt:   HELP =
1123:         {
1124:             Opflag = mdHELP;
1125:         }
1126: ;
1127: heldelstmnt:    HELP DELIM =
1128:         {
1129:             Opflag = mdHELP;
1130:         }
1131: ;
1132: helqmstmnt: HELP VIEW =
1133:         {
1134:             Opflag = mdDISPLAY;
1135:             if (!Qrymod)
1136:                 /* no qrymod in database */
1137:                 par_error(NOQRYMOD, WARN, 0);
1138:             smove("4", hqmbuf);
1139:         }
1140:     |   HELP PERMIT =
1141:         {
1142:             Opflag = mdDISPLAY;
1143:             if (!Qrymod)
1144:                 /* no qrymod in database */
1145:                 par_error(NOQRYMOD, WARN, 0);
1146:             smove("5", hqmbuf);
1147:         }
1148:     |   HELP INTEGRITY =
1149:         {
1150:             Opflag = mdDISPLAY;
1151:             if (!Qrymod)
1152:                 /* no qrymod in database */
1153:                 par_error(NOQRYMOD, WARN, 0);
1154:             smove("6", hqmbuf);
1155:         }
1156: 
1157: ;
1158: hlist:      hparam
1159:     |   hlist COMMA hparam
1160:     |   ALL =
1161:         {
1162:             setp(PV_INT, ALLRELINFO);
1163:         }
1164: ;
1165: dlist:      dparam
1166:     |   dlist COMMA dparam
1167: ;
1168: dparam: NAME =
1169:         {
1170:             /* relation */
1171:             setp(PV_INT, DELLIST);
1172:             setp(PV_STR, $1);
1173:         }
1174: ;
1175: hparam:     NAME =
1176:         {
1177:             /* relation */
1178:             setp(PV_INT, RELINFO);
1179:             setp(PV_STR, $1);
1180:         }
1181:     |   SCONST =
1182:         {
1183:             /* manual page */
1184:             setp(PV_INT, MANSEC);
1185:             setp(PV_STR, $1);
1186:         }
1187: ;
1188: hqmlist:    NAME =
1189:         {
1190:             setp(PV_STR, hqmbuf);
1191:             setp(PV_STR, $1);
1192:         }
1193:     |   hqmlist COMMA NAME =
1194:         {
1195:             setp(PV_STR, hqmbuf);
1196:             setp(PV_STR, $3);
1197:         }
1198: ;
1199: index:      instmnt LPAREN keys RPAREN =
1200:         {
1201:             if (Rsdmno > MAXKEYS)
1202:                 /* too many attributes in key */
1203:                 par_error(INDEXTRA, WARN, 0);
1204:         }
1205: ;
1206: instmnt:    indexq ON NAME IS NAME =
1207:         {
1208:             /* init INDEX command */
1209:             Rsdmno = 0;
1210:             setp(PV_STR, $3);
1211:             setp(PV_STR, $5);
1212:             Indexname = $5;
1213:         }
1214: ;
1215: indexq:     INDEX =
1216:         {
1217:             Opflag = mdINDEX;
1218:         }
1219: ;
1220: modify:     modstmnt alias TO modstorage modkeys modqual
1221: ;
1222: modstmnt:   MODIFY =
1223:         {
1224:             Opflag = mdMODIFY;
1225:             Rsdmno = 0;
1226:         }
1227: ;
1228: modstorage: NAME =
1229:         {
1230:             setp(PV_STR, $1);
1231:         }
1232: modkeys:    modstkey modrptkey
1233:     |   ;
1234: ;
1235: modstkey:   ON =
1236:         {
1237:             setp(PV_STR, "name");
1238:         }
1239: ;
1240: modrptkey:  modbasekey
1241:     |   modrptkey COMMA modbasekey
1242: ;
1243: modbasekey: NAME =
1244:         {
1245:             setp(PV_STR, $1);
1246:         }
1247:     |   NAME COLON NAME =
1248:         {
1249:             concat($1, ztack(":", $3), modbuf);
1250:             setp(PV_STR, modbuf);
1251:         }
1252: ;
1253: modqual:    modcond modfill
1254:     |   ;
1255: ;
1256: modcond:    WHERE =
1257:         {
1258:             setp(PV_STR, "\0");
1259:         }
1260: ;
1261: modfill:    modfillnum
1262:     |   modfill COMMA modfillnum
1263: ;
1264: modfillnum: NAME IS I2CONST =
1265:         {
1266:             setp(PV_STR, $1);
1267:             i = iocv(*($3));
1268:             setp(PV_STR, i);
1269:         }
1270:     |   NAME IS NAME =
1271:         {
1272:             setp(PV_STR, $1);
1273:             setp(PV_STR, $3);
1274:         }
1275: ;
1276: keys:       alias =
1277:         {
1278:             Rsdmno++;
1279:         }
1280:     |   keys COMMA alias =
1281:         {
1282:             Rsdmno++;
1283:         }
1284: ;
1285: print:      prinstmnt keys
1286: ;
1287: prinstmnt:  PRINT =
1288:         {
1289:             Opflag = mdPRINT;
1290:         }
1291: ;
1292: save:       savstmnt alias UNTIL date
1293: ;
1294: savstmnt:   SAVE =
1295:         {
1296:             Opflag = mdSAVE;
1297:         }
1298: ;
1299: date:       month day_year day_year
1300: ;
1301: month:      alias
1302:     |   day_year
1303: ;
1304: day_year:   I2CONST =
1305:         {
1306:             i = iocv(*($1));
1307: 
1308: #			ifdef   xPTR3
1309:             tTfp(39, 4, "day_year: %s\n", i);
1310: #			endif
1311: 
1312:             setp(PV_STR, i);
1313:         }
1314: ;
1315: %%
1316: # include   "scanner.h"
1317: # include   "tables.y"
1318: # include   "yyerror.y"

Defined macros

YYDEBUG defined in line 30; never used
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3125
Valid CSS Valid XHTML 1.0 Strict