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