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