Commit | Line | Data |
---|---|---|
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 | * | |
8 | * @(#)lang.l 5.1 (Berkeley) %G% | |
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 | ||
21 | struct 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 }, | |
42 | { "master", MASTER }, | |
43 | { "maxusers", MAXUSERS }, | |
44 | { "mba", MBA }, | |
45 | { "minor", MINOR }, | |
46 | { "nexus", NEXUS }, | |
47 | { "on", ON }, | |
48 | { "options", OPTIONS }, | |
49 | { "priority", PRIORITY }, | |
50 | { "pseudo-device",PSEUDO_DEVICE }, | |
51 | { "root", ROOT }, | |
52 | { "size", SIZE }, | |
53 | { "slave", SLAVE }, | |
54 | { "swap", SWAP }, | |
55 | { "tape", DEVICE }, | |
56 | { "timezone", TIMEZONE }, | |
57 | { "trace", TRACE }, | |
58 | { "uba", UBA }, | |
59 | { "vector", VECTOR }, | |
60 | { 0, 0 }, | |
bc2ed385 MT |
61 | }; |
62 | %} | |
b3043913 | 63 | WORD [A-Za-z_][-A-Za-z_]* |
bc2ed385 MT |
64 | %% |
65 | {WORD} { | |
66 | int i; | |
67 | ||
68 | if ((i = kw_lookup(yytext)) == -1) | |
69 | { | |
22d68ad0 | 70 | yylval.str = yytext; |
bc2ed385 MT |
71 | tprintf("id(%s) ", yytext); |
72 | return ID; | |
73 | } | |
74 | tprintf("(%s) ", yytext); | |
75 | return i; | |
76 | } | |
dea0cacc MT |
77 | \"[^"]+\" { |
78 | yytext[strlen(yytext)-1] = '\0'; | |
36edb824 | 79 | yylval.str = yytext + 1; |
dea0cacc MT |
80 | return ID; |
81 | } | |
bc2ed385 | 82 | 0[0-7]* { |
22d68ad0 BJ |
83 | yylval.val = octal(yytext); |
84 | tprintf("#O:%o ", yylval.val); | |
bc2ed385 MT |
85 | return NUMBER; |
86 | } | |
4cab9f3e | 87 | 0x[0-9a-fA-F]+ { |
22d68ad0 BJ |
88 | yylval.val = hex(yytext); |
89 | tprintf("#X:%x ", yylval.val); | |
bc2ed385 MT |
90 | return NUMBER; |
91 | } | |
92 | [1-9][0-9]* { | |
22d68ad0 BJ |
93 | yylval.val = atoi(yytext); |
94 | tprintf("#D:%d ", yylval.val); | |
bc2ed385 MT |
95 | return NUMBER; |
96 | } | |
a5e18d6b | 97 | [0-9]"."[0-9]* { |
22d68ad0 BJ |
98 | double atof(); |
99 | yylval.val = (int) (60 * atof(yytext) + 0.5); | |
a5e18d6b MT |
100 | return FPNUMBER; |
101 | } | |
57b7808b BJ |
102 | "-" { |
103 | return MINUS; | |
104 | } | |
bc2ed385 | 105 | "?" { |
22d68ad0 | 106 | yylval.val = -1; |
bc2ed385 MT |
107 | tprintf("? "); |
108 | return NUMBER; | |
109 | } | |
110 | \n/[ \t] { | |
111 | yyline++; | |
112 | tprintf("\n... "); | |
113 | } | |
114 | \n { | |
115 | yyline++; | |
116 | tprintf("\n"); | |
117 | return SEMICOLON; | |
118 | } | |
45a827f6 | 119 | #.* { /* Ignored (comment) */; } |
bc2ed385 MT |
120 | [ \t]* { /* Ignored (white space) */; } |
121 | ";" { return SEMICOLON; } | |
9c98d1fb | 122 | "," { return COMMA; } |
45a827f6 | 123 | "=" { return EQUALS; } |
0bf41cfc | 124 | "@" { return AT; } |
45a827f6 RE |
125 | . { return yytext[0]; } |
126 | ||
bc2ed385 MT |
127 | %% |
128 | /* | |
129 | * kw_lookup | |
130 | * Look up a string in the keyword table. Returns a -1 if the | |
131 | * string is not a keyword otherwise it returns the keyword number | |
132 | */ | |
133 | ||
134 | kw_lookup(word) | |
135 | register char *word; | |
136 | { | |
137 | register struct kt *kp; | |
138 | ||
139 | for (kp = key_words; kp->kt_name != 0; kp++) | |
140 | if (eq(word, kp->kt_name)) | |
141 | return kp->kt_val; | |
142 | return -1; | |
143 | } | |
144 | ||
145 | /* | |
146 | * Number conversion routines | |
147 | */ | |
148 | ||
149 | octal(str) | |
150 | char *str; | |
151 | { | |
152 | int num; | |
153 | ||
22d68ad0 | 154 | (void) sscanf(str, "%o", &num); |
bc2ed385 MT |
155 | return num; |
156 | } | |
157 | ||
158 | hex(str) | |
159 | char *str; | |
160 | { | |
161 | int num; | |
162 | ||
22d68ad0 | 163 | (void) sscanf(str+2, "%x", &num); |
bc2ed385 MT |
164 | return num; |
165 | } |