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 "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 { "interleave", INTERLEAVE }, 73 #if MACHINE_I386 74 { "iomem", IOMEM }, 75 { "iosiz", IOSIZ }, 76 { "irq", IRQ }, 77 #endif MACHINE_I386 78 { "machine", MACHINE }, 79 { "major", MAJOR }, 80 { "makeoptions", MAKEOPTIONS }, 81 { "master", MASTER }, 82 { "maxusers", MAXUSERS }, 83 { "minor", MINOR }, 84 #if MACHINE_I386 85 { "net", NET }, 86 #endif MACHINE_I386 87 { "nexus", NEXUS }, 88 { "on", ON }, 89 { "options", OPTIONS }, 90 #if MACHINE_I386 91 { "port", PORT }, 92 #endif MACHINE_I386 93 { "priority", PRIORITY }, 94 { "pseudo-device",PSEUDO_DEVICE }, 95 { "root", ROOT }, 96 #if MACHINE_HP300 || MACHINE_LUNA68K 97 { "scode", NEXUS }, 98 #endif 99 { "sequential", SEQUENTIAL }, 100 { "size", SIZE }, 101 { "slave", SLAVE }, 102 { "swap", SWAP }, 103 { "tape", DEVICE }, 104 #if MACHINE_I386 105 { "tty", TTY }, 106 #endif MACHINE_I386 107 { "timezone", TIMEZONE }, 108 { "trace", TRACE }, 109 { "vector", VECTOR }, 110 { 0, 0 }, 111 }; 112 %} 113 WORD [A-Za-z_][-A-Za-z_]* 114 %% 115 {WORD} { 116 int i; 117 118 if ((i = kw_lookup(yytext)) == -1) 119 { 120 yylval.str = yytext; 121 tprintf("id(%s) ", yytext); 122 return ID; 123 } 124 tprintf("(%s) ", yytext); 125 return i; 126 } 127 \"[^"]+\" { 128 yytext[strlen(yytext)-1] = '\0'; 129 yylval.str = yytext + 1; 130 return ID; 131 } 132 0[0-7]* { 133 yylval.val = octal(yytext); 134 tprintf("#O:%o ", yylval.val); 135 return NUMBER; 136 } 137 0x[0-9a-fA-F]+ { 138 yylval.val = hex(yytext); 139 tprintf("#X:%x ", yylval.val); 140 return NUMBER; 141 } 142 [1-9][0-9]* { 143 yylval.val = atoi(yytext); 144 tprintf("#D:%d ", yylval.val); 145 return NUMBER; 146 } 147 [0-9]"."[0-9]* { 148 double atof(); 149 yylval.val = (int) (60 * atof(yytext) + 0.5); 150 return FPNUMBER; 151 } 152 "-" { 153 return MINUS; 154 } 155 "?" { 156 yylval.val = -1; 157 tprintf("? "); 158 return NUMBER; 159 } 160 \n/[ \t] { 161 yyline++; 162 tprintf("\n... "); 163 } 164 \n { 165 yyline++; 166 tprintf("\n"); 167 return SEMICOLON; 168 } 169 #.* { /* Ignored (comment) */; } 170 [ \t\f]* { /* Ignored (white space) */; } 171 ";" { return SEMICOLON; } 172 "," { return COMMA; } 173 "=" { return EQUALS; } 174 "@" { return AT; } 175 . { return yytext[0]; } 176 177 %% 178 /* 179 * kw_lookup 180 * Look up a string in the keyword table. Returns a -1 if the 181 * string is not a keyword otherwise it returns the keyword number 182 */ 183 184 kw_lookup(word) 185 register char *word; 186 { 187 register struct kt *kp; 188 189 for (kp = key_words; kp->kt_name != 0; kp++) 190 if (eq(word, kp->kt_name)) 191 return kp->kt_val; 192 return -1; 193 } 194 195 /* 196 * Number conversion routines 197 */ 198 199 octal(str) 200 char *str; 201 { 202 int num; 203 204 (void) sscanf(str, "%o", &num); 205 return num; 206 } 207 208 hex(str) 209 char *str; 210 { 211 int num; 212 213 (void) sscanf(str+2, "%x", &num); 214 return num; 215 } 216