1 %{ 2 /*- 3 * Copyright (c) 1980, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * %sccs.include.redist.c% 7 * 8 * @(#)lang.l 8.1 (Berkeley) 06/06/93 9 */ 10 11 #include <ctype.h> 12 #include "y.tab.h" 13 #include "config.h" 14 15 #define tprintf if (do_trace) printf 16 17 /* 18 * Key word table 19 */ 20 21 struct kt { 22 char *kt_name; 23 int kt_val; 24 } key_words[] = { 25 { "and", AND }, 26 { "args", ARGS }, 27 { "at", AT }, 28 #if MACHINE_I386 29 { "bio", BIO }, 30 #endif MACHINE_I386 31 { "config", CONFIG }, 32 { "controller", CONTROLLER }, 33 { "cpu", CPU }, 34 { "csr", CSR }, 35 { "device", DEVICE }, 36 { "disk", DISK }, 37 { "drive", DRIVE }, 38 #if MACHINE_I386 39 { "drq", DRQ }, 40 #endif MACHINE_I386 41 { "dst", DST }, 42 { "dumps", DUMPS }, 43 { "flags", FLAGS }, 44 { "hz", HZ }, 45 { "ident", IDENT }, 46 { "interleave", INTERLEAVE }, 47 #if MACHINE_I386 48 { "iomem", IOMEM }, 49 { "iosiz", IOSIZ }, 50 { "irq", IRQ }, 51 #endif MACHINE_I386 52 { "machine", MACHINE }, 53 { "major", MAJOR }, 54 { "makeoptions", MAKEOPTIONS }, 55 { "master", MASTER }, 56 { "maxusers", MAXUSERS }, 57 { "minor", MINOR }, 58 #if MACHINE_I386 59 { "net", NET }, 60 #endif MACHINE_I386 61 { "nexus", NEXUS }, 62 { "on", ON }, 63 { "options", OPTIONS }, 64 #if MACHINE_I386 65 { "port", PORT }, 66 #endif MACHINE_I386 67 { "priority", PRIORITY }, 68 { "pseudo-device",PSEUDO_DEVICE }, 69 { "root", ROOT }, 70 #if MACHINE_HP300 || MACHINE_LUNA68K 71 { "scode", NEXUS }, 72 #endif 73 { "sequential", SEQUENTIAL }, 74 { "size", SIZE }, 75 { "slave", SLAVE }, 76 { "swap", SWAP }, 77 { "tape", DEVICE }, 78 #if MACHINE_I386 79 { "tty", TTY }, 80 #endif MACHINE_I386 81 { "timezone", TIMEZONE }, 82 { "trace", TRACE }, 83 { "vector", VECTOR }, 84 { 0, 0 }, 85 }; 86 %} 87 WORD [A-Za-z_][-A-Za-z_]* 88 %% 89 {WORD} { 90 int i; 91 92 if ((i = kw_lookup(yytext)) == -1) 93 { 94 yylval.str = yytext; 95 tprintf("id(%s) ", yytext); 96 return ID; 97 } 98 tprintf("(%s) ", yytext); 99 return i; 100 } 101 \"[^"]+\" { 102 yytext[strlen(yytext)-1] = '\0'; 103 yylval.str = yytext + 1; 104 return ID; 105 } 106 0[0-7]* { 107 yylval.val = octal(yytext); 108 tprintf("#O:%o ", yylval.val); 109 return NUMBER; 110 } 111 0x[0-9a-fA-F]+ { 112 yylval.val = hex(yytext); 113 tprintf("#X:%x ", yylval.val); 114 return NUMBER; 115 } 116 [1-9][0-9]* { 117 yylval.val = atoi(yytext); 118 tprintf("#D:%d ", yylval.val); 119 return NUMBER; 120 } 121 [0-9]"."[0-9]* { 122 double atof(); 123 yylval.val = (int) (60 * atof(yytext) + 0.5); 124 return FPNUMBER; 125 } 126 "-" { 127 return MINUS; 128 } 129 "?" { 130 yylval.val = -1; 131 tprintf("? "); 132 return NUMBER; 133 } 134 \n/[ \t] { 135 yyline++; 136 tprintf("\n... "); 137 } 138 \n { 139 yyline++; 140 tprintf("\n"); 141 return SEMICOLON; 142 } 143 #.* { /* Ignored (comment) */; } 144 [ \t]* { /* Ignored (white space) */; } 145 ";" { return SEMICOLON; } 146 "," { return COMMA; } 147 "=" { return EQUALS; } 148 "@" { return AT; } 149 . { return yytext[0]; } 150 151 %% 152 /* 153 * kw_lookup 154 * Look up a string in the keyword table. Returns a -1 if the 155 * string is not a keyword otherwise it returns the keyword number 156 */ 157 158 kw_lookup(word) 159 register char *word; 160 { 161 register struct kt *kp; 162 163 for (kp = key_words; kp->kt_name != 0; kp++) 164 if (eq(word, kp->kt_name)) 165 return kp->kt_val; 166 return -1; 167 } 168 169 /* 170 * Number conversion routines 171 */ 172 173 octal(str) 174 char *str; 175 { 176 int num; 177 178 (void) sscanf(str, "%o", &num); 179 return num; 180 } 181 182 hex(str) 183 char *str; 184 { 185 int num; 186 187 (void) sscanf(str+2, "%x", &num); 188 return num; 189 } 190