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