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