]> git.saurik.com Git - apple/xnu.git/blame - SETUP/config/lexer.l
xnu-1699.22.73.tar.gz
[apple/xnu.git] / SETUP / config / lexer.l
CommitLineData
6d2010ae
A
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 { "hz", HZ },
65 { "ident", IDENT },
66 { "init", INIT },
67 { "machine", MACHINE },
68 { "major", MAJOR },
69 { "makeoptions", MAKEOPTIONS },
70 { "makevariables", MAKEOPTIONS },
71 { "master", MASTER },
72 { "maxusers", MAXUSERS },
73 { "mba", MBA },
74 { "minor", MINOR },
75 { "nexus", NEXUS },
76 { "objectdir", OBJECTDIR },
77 { "on", ON },
78 { "options", OPTIONS },
79 { "priority", PRIORITY },
80 { "profile", PROFILE },
81 { "pseudo-device",PSEUDO_DEVICE },
82 { "root", ROOT },
83 { "size", SIZE },
84 { "slave", SLAVE },
85 { "sourcedir", SOURCEDIR },
86 { "swap", SWAP },
87 { "tape", DEVICE },
88 { "trace", TRACE },
89 { "uba", UBA },
90 { "vector", VECTOR },
91 { "lun", LUN }, /* MMAX only */
92 { "slot", SLOT }, /* MMAX only */
93 { "tape", TAPE }, /* MMAX only */
94 { "bin", BIN }, /* SQT ONLY */
95 { "am", ADDRMOD }, /* MIPS */
96 { "mbii", MBII }, /* MIPS */
97 { "vme", VME }, /* MIPS */
98 { 0, 0 },
99};
100%}
101
102%option nounput
103
104WORD ([A-Za-z_][-A-Za-z_]*|[A-Z][-A-Za-z_0-9]*)
105WORD1 ([A-Za-z_][-A-Za-z_0-9]*)
106%%
107{WORD} |
108{WORD1} {
109 int i;
110
111 if ((i = kw_lookup(yytext)) == -1)
112 {
113 yylval.str = yytext;
114 tprintf("id(%s) ", yytext);
115 return ID;
116 }
117 tprintf("(%s) ", yytext);
118 return i;
119 }
120\"[^"]+\" {
121 yytext[strlen(yytext)-1] = '\0';
122 yylval.str = yytext + 1;
123 return ID;
124 }
1250[0-7]* {
126 yylval.val = octal(yytext);
127 tprintf("#O:%o ", yylval.val);
128 return NUMBER;
129 }
1300x[0-9a-fA-F]+ {
131 yylval.val = hex(yytext);
132 tprintf("#X:%x ", yylval.val);
133 return NUMBER;
134 }
135[1-9][0-9]* {
136 yylval.val = atoi(yytext);
137 tprintf("#D:%d ", yylval.val);
138 return NUMBER;
139 }
140[0-9]"."[0-9]* {
141 yylval.val = (int) (60 * atof(yytext) + 0.5);
142 return FPNUMBER;
143 }
144"-" {
145 return MINUS;
146 }
147"?" {
148 yylval.val = -1;
149 tprintf("? ");
150 return NUMBER;
151 }
152\n/[ \t] {
153 yyline++;
154 tprintf("\n... ");
155 }
156\n {
157 yyline++;
158 tprintf("\n");
159 return SEMICOLON;
160 }
161#.* { /* Ignored (comment) */; }
162[ \t]* { /* Ignored (white space) */; }
163";" { return SEMICOLON; }
164"," { return COMMA; }
165"=" { return EQUALS; }
166"@" { return AT; }
167. { return yytext[0]; }
168
169
170%%
171/*
172 * kw_lookup
173 * Look up a string in the keyword table. Returns a -1 if the
174 * string is not a keyword otherwise it returns the keyword number
175 */
176
177int
178kw_lookup(char *word)
179{
180 register struct kt *kp;
181
182 for (kp = key_words; kp->kt_name != 0; kp++)
183 if (eq(word, kp->kt_name))
184 return kp->kt_val;
185 return -1;
186}
187
188/*
189 * Number conversion routines
190 */
191
192int
193octal(char *str)
194{
195 int num;
196
197 (void) sscanf(str, "%o", &num);
198 return num;
199}
200
201int
202hex(char *str)
203{
204 int num;
205
206 (void) sscanf(str+2, "%x", &num);
207 return num;
208}
209
210int
211yywrap()
212{
213 return 1;
214}