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