home *** CD-ROM | disk | FTP | other *** search
/ gdead.berkeley.edu / gdead.berkeley.edu.tar / gdead.berkeley.edu / pub / cad-tools / ciftomann.tar / cmd_dir / parse.y < prev    next >
Text File  |  1988-01-28  |  3KB  |  178 lines

  1. %{
  2.     /* This is the yacc file describing the input syntax for
  3.      * the ciftomann command file. It is an overkill to use 
  4.      * yacc for this sort of thing, but it is easier than writing
  5.      * my own parser
  6.      */
  7. #include "pg_desc.h"
  8. extern float scale;
  9. char *strcpy();
  10. %}
  11.  
  12. %union {
  13.     char *strval;
  14.     int intval;
  15.     float floatval;
  16.     struct {
  17.     int invert_flag;
  18.     int mod_factor;
  19.     } optlistval;
  20.     struct {
  21.     enum { MOD, INV } type;
  22.     union {
  23.         int invert_flag;
  24.         int mod_factor;
  25.     } value;
  26.     } optval;
  27. }
  28.  
  29. %token LAYER NUMBER FLOAT MINUS INVERT GROW SHRINK EOL SCALE
  30. %token APERTURE_MAX APERTURE_MIN STAGE_MAX STAGE_MIN GRID_SIZE
  31. %token CONVERT_FACTOR
  32.  
  33. %type <intval> NUMBER SNUMBER
  34. %type <floatval> FLOAT
  35. %type <strval> layer_name LAYER
  36. %type <optval> option
  37. %type <optlistval> option_list options
  38.  
  39. %start file
  40.  
  41. %%
  42. file        :    scale cmds
  43.         |    cmds
  44.         ;
  45.  
  46. scale        :    SCALE NUMBER EOL
  47.                 {
  48.                     scale = (float) $2;
  49.                 }
  50.         |    SCALE FLOAT EOL
  51.                 {
  52.                     scale = $2;
  53.                 }
  54.         ;
  55.  
  56. cmds        :    cmd
  57.         |    cmds cmd
  58.         ;
  59.  
  60. cmd        :    layer
  61.         |    pg_param
  62.         ;
  63.  
  64. pg_param    :    APERTURE_MAX NUMBER EOL
  65.                 {
  66.                     pg_desc.aperture_max = $2;
  67.                     pg_modified++;
  68.                 }
  69.         |    APERTURE_MIN NUMBER EOL
  70.                 {
  71.                     pg_desc.aperture_min = $2;
  72.                     pg_modified++;
  73.                 }
  74.         |    STAGE_MAX NUMBER EOL
  75.                 {
  76.                     pg_desc.stage_max = $2;
  77.                     pg_modified++;
  78.                 }
  79.         |    STAGE_MIN NUMBER EOL
  80.                 {
  81.                     pg_desc.stage_min = $2;
  82.                     pg_modified++;
  83.                 }
  84.         |    GRID_SIZE NUMBER EOL
  85.                 {
  86.                     pg_desc.grid_size = $2;
  87.                     pg_modified++;
  88.                 }
  89.         |    CONVERT_FACTOR NUMBER EOL
  90.                 {
  91.                     pg_desc.convert_factor = $2;
  92.                     pg_modified++;
  93.                 }
  94.         |    CONVERT_FACTOR FLOAT EOL
  95.                 {
  96.                     pg_desc.convert_factor = $2;
  97.                     pg_modified++;
  98.                 }
  99.         ;
  100.  
  101. layer        :    layer_name option_list EOL
  102.                 {
  103.                     make_cmd($1,$2.mod_factor,
  104.                             $2.invert_flag,$1);
  105.                 }
  106.         |    layer_name option_list layer_name EOL
  107.                 {
  108.                     make_cmd($1,$2.mod_factor,
  109.                             $2.invert_flag,$3);
  110.                 }
  111.         ;
  112.  
  113. option_list    :    options
  114.         |
  115.                 {
  116.                     $$.mod_factor = 0;
  117.                     $$.invert_flag = 0;
  118.                 }
  119.         ;
  120.  
  121. options        :    option
  122.                 {
  123.                     if ($1.type == MOD) {
  124.                     $$.mod_factor =
  125.                         $1.value.mod_factor;
  126.                     $$.invert_flag = 0;
  127.                      } else {
  128.                     $$.invert_flag =
  129.                         $1.value.invert_flag;
  130.                     $$.mod_factor = 0;
  131.                     }
  132.                 }
  133.         |    options option
  134.                 {
  135.                     if ($2.type == MOD)
  136.                     $$.mod_factor =
  137.                         $2.value.mod_factor;
  138.                     else
  139.                     $$.invert_flag =
  140.                         $2.value.invert_flag;
  141.                 }
  142.         ;
  143.  
  144. option        :    SNUMBER
  145.                 {
  146.                     $$.type = MOD;
  147.                     $$.value.mod_factor = $1;
  148.                 }
  149.         |    SHRINK NUMBER
  150.                 {
  151.                     $$.type = MOD;
  152.                     $$.value.mod_factor = -$2;
  153.                 }
  154.         |    GROW NUMBER
  155.                 {
  156.                     $$.type = MOD;
  157.                     $$.value.mod_factor = $2;
  158.                 }
  159.         |    INVERT
  160.                 {
  161.                     $$.type = INV;
  162.                     $$.value.invert_flag = 1;
  163.                 }
  164.         ;
  165.  
  166. SNUMBER        :    NUMBER
  167.         |    MINUS NUMBER
  168.                 {
  169.                     $$ = -$2;
  170.                 }
  171.         ;
  172.  
  173. layer_name    :    LAYER
  174.                 {
  175.                     $$ = strcpy(malloc(strlen($1)+1),$1);
  176.                 }
  177.         ;
  178.