1 #ifndef lint
2 static char sccsid[] = "@(#)lookup.c 2.2 (CWI) 87/04/01";
3 #endif lint
4 # include "e.h"
5 #include "y.tab.h"
6
7 #define TBLSIZE 100
8
9 tbl *keytbl[TBLSIZE]; /* key words */
10 tbl *restbl[TBLSIZE]; /* reserved words */
11 tbl *deftbl[TBLSIZE]; /* user-defined names */
12
13 struct {
14 char *key;
15 int keyval;
16 } keyword[] ={
17 "sub", SUB,
18 "sup", SUP,
19 ".EN", DOTEN,
20 ".EQ", DOTEQ,
21 "from", FROM,
22 "to", TO,
23 "sum", SUM,
24 "hat", HAT,
25 "vec", VEC,
26 "dyad", DYAD,
27 "dot", DOT,
28 "dotdot", DOTDOT,
29 "bar", BAR,
30 "lowbar", LOWBAR,
31 "highbar", HIGHBAR,
32 "tilde", TILDE,
33 "utilde", UTILDE,
34 "under", UNDER,
35 "prod", PROD,
36 "int", INT,
37 "integral", INT,
38 "union", UNION,
39 "inter", INTER,
40 "matrix", MATRIX,
41 "col", COL,
42 "lcol", LCOL,
43 "ccol", CCOL,
44 "rcol", RCOL,
45 "pile", COL, /* synonyms ... */
46 "lpile", LCOL,
47 "cpile", CCOL,
48 "rpile", RCOL,
49 "over", OVER,
50 "sqrt", SQRT,
51 "above", ABOVE,
52 "size", SIZE,
53 "font", FONT,
54 "fat", FAT,
55 "roman", ROMAN,
56 "italic", ITALIC,
57 "bold", BOLD,
58 "left", LEFT,
59 "right", RIGHT,
60 "delim", DELIM,
61 "define", DEFINE,
62
63 #ifdef NEQN /* make ndefine synonym for define, tdefine a no-op */
64
65 "tdefine", TDEFINE,
66 "ndefine", DEFINE,
67
68 #else /* tdefine = define, ndefine = no-op */
69
70 "tdefine", DEFINE,
71 "ndefine", NDEFINE,
72
73 #endif
74
75 "ifdef", IFDEF,
76 "gsize", GSIZE,
77 ".gsize", GSIZE,
78 "gfont", GFONT,
79 "include", INCLUDE,
80 "copy", INCLUDE,
81 "space", SPACE,
82 "up", UP,
83 "down", DOWN,
84 "fwd", FWD,
85 "back", BACK,
86 "mark", MARK,
87 "lineup", LINEUP,
88 0, 0
89 };
90
91 struct {
92 char *res;
93 char *resval;
94 } resword[] ={
95 ">=", "\\(>=",
96 "<=", "\\(<=",
97 "==", "\\(==",
98 "!=", "\\(!=",
99 "+-", "\\(+-",
100 "->", "\\(->",
101 "<-", "\\(<-",
102 "inf", "\\(if",
103 "infinity", "\\(if",
104 "partial", "\\(pd",
105 "half", "\\f1\\(12\\fP",
106 "prime", "\\f1\\(fm\\fP",
107 "dollar", "\\f1$\\fP",
108 "nothing", "",
109 "times", "\\(mu",
110 "del", "\\(gr",
111 "grad", "\\(gr",
112
113 #ifdef NEQN
114 "<<", "<<",
115 ">>", ">>",
116 "approx", "~\b\\d~\\u",
117 "cdot", "\\v'-.5'.\\v'.5'",
118 "...", "...",
119 ",...,", ",...,",
120 #else
121 "<<", "<\\h'-.3m'<",
122 ">>", ">\\h'-.3m'>",
123 "approx", "\\v'-.2m'\\z\\(ap\\v'.25m'\\(ap\\v'-.05m'",
124 "cdot", "\\v'-.3m'.\\v'.3m'",
125 "...", "\\v'-.3m'\\ .\\ .\\ .\\ \\v'.3m'",
126 ",...,", "\\f1,\\fP\\ .\\ .\\ .\\ \\f1,\\fP\\|",
127 #endif
128
129 "alpha", "\\(*a",
130 "beta", "\\(*b",
131 "gamma", "\\(*g",
132 "GAMMA", "\\(*G",
133 "delta", "\\(*d",
134 "DELTA", "\\(*D",
135 "epsilon", "\\(*e",
136 "EPSILON", "\\f1E\\fP",
137 "omega", "\\(*w",
138 "OMEGA", "\\(*W",
139 "lambda", "\\(*l",
140 "LAMBDA", "\\(*L",
141 "mu", "\\(*m",
142 "nu", "\\(*n",
143 "theta", "\\(*h",
144 "THETA", "\\(*H",
145 "phi", "\\(*f",
146 "PHI", "\\(*F",
147 "pi", "\\(*p",
148 "PI", "\\(*P",
149 "sigma", "\\(*s",
150 "SIGMA", "\\(*S",
151 "xi", "\\(*c",
152 "XI", "\\(*C",
153 "zeta", "\\(*z",
154 "iota", "\\(*i",
155 "eta", "\\(*y",
156 "kappa", "\\(*k",
157 "rho", "\\(*r",
158 "tau", "\\(*t",
159 "omicron", "\\(*o",
160 "upsilon", "\\(*u",
161 "UPSILON", "\\(*U",
162 "psi", "\\(*q",
163 "PSI", "\\(*Q",
164 "chi", "\\(*x",
165 "and", "\\f1and\\fP",
166 "for", "\\f1for\\fP",
167 "if", "\\f1if\\fP",
168 "Re", "\\f1Re\\fP",
169 "Im", "\\f1Im\\fP",
170 "sin", "\\f1sin\\fP",
171 "cos", "\\f1cos\\fP",
172 "tan", "\\f1tan\\fP",
173 "arc", "\\f1arc\\fP",
174 "sinh", "\\f1sinh\\fP",
175 "coth", "\\f1coth\\fP",
176 "tanh", "\\f1tanh\\fP",
177 "cosh", "\\f1cosh\\fP",
178 "lim", "\\f1lim\\fP",
179 "log", "\\f1log\\fP",
180 "max", "\\f1max\\fP",
181 "min", "\\f1min\\fP",
182 "ln", "\\f1ln\\fP",
183 "exp", "\\f1exp\\fP",
184 "det", "\\f1det\\fP",
185 0, 0
186 };
187
lookup(tblp,name,defn)188 tbl *lookup(tblp, name, defn) /* find name in tbl. if defn non-null, install */
189 tbl **tblp;
190 char *name, *defn;
191 {
192 register tbl *p;
193 register int h;
194 register char *s = name;
195
196 for (h = 0; *s != '\0'; )
197 h += *s++;
198 h %= TBLSIZE;
199
200 for (p = tblp[h]; p != NULL; p = p->next)
201 if (strcmp(name, p->name) == 0) { /* found it */
202 if (defn != NULL)
203 p->defn = defn;
204 return(p);
205 }
206 /* didn't find it */
207 if (defn == NULL)
208 return(NULL);
209 p = (tbl *) malloc(sizeof (tbl));
210 if (p == NULL)
211 error(FATAL, "out of space in lookup");
212 p->name = name;
213 p->defn = defn;
214 p->next = tblp[h];
215 tblp[h] = p;
216 return(p);
217 }
218
init_tbl()219 init_tbl() /* initialize all tables */
220 {
221 int i;
222
223 for (i = 0; keyword[i].key != NULL; i++)
224 lookup(keytbl, keyword[i].key, keyword[i].keyval);
225 for (i = 0; resword[i].res != NULL; i++)
226 lookup(restbl, resword[i].res, resword[i].resval);
227 }
228