allow comments other than at start of line;
[unix-history] / usr / src / usr.sbin / config / lang.l
CommitLineData
bc2ed385 1%{
45a827f6 2/* lang.l 1.9 82/07/21 */
bc2ed385
MT
3
4#include <ctype.h>
5#include "y.tab.h"
6#include "config.h"
7
8#define tprintf if (do_trace) printf
b3043913
MT
9
10int yylval;
11
bc2ed385
MT
12/*
13 * Key word table
14 */
15
16struct kt {
17 char *kt_name;
18 int kt_val;
19} key_words[] = {
20 "cpu", CPU, "ident", IDENT, "config", CONFIG, "options", OPTIONS,
21 "device", DEVICE, "controller", CONTROLLER, "uba", UBA, "mba", MBA,
22 "csr", CSR, "nexus", NEXUS, "drive", DRIVE, "vector", VECTOR,
23 "pseudo-device", PSEUDO_DEVICE, "flags", FLAGS, "trace", TRACE,
5ff81582 24 "disk", DISK, "tape", DEVICE, "slave", SLAVE, "at", AT,
a5e18d6b 25 "hz", HZ, "timezone", TIMEZONE, "dst", DST, "maxusers", MAXUSERS,
9c98d1fb 26 "master", MASTER,
bc2ed385
MT
27 0,0,
28};
29%}
b3043913 30WORD [A-Za-z_][-A-Za-z_]*
bc2ed385
MT
31%%
32{WORD} {
33 int i;
34
35 if ((i = kw_lookup(yytext)) == -1)
36 {
37 yylval = (int) yytext;
38 tprintf("id(%s) ", yytext);
39 return ID;
40 }
41 tprintf("(%s) ", yytext);
42 return i;
43 }
dea0cacc
MT
44\"[^"]+\" {
45 yytext[strlen(yytext)-1] = '\0';
46 yylval = (int) yytext + 1;
47 return ID;
48 }
bc2ed385
MT
490[0-7]* {
50 yylval = octal(yytext);
51 tprintf("#O:%o ", yylval);
52 return NUMBER;
53 }
540x[0-9a-f]+ {
55 yylval = hex(yytext);
56 tprintf("#X:%x ", yylval);
57 return NUMBER;
58 }
59[1-9][0-9]* {
60 yylval = atoi(yytext);
61 tprintf("#D:%d ", yylval);
62 return NUMBER;
63 }
a5e18d6b
MT
64[0-9]"."[0-9]* {
65 float atof();
66 yylval = (int) (60 * atof(yytext) + 0.5);
67 return FPNUMBER;
68 }
57b7808b
BJ
69"-" {
70 return MINUS;
71 }
bc2ed385
MT
72"?" {
73 yylval = -1;
74 tprintf("? ");
75 return NUMBER;
76 }
77\n/[ \t] {
78 yyline++;
79 tprintf("\n... ");
80 }
81\n {
82 yyline++;
83 tprintf("\n");
84 return SEMICOLON;
85 }
45a827f6 86#.* { /* Ignored (comment) */; }
bc2ed385
MT
87[ \t]* { /* Ignored (white space) */; }
88";" { return SEMICOLON; }
9c98d1fb 89"," { return COMMA; }
45a827f6
RE
90"=" { return EQUALS; }
91"@" { return AT; }
92. { return yytext[0]; }
93
bc2ed385
MT
94%%
95/*
96 * kw_lookup
97 * Look up a string in the keyword table. Returns a -1 if the
98 * string is not a keyword otherwise it returns the keyword number
99 */
100
101kw_lookup(word)
102register char *word;
103{
104 register struct kt *kp;
105
106 for (kp = key_words; kp->kt_name != 0; kp++)
107 if (eq(word, kp->kt_name))
108 return kp->kt_val;
109 return -1;
110}
111
112/*
113 * Number conversion routines
114 */
115
116octal(str)
117char *str;
118{
119 int num;
120
121 sscanf(str, "%o", &num);
122 return num;
123}
124
125hex(str)
126char *str;
127{
128 int num;
129
cc03da8f 130 sscanf(str+2, "%x", &num);
bc2ed385
MT
131 return num;
132}