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