home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / Watcher / control.y < prev    next >
Encoding:
Text File  |  1989-07-26  |  4.7 KB  |  254 lines

  1. /*
  2.    the grammar describing the control file for watcher.
  3.  
  4.    Kenneth Ingham
  5.  
  6.    Copyright (C) 1987 The University of New Mexico
  7. */
  8.  
  9. %token PIPELINE FLOAT INTEGER STRING QUOTED_STRING
  10. %start command
  11.  
  12. %{
  13. #include "defs.h"
  14. extern struct cmd_st *clist;
  15. extern int control_line, parse_error;
  16. int nslist = 0;
  17. struct cmd_st *build_cmd();
  18. struct rel_out_st *build_rel();
  19. struct col_out_st *build_col();
  20. struct change_fmt_st *build_pct(), *build_abs();
  21. struct change_fmt_st *build_maxmin(), *build_str();
  22. struct change_fmt_st *build_any();
  23.  
  24. #define add_end(type, start, what, assignto)    {\
  25.                 type *p; \
  26.                 for (p=(start); p->next != NULL; p = p->next)\
  27.                     ;\
  28.                 p->next = (what);\
  29.                 assignto = start; }
  30. %}
  31.  
  32. %union {
  33.     struct cmd_st *cmd;
  34.     struct col_out_st *cos;
  35.     struct rel_out_st *ros;
  36.     struct change_fmt_st *cfs;
  37.     struct out_fmt_st *of;
  38.     char **strarray;
  39.     char *str;
  40.     char chr;
  41.     int integer;
  42.     struct number *np;
  43.     float real;
  44. }
  45.  
  46. %type <str>        PIPELINE STRING QUOTED_STRING
  47. %type <integer>        INTEGER
  48. %type <real>        FLOAT
  49. %type <cmd>        command    
  50. %type <cmd>        one_command
  51. %type <cfs>        change_fmt
  52. %type <cfs>        one_change_fmt
  53. %type <of>        out_fmt
  54. %type <ros>        rel_out_fmt
  55. %type <cos>        col_out_fmt
  56. %type <ros>        one_rel_fmt
  57. %type <cos>        one_col_fmt
  58. %type <strarray>    string_list
  59. %type <str>        alias    
  60. %type <cfs>        max_min_fmt
  61. %type <cfs>        str_change_fmt
  62. %type <cfs>        pct_change_fmt
  63. %type <cfs>        abs_change_fmt
  64. %type <cfs>        any_change_fmt
  65. %type <np>        number
  66.  
  67. %%
  68. /*
  69.    THE PARSER DESCRIPTION (read aloud to the beginning of
  70.    Also Sprach Zarathustra (the theme from 2001))
  71.  
  72.    As things are discovered, they are put into the linked list structure
  73.    detailed in defs.h.  
  74. */
  75.    
  76. command        : one_command
  77.             {
  78.                 if (clist == NULL)
  79.                     clist = $1;
  80.                 else
  81.                     printf("Bad error in the parser.\n");
  82.             }
  83.         | command one_command
  84.             { 
  85.                 struct cmd_st *p;
  86.  
  87.                 if (clist != NULL) {
  88.                     for (p=clist; p->next!=NULL; p=p->next)
  89.                         ;
  90.                     p->next = $2;
  91.                 }
  92.                 else
  93.                     clist = $1;
  94.             }
  95.         | error '.'
  96.             {
  97.             fprintf(stderr, "Command error ");
  98.             fprintf(stderr,"near line %d\n", control_line);
  99.             parse_error = True;
  100.             }
  101.         ;
  102.  
  103. one_command    : PIPELINE alias out_fmt ':' change_fmt '.'
  104.             { $$ = build_cmd($1, $2, $3, $5); }
  105.         ;
  106.  
  107. out_fmt        : rel_out_fmt
  108.             { 
  109.                 struct out_fmt_st *p;
  110.  
  111.                 p = allocate(struct out_fmt_st);
  112.                 p->type = RELATIVE;
  113.                 p->out_fmt.rel_fmt = $1;
  114.                 $$ = p;
  115.             }
  116.         | col_out_fmt
  117.             {
  118.                 struct out_fmt_st *p;
  119.  
  120.                 p = allocate(struct out_fmt_st);
  121.                 p->type = COLUMN;
  122.                 p->out_fmt.col_fmt = $1;
  123.                 $$ = p;
  124.             }
  125.         | error '.'
  126.             {
  127.                 fprintf(stderr,"Output format error ");
  128.                 fprintf(stderr,"near line %d\n",
  129.                     control_line);
  130.                 parse_error = True;
  131.             }
  132.         ;
  133.  
  134. change_fmt    : one_change_fmt
  135.         | change_fmt ';' one_change_fmt
  136.             {
  137.             add_end(struct change_fmt_st, $1, $3, $$);
  138.             }
  139.         | error ';'
  140.             {
  141.                 fprintf(stderr,"Change format error ");
  142.                 fprintf(stderr,"near line %d\n",
  143.                     control_line);
  144.                 parse_error = True;
  145.             }
  146.         ;
  147.  
  148. one_change_fmt    : pct_change_fmt
  149.         | abs_change_fmt
  150.         | max_min_fmt
  151.         | str_change_fmt
  152.         | any_change_fmt
  153.         | error '.'
  154.             {
  155.             fprintf(stderr,"Unknown change format type ");
  156.             fprintf(stderr,"near line %d\n", control_line);
  157.             parse_error = True;
  158.             }
  159.         ;
  160.  
  161. rel_out_fmt    : one_rel_fmt
  162.         | rel_out_fmt  one_rel_fmt
  163.             {
  164.                 add_end(struct rel_out_st, $1, $2, $$);
  165.             }
  166.         ;
  167.  
  168. col_out_fmt    : one_col_fmt
  169.         | col_out_fmt  one_col_fmt
  170.             {
  171.                 add_end(struct col_out_st, $1, $2, $$);
  172.             }
  173.         ;
  174.  
  175. one_rel_fmt    : INTEGER STRING '%' STRING
  176.             { $$ = build_rel($1, $2, $4); }
  177.         ;
  178.  
  179. one_col_fmt    : INTEGER '-' INTEGER STRING '%' STRING
  180.             { $$ = build_col($1, $3, $4, $6); }
  181.         ;
  182.  
  183. pct_change_fmt    : STRING number '%'
  184.             { $$ = build_pct($1, $2); }
  185.         ;
  186.  
  187. abs_change_fmt    : STRING number
  188.             { $$ = build_abs($1, $2); }
  189.         ;
  190.  
  191. max_min_fmt    : STRING number number
  192.             { $$ = build_maxmin($1, $2, $3); }
  193.         ;
  194.  
  195. str_change_fmt    : STRING string_list
  196.             { $$ = build_str($1, $2); nslist = 0; }
  197.         ;
  198.  
  199. any_change_fmt    : STRING
  200.             { $$ = build_any($1); }
  201.         ;
  202.  
  203. string_list    : QUOTED_STRING
  204.             {
  205.               nslist = 2;
  206.               $$ = (char **)xmalloc((unsigned)
  207.                    (nslist * sizeof(char *)));
  208.               $$[0] = $1;
  209.               $$[1] = NULL;
  210.             }
  211.         | QUOTED_STRING ',' string_list
  212.             {
  213.               $3 = (char **)realloc((char *)$3, (unsigned)
  214.                      (++nslist * sizeof(char *)));
  215.               if ($3 == NULL) {
  216.                 fprintf(stderr, "realloc failed.\n");
  217.                 exit(1);
  218.               }
  219.               $3[nslist-2] = $1;
  220.               $3[nslist-1] = NULL;
  221.               $$ = $3;
  222.             }
  223.         ;
  224.  
  225. number        : INTEGER
  226.             {
  227.             struct number *np;
  228.  
  229.             np = allocate(struct number);
  230.             np->type = INTEGER;
  231.             np->value.integer = $1;
  232.             $$ = np;
  233.             }
  234.         | FLOAT
  235.             {
  236.             struct number *np;
  237.  
  238.             np = allocate(struct number);
  239.             np->type = FLOAT;
  240.             np->value.real = $1;
  241.             $$ = np;
  242.             }
  243.         ;
  244.  
  245. alias        : '{' STRING '}'
  246.             {
  247.                 $$ = $2;
  248.             }
  249.         | empty 
  250.             { $$ = NULL; }
  251.         ;
  252.  
  253. empty        : ;
  254.