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