| [0b990d] | 1 | /*
 | 
|---|
 | 2 |  * ipv2_parse.yy
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  * Copyright (C) 1996 Limit Point Systems, Inc.
 | 
|---|
 | 5 |  *
 | 
|---|
 | 6 |  * Author: Curtis Janssen <cljanss@ca.sandia.gov>
 | 
|---|
 | 7 |  * Maintainer: LPS
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  * This file is part of the SC Toolkit.
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  * The SC Toolkit is free software; you can redistribute it and/or modify
 | 
|---|
 | 12 |  * it under the terms of the GNU Library General Public License as published by
 | 
|---|
 | 13 |  * the Free Software Foundation; either version 2, or (at your option)
 | 
|---|
 | 14 |  * any later version.
 | 
|---|
 | 15 |  *
 | 
|---|
 | 16 |  * The SC Toolkit is distributed in the hope that it will be useful,
 | 
|---|
 | 17 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 18 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 19 |  * GNU Library General Public License for more details.
 | 
|---|
 | 20 |  *
 | 
|---|
 | 21 |  * You should have received a copy of the GNU Library General Public License
 | 
|---|
 | 22 |  * along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
 | 
|---|
 | 23 |  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 | 
|---|
 | 24 |  *
 | 
|---|
 | 25 |  * The U.S. Government is granted a limited license as per AL 91-7.
 | 
|---|
 | 26 |  */
 | 
|---|
 | 27 | %{
 | 
|---|
 | 28 | #ifdef DEC
 | 
|---|
 | 29 | #include <math.h>
 | 
|---|
 | 30 | #else
 | 
|---|
 | 31 | #include <stdlib.h>
 | 
|---|
 | 32 | #endif
 | 
|---|
 | 33 | #include <string.h>
 | 
|---|
 | 34 | #ifdef BISON
 | 
|---|
 | 35 | #define YYDEBUG 0
 | 
|---|
 | 36 | #if YYDEBUG != 0
 | 
|---|
 | 37 | int yydebug =1;
 | 
|---|
 | 38 | #endif /* YYDEBUG != 0 */
 | 
|---|
 | 39 | #endif /* BISON */
 | 
|---|
 | 40 | #if defined(SABER)
 | 
|---|
 | 41 | #define xmalloc malloc
 | 
|---|
 | 42 | #endif
 | 
|---|
 | 43 | #if defined(SGI)
 | 
|---|
 | 44 | #include <alloca.h>
 | 
|---|
 | 45 | #endif
 | 
|---|
 | 46 | #include <util/keyval/ipv2.h>
 | 
|---|
 | 47 | #define yyerror sc::IPV2::yerror
 | 
|---|
 | 48 | #define yyparse sc::IPV2::yparse
 | 
|---|
 | 49 | #define yylex sc::IPV2::ylex
 | 
|---|
 | 50 | #define yywrap sc::IPV2::ywrap
 | 
|---|
 | 51 | %}
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | %union {
 | 
|---|
 | 54 |   char *str;
 | 
|---|
 | 55 |   sc::ip_string_list_t *sl;
 | 
|---|
 | 56 |   double dbl;
 | 
|---|
 | 57 |   }
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | %token T_KEYWORD_LEFT T_ARRAY_LEFT T_TABLE_LEFT
 | 
|---|
 | 60 | %token T_KEYWORD_RIGHT T_ARRAY_RIGHT T_TABLE_RIGHT
 | 
|---|
 | 61 | %token T_CONCAT
 | 
|---|
 | 62 | %token <str> T_STRING T_QUOTED_STRING
 | 
|---|
 | 63 | %type <str> string quoted_string var_key var_sub table_key polymorph
 | 
|---|
 | 64 | %type <sl> stringlist parentlist commalist
 | 
|---|
 | 65 | %type <str> expression
 | 
|---|
 | 66 | %type <dbl> subexpression expvalue
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 | %start input
 | 
|---|
 | 69 | %%
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | input:          group_defs
 | 
|---|
 | 72 |             ;
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 | group_defs:     group_defs group_def
 | 
|---|
 | 75 |             |
 | 
|---|
 | 76 |             ;
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | group_def:      keyword ':' T_KEYWORD_LEFT group_defs T_KEYWORD_RIGHT
 | 
|---|
 | 79 |                                                 { ip_pop_keyword(); }
 | 
|---|
 | 80 |             |   keyword ':' karray_defs
 | 
|---|
 | 81 |                                                 { ip_pop_keyword(); }
 | 
|---|
 | 82 |             |   keyword ':' group_def
 | 
|---|
 | 83 |                                                 { ip_pop_keyword(); }
 | 
|---|
 | 84 |             |   keyword '=' value
 | 
|---|
 | 85 |                                                 { ip_pop_keyword(); }
 | 
|---|
 | 86 |             |   T_TABLE_LEFT stringlist T_TABLE_RIGHT
 | 
|---|
 | 87 |                                                 { ip_begin_table($2); }
 | 
|---|
 | 88 |                  '='
 | 
|---|
 | 89 |                 T_TABLE_LEFT tablevalues T_TABLE_RIGHT
 | 
|---|
 | 90 |                                                 { ip_done_table(); }
 | 
|---|
 | 91 |             |   implicit_keyword ':' T_KEYWORD_LEFT group_defs T_KEYWORD_RIGHT
 | 
|---|
 | 92 |             |   implicit_keyword ':' karray_defs
 | 
|---|
 | 93 |             |   implicit_keyword ':' group_def
 | 
|---|
 | 94 |             |   implicit_keyword '=' value
 | 
|---|
 | 95 |             ;
 | 
|---|
 | 96 | /* old table construction stuff
 | 
|---|
 | 97 |             |   T_TABLE_LEFT stringlist T_TABLE_RIGHT
 | 
|---|
 | 98 |                  '='
 | 
|---|
 | 99 |                 T_TABLE_LEFT stringlist T_TABLE_RIGHT
 | 
|---|
 | 100 |                                                 { ip_construct_table($2,$6); }
 | 
|---|
 | 101 |             ;
 | 
|---|
 | 102 |  */
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 | /* One or more strings in a stringlist.
 | 
|---|
 | 105 |  * This is needed to distinguish array construction from table contruction
 | 
|---|
 | 106 |  * (with no columns-which is silly anyway).  If we allow zero or more,
 | 
|---|
 | 107 |  * then YACC complains about the reduce/reduce conflict. */
 | 
|---|
 | 108 | stringlist:     stringlist table_key
 | 
|---|
 | 109 |                             { $$ = ip_add_string_list($1,$2); }
 | 
|---|
 | 110 |             |   table_key
 | 
|---|
 | 111 |                             { $$ = ip_string_to_string_list($1); }
 | 
|---|
 | 112 |             ;
 | 
|---|
 | 113 | 
 | 
|---|
 | 114 | 
 | 
|---|
 | 115 | table_key:      table_key ':' string    { $$ = ip_append_keystrings($1,$3); }
 | 
|---|
 | 116 |             |   string                  { $$ = $1; }
 | 
|---|
 | 117 |             ;
 | 
|---|
 | 118 | 
 | 
|---|
 | 119 | tablevalues:    tablevalues value
 | 
|---|
 | 120 |             |
 | 
|---|
 | 121 |             ;
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | karray_defs:    array_left karray_elems array_right
 | 
|---|
 | 124 |             ;
 | 
|---|
 | 125 | 
 | 
|---|
 | 126 | karray_elems:   karray_elems { ip_incr_karray(); } karray_elem
 | 
|---|
 | 127 |             |                                   { ip_init_karray(); }
 | 
|---|
 | 128 |             ;
 | 
|---|
 | 129 | 
 | 
|---|
 | 130 | karray_elem:    karray_defs
 | 
|---|
 | 131 |             |   T_KEYWORD_LEFT group_defs T_KEYWORD_RIGHT
 | 
|---|
 | 132 |             |   group_def
 | 
|---|
 | 133 |             ;
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | array_left:     T_ARRAY_LEFT                    { ip_start_karray(); }
 | 
|---|
 | 136 |             ;
 | 
|---|
 | 137 | 
 | 
|---|
 | 138 | array_right:    T_ARRAY_RIGHT                   { ip_pop_karray(); }
 | 
|---|
 | 139 |             ;
 | 
|---|
 | 140 | 
 | 
|---|
 | 141 | /*
 | 
|---|
 | 142 | keyword:        T_STRING
 | 
|---|
 | 143 |                                                 { ip_push_keyword($1); }
 | 
|---|
 | 144 |             |   T_STRING '<' T_STRING '>'       { ip_push_keyclass($1,$3); }
 | 
|---|
 | 145 |             ;
 | 
|---|
 | 146 | */
 | 
|---|
 | 147 | 
 | 
|---|
 | 148 | keyword:        string                        { ip_push_keyword($1); }
 | 
|---|
 | 149 |             |   string polymorph              { ip_push_keyclass($1,$2,0); }
 | 
|---|
 | 150 |             |   string parentlist             { ip_push_keyclass($1,0,$2); }
 | 
|---|
 | 151 |             |   string parentlist polymorph   { ip_push_keyclass($1,$3,$2); }
 | 
|---|
 | 152 |             |   string polymorph parentlist   { ip_push_keyclass($1,$2,$3); }
 | 
|---|
 | 153 |             ;
 | 
|---|
 | 154 | implicit_keyword:
 | 
|---|
 | 155 |                 polymorph                       { ip_push_keyclass(0,$1,0); }
 | 
|---|
 | 156 |             ;
 | 
|---|
 | 157 | 
 | 
|---|
 | 158 | polymorph:      '<' string '>'                { $$ = $2; }
 | 
|---|
 | 159 |             ;
 | 
|---|
 | 160 | 
 | 
|---|
 | 161 | parentlist:     '<' '<' commalist '>' '>'       { $$ = $3; }
 | 
|---|
 | 162 |             ;
 | 
|---|
 | 163 | 
 | 
|---|
 | 164 | commalist:      commalist ',' string  { $$ = ip_add_string_list($1,$3); }
 | 
|---|
 | 165 |             |   string                { $$ = ip_string_to_string_list($1); }
 | 
|---|
 | 166 |             ;
 | 
|---|
 | 167 | 
 | 
|---|
 | 168 | value:          array
 | 
|---|
 | 169 |             |   string
 | 
|---|
 | 170 |                                     { ip_assign_value($1); }
 | 
|---|
 | 171 |             |   var_sub             { ip_assign_variable($1); }
 | 
|---|
 | 172 |             |   expression          { ip_assign_value($1); }
 | 
|---|
 | 173 |             ;
 | 
|---|
 | 174 | 
 | 
|---|
 | 175 | expression:     T_KEYWORD_LEFT subexpression T_KEYWORD_RIGHT
 | 
|---|
 | 176 |                                     { $$ = ip_double_to_string($2); }
 | 
|---|
 | 177 |             ;
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 | subexpression:  expvalue '*' expvalue   { $$ = $1 * $3; }
 | 
|---|
 | 180 |             |   expvalue '-' expvalue   { $$ = $1 - $3; }
 | 
|---|
 | 181 |             |   expvalue '+' expvalue   { $$ = $1 + $3; }
 | 
|---|
 | 182 |             |   expvalue '/' expvalue   { $$ = $1 / $3; }
 | 
|---|
 | 183 |             ;
 | 
|---|
 | 184 | 
 | 
|---|
 | 185 | 
 | 
|---|
 | 186 | expvalue:       var_sub             { $$ = ip_get_variable_double($1); }
 | 
|---|
 | 187 |             |   string              { $$ = atof($1); free($1); }
 | 
|---|
 | 188 |             ; 
 | 
|---|
 | 189 | 
 | 
|---|
 | 190 | var_sub:        '$' var_key         { $$ = $2; }
 | 
|---|
 | 191 |             ;
 | 
|---|
 | 192 | 
 | 
|---|
 | 193 | 
 | 
|---|
 | 194 | var_key:        var_key ':' string    { $$ = ip_append_keystrings($1,$3); }
 | 
|---|
 | 195 |             |   ':' string            { $$ = ip_append_keystrings(NULL,$2); }
 | 
|---|
 | 196 |             |   string                { $$ = $1; }
 | 
|---|
 | 197 |             ;
 | 
|---|
 | 198 | 
 | 
|---|
 | 199 | array:          array_left values array_right
 | 
|---|
 | 200 |             ;
 | 
|---|
 | 201 | 
 | 
|---|
 | 202 | values:         values { ip_incr_karray(); } value
 | 
|---|
 | 203 |             |
 | 
|---|
 | 204 |                                                 { ip_init_karray(); }
 | 
|---|
 | 205 |             ;
 | 
|---|
 | 206 | 
 | 
|---|
 | 207 | quoted_string: quoted_string T_CONCAT T_QUOTED_STRING
 | 
|---|
 | 208 |                                 { $$ = (char*) malloc(strlen($1)+strlen($3)+1);
 | 
|---|
 | 209 |                                   strcpy($$, $1);
 | 
|---|
 | 210 |                                   strcat($$, $3);
 | 
|---|
 | 211 |                                   free($1);
 | 
|---|
 | 212 |                                   free($3);
 | 
|---|
 | 213 |                                 }
 | 
|---|
 | 214 |             |  T_QUOTED_STRING
 | 
|---|
 | 215 |                                                 { $$ = $1; }
 | 
|---|
 | 216 |             ;
 | 
|---|
 | 217 | 
 | 
|---|
 | 218 | string:        T_STRING                         { $$ = $1; }
 | 
|---|
 | 219 |             |  quoted_string                    { $$ = $1; }
 | 
|---|
 | 220 |             ;
 | 
|---|
 | 221 | 
 | 
|---|
 | 222 | %%
 | 
|---|