lang.l revision 45775
1%{ 2/*- 3 * Copyright (c) 1980, 1993 4 * The Regents of the University of California. 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 8.1 (Berkeley) 6/6/93 35 */ 36 37#include <ctype.h> 38#include <string.h> 39#include "y.tab.h" 40#include "config.h" 41 42#define YY_NO_UNPUT 43 44#define tprintf if (do_trace) printf 45 46/* 47 * Key word table 48 */ 49 50struct kt { 51 char *kt_name; 52 int kt_val; 53} key_words[] = { 54 { "and", AND }, 55 { "args", ARGS }, 56 { "at", AT }, 57 { "bio", BIO }, /* XXX going away */ 58 { "bus", BUS }, /* XXX going away */ 59 { "cam", CAM }, /* XXX going away */ 60 { "conflicts", CONFLICTS }, 61 { "config", CONFIG }, 62 { "controller", CONTROLLER }, 63 { "cpu", CPU }, 64 { "csr", CSR }, 65 { "device", DEVICE }, 66 { "disable", DISABLE }, 67 { "disk", DISK }, 68 { "drive", DRIVE }, 69 { "drq", DRQ }, 70 { "dumps", DUMPS }, 71 { "flags", FLAGS }, 72 { "ident", IDENT }, 73 { "interleave", INTERLEAVE }, 74 { "iomem", IOMEM }, 75 { "iosiz", IOSIZ }, 76 { "irq", IRQ }, 77 { "machine", MACHINE }, 78 { "major", MAJOR }, 79 { "makeoptions", MAKEOPTIONS }, 80 { "master", MASTER }, 81 { "maxusers", MAXUSERS }, 82 { "minor", MINOR }, 83 { "net", NET }, /* XXX going away */ 84 { "nexus", NEXUS }, 85 { "on", ON }, 86 { "options", OPTIONS }, 87 { "port", PORT }, 88 { "priority", PRIORITY }, 89 { "pseudo-device",PSEUDO_DEVICE }, 90 { "root", ROOT }, 91 { "sequential", SEQUENTIAL }, 92 { "size", SIZE }, 93 { "slave", SLAVE }, 94 { "swap", SWAP }, 95 { "tape", DEVICE }, 96 { "target", TARGET }, 97 { "tty", TTY }, /* XXX going away */ 98 { "trace", TRACE }, 99 { "unit", UNIT }, 100 { "vector", VECTOR }, 101 { 0, 0 }, 102}; 103 104 105int kw_lookup __P((char *)); 106int octal __P((char *)); 107int hex __P((char *)); 108 109%} 110WORD [A-Za-z_][-A-Za-z_]* 111%% 112{WORD} { 113 int i; 114 115 if ((i = kw_lookup(yytext)) == -1) 116 { 117 yylval.str = strdup(yytext); 118 tprintf("id(%s) ", yytext); 119 return ID; 120 } 121 tprintf("(%s) ", yytext); 122 return i; 123 } 124\\\"[^"]+\\\" { 125 yytext[strlen(yytext)-2] = '"'; 126 yytext[strlen(yytext)-1] = '\0'; 127 yylval.str = strdup(yytext + 1); 128 return ID; 129 } 130\"[^"]+\" { 131 yytext[strlen(yytext)-1] = '\0'; 132 yylval.str = strdup(yytext + 1); 133 return ID; 134 } 1350[0-7]* { 136 yylval.val = octal(yytext); 137 tprintf("#O:%o ", yylval.val); 138 return NUMBER; 139 } 1400x[0-9a-fA-F]+ { 141 yylval.val = hex(yytext); 142 tprintf("#X:%x ", yylval.val); 143 return NUMBER; 144 } 145[1-9][0-9]* { 146 yylval.val = atoi(yytext); 147 tprintf("#D:%d ", yylval.val); 148 return NUMBER; 149 } 150[0-9]"."[0-9]* { 151 yylval.val = (int) (60 * atof(yytext) + 0.5); 152 return FPNUMBER; 153 } 154"-" { 155 return MINUS; 156 } 157"?" { 158 yylval.val = -1; 159 tprintf("? "); 160 return NUMBER; 161 } 162\n/[ \t] { 163 yyline++; 164 tprintf("\n... "); 165 } 166\n { 167 yyline++; 168 tprintf("\n"); 169 return SEMICOLON; 170 } 171#.* { /* Ignored (comment) */; } 172[ \t\f]* { /* Ignored (white space) */; } 173";" { return SEMICOLON; } 174"," { return COMMA; } 175"=" { return EQUALS; } 176"@" { return AT; } 177. { return yytext[0]; } 178 179%% 180/* 181 * kw_lookup 182 * Look up a string in the keyword table. Returns a -1 if the 183 * string is not a keyword otherwise it returns the keyword number 184 */ 185 186int 187kw_lookup(word) 188register char *word; 189{ 190 register struct kt *kp; 191 192 for (kp = key_words; kp->kt_name != 0; kp++) 193 if (eq(word, kp->kt_name)) 194 return kp->kt_val; 195 return -1; 196} 197 198/* 199 * Number conversion routines 200 */ 201 202int 203octal(str) 204char *str; 205{ 206 int num; 207 208 (void) sscanf(str, "%o", &num); 209 return num; 210} 211 212int 213hex(str) 214char *str; 215{ 216 int num; 217 218 (void) sscanf(str+2, "%x", &num); 219 return num; 220} 221