home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lr.zip / LR_SQL.C < prev    next >
C/C++ Source or Header  |  1993-05-15  |  5KB  |  105 lines

  1.  
  2. /*
  3. ______________________________________________________________________________
  4. Example LR processing
  5. Philip R Brenan, Transcendental Automation, 1993, CompuServe 71022,3620
  6. ______________________________________________________________________________
  7. */
  8. #include "lrx.inc"           //01 Include this file in all parsing programs
  9. #include "lr_sql.str"        //02 Generated declarations for SQL
  10. #include "lr_sql.cc"         //03 Generated load procedures for SQL
  11.  
  12. lrx_cmd(lr_sql_print);       //04 Generic print routine for any non terminal
  13. lrx_cmd(lr_sql_ts_options);  //05 Print routine for create tablespace options
  14. /*
  15. _______________________________________________________________________________
  16. Parse the sql in LR_SQL.SQL and print each non terminal
  17. _______________________________________________________________________________
  18. */
  19. int main(void)               //06 Main procedure
  20.  {LRX_REQ    r;              //07 Request structure to lrx_req
  21.   LR_SQL_cmd cmd;            //08 Procedures to implement non terminals for SQL
  22.   LR_SQL_NPS nps;            //09 Non terminal work area for SQL
  23.   int        i, j;           //10 Counters
  24.  
  25.   r.pre  = cmd.pre;          //11 Initialize pointer to pre commands for SQL
  26.   r.post = 0;                //12 No post commands
  27.   r.nps  = &.nps;            //13 Initialize pointer to Non terminal Pointer Set work area for SQL
  28. /*
  29. _______________________________________________________________________________
  30. Load print routine into each non terminal's pre command - must initialize each
  31. semantic routine pointer, or set to zero.  r.post will be zero and hence ignored.
  32. _______________________________________________________________________________
  33. */
  34.   for(i = 0; i < LR_SQL_n; ++i)           //14 For each non terminal in SQL
  35.    {cmd.pre[i] = lr_sql_print;            //15 Set print routine as semantic action
  36.    }
  37.   cmd.pre[LR_SQL_CREATE_TS_OPTIONS_n] = lr_sql_ts_options;
  38.                                           //16 Load semantic action for specific non terminal
  39. /*
  40. _______________________________________________________________________________
  41. Request parse of the sql in LR_SQL.SQL and print each non terminal
  42. _______________________________________________________________________________
  43. */
  44.   r.text_file    = "lr_sql.sql";          //17 Name the input filer
  45.   r.grammar_file = "lr_sql.lrs";          //18 Name grammar file
  46.   r.req          = lrx_req_load_grammar | //19 Load grammar
  47.                    lrx_req_load_text    | //20 Load text
  48.                    lrx_req_parse        | //21 Parse text with grammar
  49.                    lrx_req_print_parse  | //22 Print parse tree
  50.                    lrx_req_free_all;      //23 Free all parse resources
  51. /*
  52. _______________________________________________________________________________
  53. Perform parse and exit
  54. _______________________________________________________________________________
  55. */
  56.   lrx_req(&.r);                           //24 Perform requests
  57.  }
  58. /*
  59. _______________________________________________________________________________
  60. Generic Semantic action
  61. REQ - request list
  62. PT  - Non terminal pointer
  63. _______________________________________________________________________________
  64. */
  65. lrx_cmd(lr_sql_print)                     //25 Generic print
  66.  {printf("%s", PT->k);                    //26 Print non terminal name
  67.   if (PT->t)                              //27 If non terminal has a value
  68.     printf(" = %s", PT->t);               //28 Print associated value
  69.   printf("\n");                           //29 New line
  70.  }
  71. /*
  72. _______________________________________________________________________________
  73. Put a non terminal - lrx_concat concatenates all the text under the given
  74. non terminal
  75. _______________________________________________________________________________
  76. */
  77. void lr_sql_put(LR_PT *pt)                  //30 Put a non terminal
  78.  {char   c[256];                            //31 Character buffer
  79.  
  80.   if (pt) printf("%s ", lrx_concat(c, pt)); //32 Print non terminal if present
  81.  }
  82. /*
  83. _______________________________________________________________________________
  84. CREATE_TS_OPTIONS semantic action.
  85. Get addressability to non terminals beneath current non terminal, and print them
  86.  
  87. REQ - request list - from main procedure
  88. PT  - Non terminal pointer
  89. _______________________________________________________________________________
  90. */
  91. lrx_cmd(lr_sql_ts_options)                   //33 Process CREATE_TS_OPTIONS non terminal
  92.  {LR_SQL_NT_CREATE_TS_OPTIONS a;             //34 Pointers to this non terminal's immediate decendents
  93.  
  94.   LR_SQL_LOAD_NT_CREATE_TS_OPTIONS(&.a, PT); //35 Get addressability to non terminals dependents
  95.  
  96.   lr_sql_put(a.FREEPAGE);                    //36 Print FREEPAGE
  97.   lr_sql_put(a.PCTFREE);                     //37 Print PCTFREE
  98.   lr_sql_put(a.BUFFERPOOL3);                 //38 Print BUFFERPOOL
  99.   lr_sql_put(a.LOCKSIZE);                    //39 Print LOCKSIZE
  100.   lr_sql_put(a.CLOSE);                       //40 Print CLOSE
  101.   printf("\n");                              //41 New line
  102.  }
  103.  
  104.  
  105.