home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume10 / contool / part02 / parse.y < prev    next >
Text File  |  1990-10-30  |  7KB  |  319 lines

  1. /************************************************************************/
  2. /*    Copyright 1988-1990 by Chuck Musciano and Harris Corporation    */
  3. /*                                    */
  4. /*    Permission to use, copy, modify, and distribute this software    */
  5. /*    and its documentation for any purpose and without fee is    */
  6. /*    hereby granted, provided that the above copyright notice    */
  7. /*    appear in all copies and that both that copyright notice and    */
  8. /*    this permission notice appear in supporting documentation, and    */
  9. /*    that the name of Chuck Musciano and Harris Corporation not be    */
  10. /*    used in advertising or publicity pertaining to distribution    */
  11. /*    of the software without specific, written prior permission.    */
  12. /*    Chuck Musciano and Harris Corporation make no representations    */
  13. /*    about the suitability of this software for any purpose.  It is    */
  14. /*    provided "as is" without express or implied warranty.  This     */
  15. /*    software may not be sold without the prior explicit permission    */
  16. /*    of Harris Corporation.                        */
  17. /************************************************************************/
  18.  
  19. %{
  20.  
  21. #include    <stdio.h>
  22. #include    <ctype.h>
  23.  
  24. #include    "manifest.h"
  25. #include    "contool.h"
  26.  
  27. EXPORT    Props    *parsed_defaults;
  28. EXPORT    Filter    *parsed_filters;
  29.  
  30. EXPORT    int    parse_errors_occured;
  31.  
  32. PRIVATE    char    *get_last_token();
  33.  
  34. PRIVATE    Filter    *curr;
  35. PRIVATE    char    *curr_file;
  36. PRIVATE    int    line_count = 1;
  37. PRIVATE    char    ungetc = -1;
  38.  
  39. %}
  40.  
  41. %start    configuration
  42.  
  43. %union    {char    *cpval;
  44.      int    ival;
  45.      Filter    *fval;
  46.      Props    *pval;
  47.     }
  48.  
  49. %token    <cpval>    STRING
  50. %token    <ival>    INTEGER
  51.  
  52. %token        LBRACE RBRACE
  53.  
  54. %token        BEEP CHECK_ICON COMMAND COMMENT DEFAULTS DELETE DISPLAY FILTERS
  55.         FLASH FLASH_ICON GOOD_ICON IGNORE LOG_BEFORE_FILTERING LOG_FILE
  56.         MATCH NO NOFLASH NOOPEN NOSTAMP OPEN PRINT SAVE STAMP TIMESTAMP TO YES
  57.  
  58. %type    <ival>    beep flash old_flash old_open old_stamp open stamp yes_no
  59. %type    <cpval>    command old_end_string string
  60. %type    <fval>    filter filter_list old_filter old_filter_list old_ignore old_save
  61.  
  62. %%
  63.  
  64. configuration    :    empty
  65.         |    old_style
  66.         |    new_style
  67.         ;
  68.  
  69. old_style    :    old_filter_list
  70.                     { parsed_defaults = NULL;
  71.                       parsed_filters = $1;
  72.                     }
  73.         ;
  74.  
  75. old_filter_list    :    old_filter
  76.                     { $$ = $1; }
  77.         |    old_filter_list old_filter
  78.                     { Filter    *f;
  79.                     
  80.                       for (f = $1; f->next; f = f->next)
  81.                          ;
  82.                       f->next = $2;
  83.                       $$ = $1;
  84.                     }
  85.         ;
  86.  
  87. old_filter    :    old_save
  88.         |    old_ignore
  89.         ;
  90.  
  91. old_save    :    SAVE beep old_flash old_open old_stamp STRING old_end_string
  92.                     { Filter    *f;
  93.                       char        *msg;
  94.  
  95.                       f = (Filter *) malloc(sizeof(Filter));
  96.                       f->save     = TRUE;
  97.                       f->beep     = $2;
  98.                       f->flash    = $3;
  99.                       f->open     = $4;
  100.                       f->stamp    = $5;
  101.                       f->start    = $6;
  102.                       f->stop     = $7;
  103.                       f->start_re = NULL;
  104.                       f->stop_re  = NULL;
  105.                       f->command  = NULL;
  106.                       f->comment  = NULL;
  107.                       f->next     = NULL;
  108.                       if (msg = compile_exp(f, f->start, f->stop))
  109.                          yyerror(msg);
  110.                       $$ = f;
  111.                     }
  112.         ;
  113.  
  114. old_ignore    :    IGNORE STRING old_end_string
  115.                     { Filter    *f;
  116.                       char        *msg;
  117.                     
  118.                       f = (Filter *) malloc(sizeof(Filter));
  119.                       f->save     = FALSE;
  120.                       f->beep     = 0;
  121.                       f->flash    = FALSE;
  122.                       f->open     = FALSE;
  123.                       f->stamp    = FALSE;
  124.                       f->start    = $2;
  125.                       f->stop     = $3;
  126.                       f->start_re = NULL;
  127.                       f->stop_re  = NULL;
  128.                       f->command  = NULL;
  129.                       f->comment  = NULL;
  130.                       f->next     = NULL;
  131.                       if (msg = compile_exp(f, f->start, f->stop))
  132.                          yyerror(msg);
  133.                       $$ = f;
  134.                     }
  135.         ;
  136.  
  137. old_flash    :    FLASH
  138.                     { $$ = TRUE; }
  139.         |    NOFLASH
  140.                     { $$ = FALSE; }
  141.         ;
  142.  
  143. old_open    :    OPEN
  144.                     { $$ = TRUE; }
  145.         |    NOOPEN
  146.                     { $$ = FALSE; }
  147.         ;
  148.  
  149. old_stamp    :    STAMP
  150.                     { $$ = TRUE; }
  151.         |    NOSTAMP
  152.                     { $$ = FALSE; }
  153.         ;
  154.  
  155. old_end_string    :    empty
  156.                     { $$ = NULL; }
  157.         |    TO STRING
  158.                     { $$ = $2; }
  159.         ;
  160.  
  161. new_style    :    defaults
  162.         |    filters
  163.         |    defaults filters
  164.         ;
  165.  
  166. defaults    :    DEFAULTS
  167.                     { parsed_defaults = (Props *) malloc(sizeof(Props));
  168.                       *parsed_defaults = defaults;
  169.                     }
  170.             LBRACE default_list RBRACE
  171.         ;
  172.  
  173. filters        :    FILTERS LBRACE filter_list RBRACE
  174.                     { parsed_filters = $3; }
  175.         ;
  176.  
  177. default_list    :    empty
  178.         |    default_list default
  179.         ;
  180.  
  181. default        :    beep
  182.                     { parsed_defaults->beep = $1; }
  183.         |    command
  184.                     { parsed_defaults->command = $1; }
  185.         |    flash
  186.                     { parsed_defaults->flash = $1; }
  187.         |    open
  188.                     { parsed_defaults->open = $1; }
  189.         |    stamp
  190.                     { parsed_defaults->stamp = $1; }
  191.         |    CHECK_ICON string
  192.                     { parsed_defaults->bad_icon = $2; }
  193.         |    DELETE INTEGER
  194.                     { parsed_defaults->delete_amount = $2; }
  195.         |    DISPLAY INTEGER
  196.                     { parsed_defaults->max_size = $2; }
  197.         |    FLASH_ICON string
  198.                     { parsed_defaults->flash_icon = $2; }
  199.         |    GOOD_ICON string
  200.                     { parsed_defaults->good_icon = $2; }
  201.         |    LOG_BEFORE_FILTERING yes_no
  202.                     { parsed_defaults->log_after = !$2; }
  203.         |    LOG_FILE string
  204.                     { parsed_defaults->log_file = $2; }
  205.         |    PRINT STRING
  206.                     { parsed_defaults->print_filter = $2; }
  207.         |    TIMESTAMP INTEGER
  208.                     { parsed_defaults->stamp_resolution = $2; }
  209.         ;
  210.  
  211. filter_list    :    empty
  212.                     { $$ = NULL; }
  213.         |    filter_list filter
  214.                     { Filter    *f;
  215.                     
  216.                       if ($1 == NULL)
  217.                          $$ = $2;
  218.                       else {
  219.                          for (f = $1; f->next; f = f->next)
  220.                             ;
  221.                          f->next = $2;
  222.                          $$ = $1;
  223.                          }
  224.                     }
  225.         ;
  226.  
  227. filter        :    LBRACE
  228.                     { curr = (Filter *) malloc(sizeof(Filter));
  229.                       bzero(curr, sizeof(Filter));
  230.                     }
  231.             filter_attr_list RBRACE
  232.                     { char    *msg;
  233.                     
  234.                       if (curr->start == NULL)
  235.                          yyerror("no filter pattern specified");
  236.                       if (msg = compile_exp(curr, curr->start, curr->stop))
  237.                          yyerror(msg);
  238.                       $$ = curr;
  239.                     }
  240.         ;
  241.  
  242. filter_attr_list:    empty
  243.         |    filter_attr_list filter_attr
  244.         ;
  245.  
  246. filter_attr    :    beep
  247.                     { curr->beep = $1; }
  248.         |    command
  249.                     { curr->command = $1; }
  250.         |    flash
  251.                     { curr->flash = $1; }
  252.         |    open
  253.                     { curr->open = $1; }
  254.         |    stamp
  255.                     { curr->stamp = $1; }
  256.         |    COMMENT string
  257.                     { curr->comment = $2; }
  258.         |    IGNORE yes_no
  259.                     { curr->save = !$2; }
  260.         |    MATCH string
  261.                     { curr->start = $2; }
  262.         |    TO string
  263.                     { curr->stop = $2; }
  264.         ;
  265.  
  266. beep        :    BEEP INTEGER
  267.                     { $$ = $2; }
  268.         ;
  269.  
  270. command        :    COMMAND string
  271.                     { $$ = $2; }
  272.         ;
  273. flash        :    FLASH yes_no
  274.                     { $$ = $2; }
  275.         ;
  276.  
  277. open        :    OPEN yes_no
  278.                     { $$ = $2; }
  279.         ;
  280.  
  281. stamp        :    STAMP yes_no
  282.                     { $$ = $2; }
  283.         ;
  284.  
  285. yes_no        :    YES
  286.                     { $$ = TRUE; }
  287.         |    NO
  288.                     { $$ = FALSE; }
  289.         ;
  290.  
  291. string        :    STRING
  292.                     { $$ = (*$1 == '\0')? NULL : $1; }
  293.         ;
  294.  
  295. empty        : ;
  296.  
  297. %%
  298.  
  299. /************************************************************************/
  300. PRIVATE    yyerror(s1, s2, s3, s4, s5, s6, s7)
  301.  
  302. char    *s1, *s2, *s3, *s4, *s5, *s6, *s7;
  303.  
  304. {    char    buf1[1024], buf2[1024];
  305.  
  306.     sprintf(buf1, "%s: line %d: ", curr_file, line_count - ((ungetc == '\n')? 1 : 0));
  307.     sprintf(buf2, s1, s2, s3, s4, s5, s6, s7);
  308.     strcat(buf1, buf2);
  309.     if (strcmp(s1, "syntax error") == 0) {
  310.        strcat(buf1, " at or near ");
  311.        strcat(buf1, get_last_token());
  312.        }
  313.     error(buf1);
  314.     yyclearin;
  315.     parse_errors_occured++;
  316. }
  317.  
  318. #include "lex.c"
  319.