home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.sbin / config / lang.l < prev    next >
Encoding:
Lex Description  |  1991-04-19  |  4.8 KB  |  214 lines

  1. %{
  2. /*-
  3.  * Copyright (c) 1980 The Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in the
  13.  *    documentation and/or other materials provided with the distribution.
  14.  * 3. All advertising materials mentioning features or use of this software
  15.  *    must display the following acknowledgement:
  16.  *    This product includes software developed by the University of
  17.  *    California, Berkeley and its contributors.
  18.  * 4. Neither the name of the University nor the names of its contributors
  19.  *    may be used to endorse or promote products derived from this software
  20.  *    without specific prior written permission.
  21.  *
  22.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32.  * SUCH DAMAGE.
  33.  *
  34.  *    @(#)lang.l    5.8 (Berkeley) 4/19/91
  35.  */
  36.  
  37. #include <ctype.h>
  38. #include "y.tab.h"
  39. #include "config.h"
  40.  
  41. #define tprintf if (do_trace) printf
  42.  
  43. /*
  44.  * Key word table
  45.  */
  46.  
  47. struct kt {
  48.     char *kt_name;
  49.     int kt_val;
  50. } key_words[] = {
  51.     { "and",    AND },
  52.     { "args",    ARGS },
  53.     { "at",        AT },
  54. #if MACHINE_I386
  55.     { "bio",    BIO },
  56. #endif MACHINE_I386
  57.     { "config",    CONFIG },
  58.     { "controller",    CONTROLLER },
  59.     { "cpu",    CPU },
  60.     { "csr",    CSR },
  61.     { "device",    DEVICE },
  62.     { "disk",    DISK },
  63.     { "drive",    DRIVE },
  64. #if    MACHINE_I386
  65.     { "drq",    DRQ },
  66. #endif MACHINE_I386
  67.     { "dst",    DST },
  68.     { "dumps",    DUMPS },
  69.     { "flags",    FLAGS },
  70.     { "hz",        HZ },
  71.     { "ident",    IDENT },
  72. #if MACHINE_I386
  73.     { "iomem",    IOMEM },
  74.     { "iosiz",    IOSIZ },
  75.     { "irq",    IRQ },
  76. #endif MACHINE_I386
  77.     { "machine",    MACHINE },
  78.     { "major",    MAJOR },
  79.     { "makeoptions", MAKEOPTIONS },
  80.     { "master",    MASTER },
  81.     { "maxusers",    MAXUSERS },
  82.     { "minor",    MINOR },
  83. #if MACHINE_I386
  84.     { "net",    NET },
  85. #endif MACHINE_I386
  86.     { "nexus",    NEXUS },
  87.     { "on",        ON },
  88.     { "options",    OPTIONS },
  89. #if MACHINE_I386
  90.     { "port",    PORT },
  91. #endif MACHINE_I386
  92.     { "priority",    PRIORITY },
  93.     { "pseudo-device",PSEUDO_DEVICE },
  94.     { "root",    ROOT },
  95. #if MACHINE_HP300
  96.     { "scode",    NEXUS },
  97. #endif
  98.     { "size",    SIZE },
  99.     { "slave",    SLAVE },
  100.     { "swap",    SWAP },
  101.     { "tape",    DEVICE },
  102. #if MACHINE_I386
  103.     { "tty",    TTY },
  104. #endif MACHINE_I386
  105.     { "timezone",    TIMEZONE },
  106.     { "trace",    TRACE },
  107.     { "vector",    VECTOR },
  108.     { 0, 0 },
  109. };
  110. %}
  111. WORD    [A-Za-z_][-A-Za-z_]*
  112. %%
  113. {WORD}        {
  114.             int i;
  115.  
  116.             if ((i = kw_lookup(yytext)) == -1)
  117.             {
  118.                 yylval.str = yytext;
  119.                 tprintf("id(%s) ", yytext);
  120.                 return ID;
  121.             }
  122.             tprintf("(%s) ", yytext);
  123.             return i;
  124.         }
  125. \"[^"]+\"    {
  126.             yytext[strlen(yytext)-1] = '\0';
  127.             yylval.str = yytext + 1;
  128.             return ID;
  129.         }
  130. 0[0-7]*        {
  131.             yylval.val = octal(yytext);
  132.             tprintf("#O:%o ", yylval.val);
  133.             return NUMBER;
  134.         }
  135. 0x[0-9a-fA-F]+    {
  136.             yylval.val = hex(yytext);
  137.             tprintf("#X:%x ", yylval.val);
  138.             return NUMBER;
  139.         }
  140. [1-9][0-9]*    {
  141.             yylval.val = atoi(yytext);
  142.             tprintf("#D:%d ", yylval.val);
  143.             return NUMBER;
  144.         }
  145. [0-9]"."[0-9]*    {
  146.             double atof();
  147.             yylval.val = (int) (60 * atof(yytext) + 0.5);
  148.             return FPNUMBER;
  149.         }
  150. "-"        {
  151.             return MINUS;
  152.         }
  153. "?"        {
  154.             yylval.val = -1;
  155.             tprintf("? ");
  156.             return NUMBER;
  157.         }
  158. \n/[ \t]    {
  159.             yyline++;
  160.             tprintf("\n... ");
  161.         }
  162. \n        {
  163.             yyline++;
  164.             tprintf("\n");
  165.             return SEMICOLON;
  166.         }
  167. #.*        {    /* Ignored (comment) */;    }
  168. [ \t]*        {    /* Ignored (white space) */;    }
  169. ";"        {    return SEMICOLON;        }
  170. ","        {    return COMMA;            }
  171. "="        {    return EQUALS;            }
  172. "@"        {    return AT;            }
  173. .        {    return yytext[0];        }
  174.  
  175. %%
  176. /*
  177.  * kw_lookup
  178.  *    Look up a string in the keyword table.  Returns a -1 if the
  179.  *    string is not a keyword otherwise it returns the keyword number
  180.  */
  181.  
  182. kw_lookup(word)
  183. register char *word;
  184. {
  185.     register struct kt *kp;
  186.  
  187.     for (kp = key_words; kp->kt_name != 0; kp++)
  188.         if (eq(word, kp->kt_name))
  189.             return kp->kt_val;
  190.     return -1;
  191. }
  192.  
  193. /*
  194.  * Number conversion routines
  195.  */
  196.  
  197. octal(str)
  198. char *str;
  199. {
  200.     int num;
  201.  
  202.     (void) sscanf(str, "%o", &num);
  203.     return num;
  204. }
  205.  
  206. hex(str)
  207. char *str;
  208. {
  209.     int num;
  210.  
  211.     (void) sscanf(str+2, "%x", &num);
  212.     return num;
  213. }
  214.