1%{
2/*
3 * Mach Operating System
4 * Copyright (c) 1990 Carnegie-Mellon University
5 * Copyright (c) 1989 Carnegie-Mellon University
6 * Copyright (c) 1988 Carnegie-Mellon University
7 * Copyright (c) 1987 Carnegie-Mellon University
8 * All rights reserved.  The CMU software License Agreement specifies
9 * the terms and conditions for use and redistribution.
10 */
11
12/*
13 * Copyright (c) 1980 Regents of the University of California.
14 * All rights reserved.
15 *
16 * Redistribution and use in source and binary forms are permitted
17 * provided that the above copyright notice and this paragraph are
18 * duplicated in all such forms and that any documentation,
19 * advertising materials, and other materials related to such
20 * distribution and use acknowledge that the software was developed
21 * by the University of California, Berkeley.  The name of the
22 * University may not be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
26 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 *
28 *	@(#)config.l	5.5 (Berkeley) 6/18/88
29 */
30
31#include <ctype.h>
32#include "parser.h"
33#include "config.h"
34
35int	kw_lookup(char *word);
36int	octal(char *str);
37int	hex(char *str);
38int	yylex(void);
39
40#define tprintf if (do_trace) printf
41
42/*
43 * Key word table
44 */
45
46struct kt {
47	const char *kt_name;
48	int kt_val;
49} key_words[] = {
50	{ "and",	AND },
51	{ "args",	ARGS },
52	{ "at",		AT },
53	{ "builddir",	BUILDDIR },
54	{ "config",	CONFIG },
55	{ "configdir",	CONFIGDIR },
56	{ "controller",	CONTROLLER },
57	{ "cpu",	CPU },
58	{ "csr",	CSR },
59	{ "device",	DEVICE },
60	{ "disk",	DISK },
61	{ "drive",	DRIVE },
62	{ "dumps",	DUMPS },
63	{ "flags",	FLAGS },
64	{ "ident",	IDENT },
65	{ "init",	INIT },
66	{ "machine",	MACHINE },
67	{ "major",	MAJOR },
68	{ "makeoptions", MAKEOPTIONS },
69	{ "makevariables", MAKEOPTIONS },
70	{ "master",	MASTER },
71	{ "maxusers",	MAXUSERS },
72	{ "mba",	MBA },
73	{ "minor",	MINOR },
74	{ "nexus",	NEXUS },
75	{ "objectdir",	OBJECTDIR },
76	{ "on",		ON },
77	{ "options",	OPTIONS },
78	{ "priority",	PRIORITY },
79	{ "profile",	PROFILE },
80	{ "pseudo-device",PSEUDO_DEVICE },
81	{ "root",	ROOT },
82	{ "size",	SIZE },
83	{ "slave",	SLAVE },
84	{ "sourcedir",	SOURCEDIR },
85	{ "swap",	SWAP },
86	{ "tape",	DEVICE },
87	{ "trace",	TRACE },
88	{ "uba",	UBA },
89	{ "vector",	VECTOR },
90	{ "lun",	LUN },			/* MMAX only */
91	{ "slot",	SLOT },			/* MMAX only */
92	{ "tape",	TAPE },			/* MMAX only */
93	{ "bin",	BIN },			/* SQT ONLY */
94	{ "am",		ADDRMOD },		/* MIPS */
95	{ "mbii",	MBII },			/* MIPS */
96 	{ "vme",	VME },			/* MIPS */
97	{ 0, 0 },
98};
99%}
100
101%option nounput
102
103WORD	([A-Za-z_][-A-Za-z_]*|[A-Z][-A-Za-z_0-9]*)
104WORD1	([A-Za-z_][-A-Za-z_0-9]*)
105%%
106{WORD} |
107{WORD1}		{
108			int i;
109
110			if ((i = kw_lookup(yytext)) == -1)
111			{
112				yylval.str = yytext;
113				tprintf("id(%s) ", yytext);
114				return ID;
115			}
116			tprintf("(%s) ", yytext);
117			return i;
118		}
119\"[^"]+\"	{
120			yytext[strlen(yytext)-1] = '\0';
121			yylval.str = yytext + 1;
122			return ID;
123		}
1240[0-7]*		{
125			yylval.val = octal(yytext);
126			tprintf("#O:%o ", yylval.val);
127			return NUMBER;
128		}
1290x[0-9a-fA-F]+	{
130			yylval.val = hex(yytext);
131			tprintf("#X:%x ", yylval.val);
132			return NUMBER;
133		}
134[1-9][0-9]*	{
135			yylval.val = atoi(yytext);
136			tprintf("#D:%d ", yylval.val);
137			return NUMBER;
138		}
139[0-9]"."[0-9]*	{
140			yylval.val = (int) (60 * atof(yytext) + 0.5);
141			return FPNUMBER;
142		}
143"-"		{
144			return MINUS;
145		}
146"?"		{
147			yylval.val = -1;
148			tprintf("? ");
149			return NUMBER;
150		}
151\n/[ \t]	{
152			yyline++;
153			tprintf("\n... ");
154		}
155\n		{
156			yyline++;
157			tprintf("\n");
158			return SEMICOLON;
159		}
160#.*		{	/* Ignored (comment) */;	}
161[ \t]*		{	/* Ignored (white space) */;	}
162";"		{	return SEMICOLON;		}
163","		{	return COMMA;			}
164"="		{	return EQUALS;			}
165"@"		{	return AT;			}
166.		{	return yytext[0];		}
167
168
169%%
170/*
171 * kw_lookup
172 *	Look up a string in the keyword table.  Returns a -1 if the
173 *	string is not a keyword otherwise it returns the keyword number
174 */
175
176int
177kw_lookup(char *word)
178{
179	register struct kt *kp;
180
181	for (kp = key_words; kp->kt_name != 0; kp++)
182		if (eq(word, kp->kt_name))
183			return kp->kt_val;
184	return -1;
185}
186
187/*
188 * Number conversion routines
189 */
190
191int
192octal(char *str)
193{
194	int num;
195
196	(void) sscanf(str, "%o", &num);
197	return num;
198}
199
200int
201hex(char *str)
202{
203	int num;
204
205	(void) sscanf(str+2, "%x", &num);
206	return num;
207}
208
209int
210yywrap()
211{
212	return 1;
213}
214