Commit | Line | Data |
---|---|---|
bc2ed385 | 1 | %{ |
cd68466f DF |
2 | |
3 | /* | |
4 | * Copyright (c) 1980 Regents of the University of California. | |
67259f7b | 5 | * All rights reserved. |
cd68466f | 6 | * |
67259f7b | 7 | * Redistribution and use in source and binary forms are permitted |
b8c620d6 KB |
8 | * provided that the above copyright notice and this paragraph are |
9 | * duplicated in all such forms and that any documentation, | |
10 | * advertising materials, and other materials related to such | |
11 | * distribution and use acknowledge that the software was developed | |
12 | * by the University of California, Berkeley. The name of the | |
13 | * University may not be used to endorse or promote products derived | |
14 | * from this software without specific prior written permission. | |
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
16 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
17 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
67259f7b | 18 | * |
b8c620d6 | 19 | * @(#)lang.l 5.5 (Berkeley) %G% |
cd68466f | 20 | */ |
bc2ed385 MT |
21 | |
22 | #include <ctype.h> | |
23 | #include "y.tab.h" | |
24 | #include "config.h" | |
25 | ||
26 | #define tprintf if (do_trace) printf | |
b3043913 | 27 | |
bc2ed385 MT |
28 | /* |
29 | * Key word table | |
30 | */ | |
31 | ||
32 | struct kt { | |
33 | char *kt_name; | |
34 | int kt_val; | |
35 | } key_words[] = { | |
36edb824 SL |
36 | { "and", AND }, |
37 | { "args", ARGS }, | |
38 | { "at", AT }, | |
39 | { "config", CONFIG }, | |
40 | { "controller", CONTROLLER }, | |
41 | { "cpu", CPU }, | |
42 | { "csr", CSR }, | |
43 | { "device", DEVICE }, | |
44 | { "disk", DISK }, | |
45 | { "drive", DRIVE }, | |
46 | { "dst", DST }, | |
47 | { "dumps", DUMPS }, | |
48 | { "flags", FLAGS }, | |
49 | { "hz", HZ }, | |
50 | { "ident", IDENT }, | |
51 | { "machine", MACHINE }, | |
52 | { "major", MAJOR }, | |
7c1d4665 | 53 | { "makeoptions", MAKEOPTIONS }, |
36edb824 SL |
54 | { "master", MASTER }, |
55 | { "maxusers", MAXUSERS }, | |
36edb824 SL |
56 | { "minor", MINOR }, |
57 | { "nexus", NEXUS }, | |
58 | { "on", ON }, | |
59 | { "options", OPTIONS }, | |
60 | { "priority", PRIORITY }, | |
61 | { "pseudo-device",PSEUDO_DEVICE }, | |
62 | { "root", ROOT }, | |
63 | { "size", SIZE }, | |
64 | { "slave", SLAVE }, | |
65 | { "swap", SWAP }, | |
66 | { "tape", DEVICE }, | |
67 | { "timezone", TIMEZONE }, | |
68 | { "trace", TRACE }, | |
36edb824 SL |
69 | { "vector", VECTOR }, |
70 | { 0, 0 }, | |
bc2ed385 MT |
71 | }; |
72 | %} | |
b3043913 | 73 | WORD [A-Za-z_][-A-Za-z_]* |
bc2ed385 MT |
74 | %% |
75 | {WORD} { | |
76 | int i; | |
77 | ||
78 | if ((i = kw_lookup(yytext)) == -1) | |
79 | { | |
22d68ad0 | 80 | yylval.str = yytext; |
bc2ed385 MT |
81 | tprintf("id(%s) ", yytext); |
82 | return ID; | |
83 | } | |
84 | tprintf("(%s) ", yytext); | |
85 | return i; | |
86 | } | |
dea0cacc MT |
87 | \"[^"]+\" { |
88 | yytext[strlen(yytext)-1] = '\0'; | |
36edb824 | 89 | yylval.str = yytext + 1; |
dea0cacc MT |
90 | return ID; |
91 | } | |
bc2ed385 | 92 | 0[0-7]* { |
22d68ad0 BJ |
93 | yylval.val = octal(yytext); |
94 | tprintf("#O:%o ", yylval.val); | |
bc2ed385 MT |
95 | return NUMBER; |
96 | } | |
4cab9f3e | 97 | 0x[0-9a-fA-F]+ { |
22d68ad0 BJ |
98 | yylval.val = hex(yytext); |
99 | tprintf("#X:%x ", yylval.val); | |
bc2ed385 MT |
100 | return NUMBER; |
101 | } | |
102 | [1-9][0-9]* { | |
22d68ad0 BJ |
103 | yylval.val = atoi(yytext); |
104 | tprintf("#D:%d ", yylval.val); | |
bc2ed385 MT |
105 | return NUMBER; |
106 | } | |
a5e18d6b | 107 | [0-9]"."[0-9]* { |
22d68ad0 BJ |
108 | double atof(); |
109 | yylval.val = (int) (60 * atof(yytext) + 0.5); | |
a5e18d6b MT |
110 | return FPNUMBER; |
111 | } | |
57b7808b BJ |
112 | "-" { |
113 | return MINUS; | |
114 | } | |
bc2ed385 | 115 | "?" { |
22d68ad0 | 116 | yylval.val = -1; |
bc2ed385 MT |
117 | tprintf("? "); |
118 | return NUMBER; | |
119 | } | |
120 | \n/[ \t] { | |
121 | yyline++; | |
122 | tprintf("\n... "); | |
123 | } | |
124 | \n { | |
125 | yyline++; | |
126 | tprintf("\n"); | |
127 | return SEMICOLON; | |
128 | } | |
45a827f6 | 129 | #.* { /* Ignored (comment) */; } |
bc2ed385 MT |
130 | [ \t]* { /* Ignored (white space) */; } |
131 | ";" { return SEMICOLON; } | |
9c98d1fb | 132 | "," { return COMMA; } |
45a827f6 | 133 | "=" { return EQUALS; } |
0bf41cfc | 134 | "@" { return AT; } |
45a827f6 RE |
135 | . { return yytext[0]; } |
136 | ||
bc2ed385 MT |
137 | %% |
138 | /* | |
139 | * kw_lookup | |
140 | * Look up a string in the keyword table. Returns a -1 if the | |
141 | * string is not a keyword otherwise it returns the keyword number | |
142 | */ | |
143 | ||
144 | kw_lookup(word) | |
145 | register char *word; | |
146 | { | |
147 | register struct kt *kp; | |
148 | ||
149 | for (kp = key_words; kp->kt_name != 0; kp++) | |
150 | if (eq(word, kp->kt_name)) | |
151 | return kp->kt_val; | |
152 | return -1; | |
153 | } | |
154 | ||
155 | /* | |
156 | * Number conversion routines | |
157 | */ | |
158 | ||
159 | octal(str) | |
160 | char *str; | |
161 | { | |
162 | int num; | |
163 | ||
22d68ad0 | 164 | (void) sscanf(str, "%o", &num); |
bc2ed385 MT |
165 | return num; |
166 | } | |
167 | ||
168 | hex(str) | |
169 | char *str; | |
170 | { | |
171 | int num; | |
172 | ||
22d68ad0 | 173 | (void) sscanf(str+2, "%x", &num); |
bc2ed385 MT |
174 | return num; |
175 | } |