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 50 struct kt { 51 char *kt_name; 52 int kt_val; 53 } key_words[] = { 54 { "and", AND }, 55 { "at", AT }, 56 { "bio", BIO }, /* XXX going away */ 57 { "bus", BUS }, 58 { "cam", CAM }, /* XXX going away */ 59 { "conflicts", CONFLICTS }, 60 { "config", CONFIG }, 61 { "controller", CONTROLLER }, 62 { "cpu", CPU }, 63 { "device", DEVICE }, 64 { "disable", DISABLE }, 65 { "disk", DISK }, 66 { "drive", DRIVE }, 67 { "drq", DRQ }, 68 { "flags", FLAGS }, 69 { "ident", IDENT }, 70 { "iomem", IOMEM }, 71 { "iosiz", IOSIZ }, 72 { "irq", IRQ }, 73 { "machine", MACHINE }, 74 { "major", MAJOR }, 75 { "makeoptions", MAKEOPTIONS }, 76 { "master", MASTER }, 77 { "maxusers", MAXUSERS }, 78 { "minor", MINOR }, 79 { "net", NET }, /* XXX going away */ 80 { "nexus", NEXUS }, 81 { "option", OPTIONS }, 82 { "options", OPTIONS }, 83 { "port", PORT }, 84 { "priority", PRIORITY }, 85 { "pseudo-device",PSEUDO_DEVICE }, 86 { "sequential", SEQUENTIAL }, 87 { "size", SIZE }, 88 { "slave", SLAVE }, 89 { "tape", DEVICE }, 90 { "target", TARGET }, 91 { "tty", TTY }, /* XXX going away */ 92 { "trace", TRACE }, 93 { "unit", UNIT }, 94 { "vector", VECTOR }, 95 { 0, 0 }, 96 }; 97 98 99 int kw_lookup __P((char *)); 100 int octal __P((char *)); 101 int hex __P((char *)); 102 103 %} 104 WORD [A-Za-z_][-A-Za-z_]* 105 ID [A-Za-z_][-A-Za-z_0-9]* 106 %START NONUM TOEOL 107 %% 108 <NONUM>{WORD} { 109 int i; 110 111 BEGIN 0; 112 if ((i = kw_lookup(yytext)) == -1) 113 { 114 yylval.str = strdup(yytext); 115 tprintf("id(%s) ", yytext); 116 return ID; 117 } 118 tprintf("(%s) ", yytext); 119 return i; 120 } 121 <INITIAL>{WORD}/[0-9]* { 122 int i; 123 124 if ((i = kw_lookup(yytext)) == -1) 125 REJECT; 126 if (i == CONTROLLER || i == DEVICE || i == DISK || 127 i == PSEUDO_DEVICE || i == AT) 128 BEGIN NONUM; 129 tprintf("(%s) ", yytext); 130 return i; 131 } 132 <INITIAL>{ID} { 133 BEGIN 0; 134 yylval.str = strdup(yytext); 135 tprintf("id(%s) ", yytext); 136 return ID; 137 } 138 \\\"[^"]+\\\" { 139 BEGIN 0; 140 yytext[yyleng-2] = '"'; 141 yytext[yyleng-1] = '\0'; 142 yylval.str = strdup(yytext + 1); 143 tprintf("id(%s) ", yytext+1); 144 return ID; 145 } 146 \"[^"]+\" { 147 BEGIN 0; 148 yytext[yyleng-1] = '\0'; 149 yylval.str = strdup(yytext + 1); 150 tprintf("id(%s) ", yytext+1); 151 return ID; 152 } 153 <TOEOL>[^# \t\n]* { 154 BEGIN 0; 155 yylval.str = strdup(yytext); 156 tprintf("id(%s) ", yytext); 157 return ID; 158 } 159 0[0-7]* { 160 yylval.val = octal(yytext); 161 tprintf("#O:%o ", yylval.val); 162 return NUMBER; 163 } 164 0x[0-9a-fA-F]+ { 165 yylval.val = hex(yytext); 166 tprintf("#X:%x ", yylval.val); 167 return NUMBER; 168 } 169 -?[1-9][0-9]* { 170 yylval.val = atoi(yytext); 171 tprintf("#D:%d ", yylval.val); 172 return NUMBER; 173 } 174 [0-9]"."[0-9]* { 175 yylval.val = (int) (60 * atof(yytext) + 0.5); 176 tprintf("#F:%d ", yylval.val); 177 return FPNUMBER; 178 } 179 "?" { 180 yylval.val = -1; 181 tprintf("? "); 182 return NUMBER; 183 } 184 \n/[ \t] { 185 yyline++; 186 tprintf("\n... "); 187 } 188 \n { 189 yyline++; 190 tprintf("\n"); 191 return SEMICOLON; 192 } 193 #.* { /* Ignored (comment) */; } 194 [ \t\f]* { /* Ignored (white space) */; } 195 ";" { return SEMICOLON; } 196 "," { return COMMA; } 197 "=" { BEGIN TOEOL; return EQUALS; } 198 "@" { return AT; } 199 . { return yytext[0]; } 200 201 %% 202 /* 203 * kw_lookup 204 * Look up a string in the keyword table. Returns a -1 if the 205 * string is not a keyword otherwise it returns the keyword number 206 */ 207 208 int 209 kw_lookup(word) 210 register char *word; 211 { 212 register struct kt *kp; 213 214 for (kp = key_words; kp->kt_name != 0; kp++) 215 if (eq(word, kp->kt_name)) 216 return kp->kt_val; 217 return -1; 218 } 219 220 /* 221 * Number conversion routines 222 */ 223 224 int 225 octal(str) 226 char *str; 227 { 228 int num; 229 230 (void) sscanf(str, "%o", &num); 231 return num; 232 } 233 234 int 235 hex(str) 236 char *str; 237 { 238 int num; 239 240 (void) sscanf(str+2, "%x", &num); 241 return num; 242 } 243