4.3BSD beta release document
[unix-history] / usr / src / usr.sbin / config / lang.l
CommitLineData
bc2ed385 1%{
cd68466f
DF
2
3/*
4 * Copyright (c) 1980 Regents of the University of California.
5 * All rights reserved. The Berkeley software License Agreement
6 * specifies the terms and conditions for redistribution.
7 *
7c1d4665 8 * @(#)lang.l 5.2 (Berkeley) %G%
cd68466f 9 */
bc2ed385
MT
10
11#include <ctype.h>
12#include "y.tab.h"
13#include "config.h"
14
15#define tprintf if (do_trace) printf
b3043913 16
bc2ed385
MT
17/*
18 * Key word table
19 */
20
21struct kt {
22 char *kt_name;
23 int kt_val;
24} key_words[] = {
36edb824
SL
25 { "and", AND },
26 { "args", ARGS },
27 { "at", AT },
28 { "config", CONFIG },
29 { "controller", CONTROLLER },
30 { "cpu", CPU },
31 { "csr", CSR },
32 { "device", DEVICE },
33 { "disk", DISK },
34 { "drive", DRIVE },
35 { "dst", DST },
36 { "dumps", DUMPS },
37 { "flags", FLAGS },
38 { "hz", HZ },
39 { "ident", IDENT },
40 { "machine", MACHINE },
41 { "major", MAJOR },
7c1d4665 42 { "makeoptions", MAKEOPTIONS },
36edb824
SL
43 { "master", MASTER },
44 { "maxusers", MAXUSERS },
45 { "mba", MBA },
46 { "minor", MINOR },
47 { "nexus", NEXUS },
48 { "on", ON },
49 { "options", OPTIONS },
50 { "priority", PRIORITY },
51 { "pseudo-device",PSEUDO_DEVICE },
52 { "root", ROOT },
53 { "size", SIZE },
54 { "slave", SLAVE },
55 { "swap", SWAP },
56 { "tape", DEVICE },
57 { "timezone", TIMEZONE },
58 { "trace", TRACE },
59 { "uba", UBA },
60 { "vector", VECTOR },
61 { 0, 0 },
bc2ed385
MT
62};
63%}
b3043913 64WORD [A-Za-z_][-A-Za-z_]*
bc2ed385
MT
65%%
66{WORD} {
67 int i;
68
69 if ((i = kw_lookup(yytext)) == -1)
70 {
22d68ad0 71 yylval.str = yytext;
bc2ed385
MT
72 tprintf("id(%s) ", yytext);
73 return ID;
74 }
75 tprintf("(%s) ", yytext);
76 return i;
77 }
dea0cacc
MT
78\"[^"]+\" {
79 yytext[strlen(yytext)-1] = '\0';
36edb824 80 yylval.str = yytext + 1;
dea0cacc
MT
81 return ID;
82 }
bc2ed385 830[0-7]* {
22d68ad0
BJ
84 yylval.val = octal(yytext);
85 tprintf("#O:%o ", yylval.val);
bc2ed385
MT
86 return NUMBER;
87 }
4cab9f3e 880x[0-9a-fA-F]+ {
22d68ad0
BJ
89 yylval.val = hex(yytext);
90 tprintf("#X:%x ", yylval.val);
bc2ed385
MT
91 return NUMBER;
92 }
93[1-9][0-9]* {
22d68ad0
BJ
94 yylval.val = atoi(yytext);
95 tprintf("#D:%d ", yylval.val);
bc2ed385
MT
96 return NUMBER;
97 }
a5e18d6b 98[0-9]"."[0-9]* {
22d68ad0
BJ
99 double atof();
100 yylval.val = (int) (60 * atof(yytext) + 0.5);
a5e18d6b
MT
101 return FPNUMBER;
102 }
57b7808b
BJ
103"-" {
104 return MINUS;
105 }
bc2ed385 106"?" {
22d68ad0 107 yylval.val = -1;
bc2ed385
MT
108 tprintf("? ");
109 return NUMBER;
110 }
111\n/[ \t] {
112 yyline++;
113 tprintf("\n... ");
114 }
115\n {
116 yyline++;
117 tprintf("\n");
118 return SEMICOLON;
119 }
45a827f6 120#.* { /* Ignored (comment) */; }
bc2ed385
MT
121[ \t]* { /* Ignored (white space) */; }
122";" { return SEMICOLON; }
9c98d1fb 123"," { return COMMA; }
45a827f6 124"=" { return EQUALS; }
0bf41cfc 125"@" { return AT; }
45a827f6
RE
126. { return yytext[0]; }
127
bc2ed385
MT
128%%
129/*
130 * kw_lookup
131 * Look up a string in the keyword table. Returns a -1 if the
132 * string is not a keyword otherwise it returns the keyword number
133 */
134
135kw_lookup(word)
136register char *word;
137{
138 register struct kt *kp;
139
140 for (kp = key_words; kp->kt_name != 0; kp++)
141 if (eq(word, kp->kt_name))
142 return kp->kt_val;
143 return -1;
144}
145
146/*
147 * Number conversion routines
148 */
149
150octal(str)
151char *str;
152{
153 int num;
154
22d68ad0 155 (void) sscanf(str, "%o", &num);
bc2ed385
MT
156 return num;
157}
158
159hex(str)
160char *str;
161{
162 int num;
163
22d68ad0 164 (void) sscanf(str+2, "%x", &num);
bc2ed385
MT
165 return num;
166}