home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.sbin / htable / parse.y < prev    next >
Encoding:
Lex Description  |  1991-04-19  |  3.6 KB  |  165 lines

  1. %{
  2.  
  3. /*
  4.  * Copyright (c) 1983 Regents of the University of California.
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  * 3. All advertising materials mentioning features or use of this software
  16.  *    must display the following acknowledgement:
  17.  *    This product includes software developed by the University of
  18.  *    California, Berkeley and its contributors.
  19.  * 4. Neither the name of the University nor the names of its contributors
  20.  *    may be used to endorse or promote products derived from this software
  21.  *    without specific prior written permission.
  22.  *
  23.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33.  * SUCH DAMAGE.
  34.  */
  35.  
  36. #ifndef lint
  37. static char sccsid[] = "@(#)parse.y    5.5 (Berkeley) 6/1/90";
  38. #endif /* not lint */
  39.  
  40. #include "htable.h"
  41. %}
  42.  
  43. %union {
  44.     int    number;
  45.     struct    addr *addrlist;
  46.     struct    name *namelist;
  47. }
  48. %start Table
  49.  
  50. %token            END
  51. %token <number>        NUMBER KEYWORD
  52. %token <namelist>    NAME
  53.  
  54. %type <namelist>    Names Cputype Opsys Protos Proto
  55. %type <addrlist>    Addresses Address
  56. %%
  57. Table    :    Entry
  58.     |    Table Entry
  59.     ;
  60.  
  61. Entry    :    KEYWORD ':' Addresses ':' Names ':' END
  62.     = {
  63.         do_entry($1, $3, $5, NONAME, NONAME, NONAME);
  64.     }
  65.     |    KEYWORD ':' Addresses ':' Names ':' Cputype ':' END
  66.     = {
  67.         do_entry($1, $3, $5, $7, NONAME, NONAME);
  68.     }
  69.     |    KEYWORD ':' Addresses ':' Names ':' Cputype ':' Opsys ':' END
  70.     = {
  71.         do_entry($1, $3, $5, $7, $9, NONAME);
  72.     }
  73.     |    KEYWORD ':' Addresses ':' Names ':' Cputype ':' Opsys ':' ':' END
  74.     = {
  75.         do_entry($1, $3, $5, $7, $9, NONAME);
  76.     }
  77.     |    KEYWORD ':' Addresses ':' Names ':' Cputype ':' Opsys ':' Protos ':' END
  78.     = {
  79.         do_entry($1, $3, $5, $7, $9, $11);
  80.     }
  81.     |    error END
  82.     |    END        /* blank line */
  83.     ;
  84.  
  85. Addresses:    Address
  86.     = {
  87.         $$ = $1;
  88.     }
  89.     |    Address ',' Addresses
  90.     = {
  91.         $1->addr_link = $3;
  92.         $$ = $1;
  93.     }
  94.     ;
  95.  
  96. Address    :    NUMBER '.' NUMBER '.' NUMBER '.' NUMBER
  97.     = {
  98.         char *a;
  99.  
  100.         $$ = (struct addr *)malloc(sizeof (struct addr));
  101.         a = (char *)&($$->addr_val);
  102.         a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7;
  103.         $$->addr_link = NOADDR;
  104.     }
  105.     ;
  106.  
  107. Names    :    NAME
  108.     = {
  109.         $$ = $1;
  110.     }
  111.     |    NAME ',' Names
  112.     = {
  113.         $1->name_link = $3;
  114.         $$ = $1;
  115.     }
  116.     ;
  117.  
  118. Cputype :    /* empty */
  119.     = {
  120.         $$ = NONAME;
  121.     }
  122.     |    NAME
  123.     = {
  124.         $$ = $1;
  125.     }
  126.     ;
  127.  
  128. Opsys    :    /* empty */
  129.     = {
  130.         $$ = NONAME;
  131.     }
  132.     |    NAME
  133.     = {
  134.         $$ = $1;
  135.     }
  136.     ;
  137.  
  138. Protos    :    Proto
  139.     = {
  140.         $$ = $1;
  141.     }
  142.     |    Proto ',' Protos
  143.     = {
  144.         $1->name_link = $3;
  145.         $$ = $1;
  146.     }
  147.     ;
  148.  
  149. Proto    :    NAME
  150.     = {
  151.         $$ = $1;
  152.     }
  153.     ;
  154. %%
  155.  
  156. #include <stdio.h>
  157.  
  158. extern int yylineno;
  159.  
  160. yyerror(msg)
  161.     char *msg;
  162. {
  163.     fprintf(stderr, "\"%s\", line %d: %s\n", infile, yylineno, msg);
  164. }
  165.