lang.l revision 4242
1226031Sstas%{
2226031Sstas/*-
3226031Sstas * Copyright (c) 1980, 1993
4226031Sstas *	The Regents of the University of California.  All rights reserved.
5226031Sstas *
6226031Sstas * Redistribution and use in source and binary forms, with or without
7226031Sstas * modification, are permitted provided that the following conditions
8226031Sstas * are met:
9226031Sstas * 1. Redistributions of source code must retain the above copyright
10226031Sstas *    notice, this list of conditions and the following disclaimer.
11226031Sstas * 2. Redistributions in binary form must reproduce the above copyright
12226031Sstas *    notice, this list of conditions and the following disclaimer in the
13226031Sstas *    documentation and/or other materials provided with the distribution.
14226031Sstas * 3. All advertising materials mentioning features or use of this software
15226031Sstas *    must display the following acknowledgement:
16226031Sstas *	This product includes software developed by the University of
17226031Sstas *	California, Berkeley and its contributors.
18226031Sstas * 4. Neither the name of the University nor the names of its contributors
19226031Sstas *    may be used to endorse or promote products derived from this software
20226031Sstas *    without specific prior written permission.
21226031Sstas *
22226031Sstas * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25226031Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32226031Sstas * SUCH DAMAGE.
33226031Sstas *
34226031Sstas *	@(#)lang.l	8.1 (Berkeley) 6/6/93
35226031Sstas */
36226031Sstas
37226031Sstas#include <ctype.h>
38226031Sstas#include "y.tab.h"
39226031Sstas#include "config.h"
40226031Sstas
41226031Sstas#define tprintf if (do_trace) printf
42226031Sstas
43226031Sstas/*
44226031Sstas * Key word table
45226031Sstas */
46226031Sstas
47226031Sstasstruct kt {
48226031Sstas	char *kt_name;
49226031Sstas	int kt_val;
50226031Sstas} key_words[] = {
51226031Sstas	{ "and",	AND },
52226031Sstas	{ "args",	ARGS },
53226031Sstas	{ "at",		AT },
54226031Sstas#if MACHINE_I386
55226031Sstas	{ "bio",	BIO },
56226031Sstas#endif MACHINE_I386
57226031Sstas	{ "config",	CONFIG },
58226031Sstas	{ "controller",	CONTROLLER },
59226031Sstas	{ "cpu",	CPU },
60226031Sstas	{ "csr",	CSR },
61226031Sstas	{ "device",	DEVICE },
62226031Sstas	{ "disk",	DISK },
63226031Sstas	{ "drive",	DRIVE },
64226031Sstas#if	MACHINE_I386
65226031Sstas	{ "drq",	DRQ },
66226031Sstas#endif MACHINE_I386
67226031Sstas	{ "dst",	DST },
68226031Sstas	{ "dumps",	DUMPS },
69226031Sstas	{ "flags",	FLAGS },
70226031Sstas	{ "hz",		HZ },
71226031Sstas	{ "ident",	IDENT },
72226031Sstas	{ "interleave",	INTERLEAVE },
73226031Sstas#if MACHINE_I386
74226031Sstas	{ "iomem",	IOMEM },
75226031Sstas	{ "iosiz",	IOSIZ },
76226031Sstas	{ "irq",	IRQ },
77226031Sstas#endif MACHINE_I386
78226031Sstas	{ "machine",	MACHINE },
79226031Sstas	{ "major",	MAJOR },
80226031Sstas	{ "makeoptions", MAKEOPTIONS },
81226031Sstas	{ "master",	MASTER },
82226031Sstas	{ "maxusers",	MAXUSERS },
83226031Sstas	{ "minor",	MINOR },
84226031Sstas#if MACHINE_I386
85226031Sstas	{ "net",	NET },
86226031Sstas#endif MACHINE_I386
87226031Sstas	{ "nexus",	NEXUS },
88226031Sstas	{ "on",		ON },
89226031Sstas	{ "options",	OPTIONS },
90226031Sstas#if MACHINE_I386
91226031Sstas	{ "port",	PORT },
92226031Sstas#endif MACHINE_I386
93226031Sstas	{ "priority",	PRIORITY },
94226031Sstas	{ "pseudo-device",PSEUDO_DEVICE },
95226031Sstas	{ "root",	ROOT },
96226031Sstas#if MACHINE_HP300 || MACHINE_LUNA68K
97226031Sstas	{ "scode",	NEXUS },
98226031Sstas#endif
99	{ "sequential",	SEQUENTIAL },
100	{ "size",	SIZE },
101	{ "slave",	SLAVE },
102	{ "swap",	SWAP },
103	{ "tape",	DEVICE },
104#if MACHINE_I386
105	{ "tty",	TTY },
106#endif MACHINE_I386
107	{ "timezone",	TIMEZONE },
108	{ "trace",	TRACE },
109	{ "vector",	VECTOR },
110	{ 0, 0 },
111};
112%}
113WORD	[A-Za-z_][-A-Za-z_]*
114%%
115{WORD}		{
116			int i;
117
118			if ((i = kw_lookup(yytext)) == -1)
119			{
120				yylval.str = yytext;
121				tprintf("id(%s) ", yytext);
122				return ID;
123			}
124			tprintf("(%s) ", yytext);
125			return i;
126		}
127\"[^"]+\"	{
128			yytext[strlen(yytext)-1] = '\0';
129			yylval.str = yytext + 1;
130			return ID;
131		}
1320[0-7]*		{
133			yylval.val = octal(yytext);
134			tprintf("#O:%o ", yylval.val);
135			return NUMBER;
136		}
1370x[0-9a-fA-F]+	{
138			yylval.val = hex(yytext);
139			tprintf("#X:%x ", yylval.val);
140			return NUMBER;
141		}
142[1-9][0-9]*	{
143			yylval.val = atoi(yytext);
144			tprintf("#D:%d ", yylval.val);
145			return NUMBER;
146		}
147[0-9]"."[0-9]*	{
148			double atof();
149			yylval.val = (int) (60 * atof(yytext) + 0.5);
150			return FPNUMBER;
151		}
152"-"		{
153			return MINUS;
154		}
155"?"		{
156			yylval.val = -1;
157			tprintf("? ");
158			return NUMBER;
159		}
160\n/[ \t]	{
161			yyline++;
162			tprintf("\n... ");
163		}
164\n		{
165			yyline++;
166			tprintf("\n");
167			return SEMICOLON;
168		}
169#.*		{	/* Ignored (comment) */;	}
170[ \t\f]*	{	/* Ignored (white space) */;	}
171";"		{	return SEMICOLON;		}
172","		{	return COMMA;			}
173"="		{	return EQUALS;			}
174"@"		{	return AT;			}
175.		{	return yytext[0];		}
176
177%%
178/*
179 * kw_lookup
180 *	Look up a string in the keyword table.  Returns a -1 if the
181 *	string is not a keyword otherwise it returns the keyword number
182 */
183
184kw_lookup(word)
185register char *word;
186{
187	register struct kt *kp;
188
189	for (kp = key_words; kp->kt_name != 0; kp++)
190		if (eq(word, kp->kt_name))
191			return kp->kt_val;
192	return -1;
193}
194
195/*
196 * Number conversion routines
197 */
198
199octal(str)
200char *str;
201{
202	int num;
203
204	(void) sscanf(str, "%o", &num);
205	return num;
206}
207
208hex(str)
209char *str;
210{
211	int num;
212
213	(void) sscanf(str+2, "%x", &num);
214	return num;
215}
216