Commit | Line | Data |
---|---|---|
bc2ed385 | 1 | %{ |
57b7808b | 2 | /* lang.l 1.8 81/05/18 */ |
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 | |
10 | int yylval; | |
11 | ||
bc2ed385 MT |
12 | /* |
13 | * Key word table | |
14 | */ | |
15 | ||
16 | struct 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 | 30 | WORD [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 |
49 | 0[0-7]* { |
50 | yylval = octal(yytext); | |
51 | tprintf("#O:%o ", yylval); | |
52 | return NUMBER; | |
53 | } | |
54 | 0x[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 | } | |
86 | ^#.* { /* Ignored (comment) */; } | |
87 | [ \t]* { /* Ignored (white space) */; } | |
88 | ";" { return SEMICOLON; } | |
9c98d1fb | 89 | "," { return COMMA; } |
bc2ed385 MT |
90 | %% |
91 | /* | |
92 | * kw_lookup | |
93 | * Look up a string in the keyword table. Returns a -1 if the | |
94 | * string is not a keyword otherwise it returns the keyword number | |
95 | */ | |
96 | ||
97 | kw_lookup(word) | |
98 | register char *word; | |
99 | { | |
100 | register struct kt *kp; | |
101 | ||
102 | for (kp = key_words; kp->kt_name != 0; kp++) | |
103 | if (eq(word, kp->kt_name)) | |
104 | return kp->kt_val; | |
105 | return -1; | |
106 | } | |
107 | ||
108 | /* | |
109 | * Number conversion routines | |
110 | */ | |
111 | ||
112 | octal(str) | |
113 | char *str; | |
114 | { | |
115 | int num; | |
116 | ||
117 | sscanf(str, "%o", &num); | |
118 | return num; | |
119 | } | |
120 | ||
121 | hex(str) | |
122 | char *str; | |
123 | { | |
124 | int num; | |
125 | ||
cc03da8f | 126 | sscanf(str+2, "%x", &num); |
bc2ed385 MT |
127 | return num; |
128 | } |