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 { "options", OPTIONS }, 82 { "port", PORT }, 83 { "priority", PRIORITY }, 84 { "pseudo-device",PSEUDO_DEVICE }, 85 { "sequential", SEQUENTIAL }, 86 { "size", SIZE }, 87 { "slave", SLAVE }, 88 { "tape", DEVICE }, 89 { "target", TARGET }, 90 { "tty", TTY }, /* XXX going away */ 91 { "trace", TRACE }, 92 { "unit", UNIT }, 93 { "vector", VECTOR }, 94 { 0, 0 }, 95 }; 96 97 98 int kw_lookup __P((char *)); 99 int octal __P((char *)); 100 int hex __P((char *)); 101 102 %} 103 WORD [A-Za-z_][-A-Za-z_]* 104 ID [A-Za-z_][-A-Za-z_0-9]* 105 %START NONUM TOEOL 106 %% 107 <NONUM>{WORD} { 108 int i; 109 110 BEGIN 0; 111 if ((i = kw_lookup(yytext)) == -1) 112 { 113 yylval.str = strdup(yytext); 114 tprintf("id(%s) ", yytext); 115 return ID; 116 } 117 tprintf("(%s) ", yytext); 118 return i; 119 } 120 <INITIAL>{WORD}/[0-9]* { 121 int i; 122 123 if ((i = kw_lookup(yytext)) == -1) 124 REJECT; 125 if (i == CONTROLLER || i == DEVICE || i == DISK || 126 i == PSEUDO_DEVICE || i == AT) 127 BEGIN NONUM; 128 tprintf("(%s) ", yytext); 129 return i; 130 } 131 <INITIAL>{ID} { 132 BEGIN 0; 133 yylval.str = strdup(yytext); 134 tprintf("id(%s) ", yytext); 135 return ID; 136 } 137 \\\"[^"]+\\\" { 138 BEGIN 0; 139 yytext[yyleng-2] = '"'; 140 yytext[yyleng-1] = '\0'; 141 yylval.str = strdup(yytext + 1); 142 tprintf("id(%s) ", yytext+1); 143 return ID; 144 } 145 \"[^"]+\" { 146 BEGIN 0; 147 yytext[yyleng-1] = '\0'; 148 yylval.str = strdup(yytext + 1); 149 tprintf("id(%s) ", yytext+1); 150 return ID; 151 } 152 <TOEOL>[^#\n]* { 153 BEGIN 0; 154 yylval.str = strdup(yytext); 155 tprintf("id(%s) ", yytext); 156 return ID; 157 } 158 0[0-7]* { 159 yylval.val = octal(yytext); 160 tprintf("#O:%o ", yylval.val); 161 return NUMBER; 162 } 163 0x[0-9a-fA-F]+ { 164 yylval.val = hex(yytext); 165 tprintf("#X:%x ", yylval.val); 166 return NUMBER; 167 } 168 -?[1-9][0-9]* { 169 yylval.val = atoi(yytext); 170 tprintf("#D:%d ", yylval.val); 171 return NUMBER; 172 } 173 [0-9]"."[0-9]* { 174 yylval.val = (int) (60 * atof(yytext) + 0.5); 175 tprintf("#F:%d ", yylval.val); 176 return FPNUMBER; 177 } 178 "?" { 179 yylval.val = -1; 180 tprintf("? "); 181 return NUMBER; 182 } 183 \n/[ \t] { 184 yyline++; 185 tprintf("\n... "); 186 } 187 \n { 188 yyline++; 189 tprintf("\n"); 190 return SEMICOLON; 191 } 192 #.* { /* Ignored (comment) */; } 193 [ \t\f]* { /* Ignored (white space) */; } 194 ";" { return SEMICOLON; } 195 "," { return COMMA; } 196 "=" { BEGIN TOEOL; return EQUALS; } 197 "@" { return AT; } 198 . { return yytext[0]; } 199 200 %% 201 /* 202 * kw_lookup 203 * Look up a string in the keyword table. Returns a -1 if the 204 * string is not a keyword otherwise it returns the keyword number 205 */ 206 207 int 208 kw_lookup(word) 209 register char *word; 210 { 211 register struct kt *kp; 212 213 for (kp = key_words; kp->kt_name != 0; kp++) 214 if (eq(word, kp->kt_name)) 215 return kp->kt_val; 216 return -1; 217 } 218 219 /* 220 * Number conversion routines 221 */ 222 223 int 224 octal(str) 225 char *str; 226 { 227 int num; 228 229 (void) sscanf(str, "%o", &num); 230 return num; 231 } 232 233 int 234 hex(str) 235 char *str; 236 { 237 int num; 238 239 (void) sscanf(str+2, "%x", &num); 240 return num; 241 } 242