-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.c
303 lines (274 loc) · 7.4 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
* ScottCom -- Compiles adventures into the Scott Adams format.
* Copyright (C) 1985-1996 Bjorn Gustavsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: init.c,v 1.2 1996/10/17 04:04:05 bjorn Exp bjorn $
*
*/
#include "scottcom.h"
#include "parser.h"
extern Symbol* main_table;
extern Symbol* verb_table;
extern Symbol* noun_table;
extern Symbol* label_table;
static Keyword actions[] = {
/*
* Conditions. The value is code for the TI-99 format, and it will
* be translated before being inserted into the symbol table.
*/
{"has", TESTOBJ, (OP_BASE+0xb7)},
{"here", TESTOBJ, (OP_BASE+0xb8)},
{"avail", TESTOBJ, (OP_BASE+0xb9)},
{"!here", TESTOBJ, (OP_BASE+0xba)},
{"!has", TESTOBJ, (OP_BASE+0xbb)},
{"!avail", TESTOBJ, (OP_BASE+0xbc)},
{"exists", TESTOBJ, (OP_BASE+0xbd)},
{"!exists", TESTOBJ, (OP_BASE+0xbe)},
{"in", TESTROOM, (OP_BASE+0xbf)},
{"!in", TESTROOM, (OP_BASE+0xc0)},
{"set", TESTFLAG, (OP_BASE+0xc1)},
{"!set", TESTFLAG, (OP_BASE+0xc2)},
{"something",PARAMLESS, (OP_BASE+0xc3)},
{"nothing", PARAMLESS, (OP_BASE+0xc4)},
{"le", TESTNUM, (OP_BASE+0xc5)},
{"gt", TESTNUM, (OP_BASE+0xc6)},
{"eq", TESTNUM, (OP_BASE+0xc7)},
{"!moved", TESTOBJ, (OP_BASE+0xc8)},
{"moved", TESTOBJ, (OP_BASE+0xc9)},
/*
* Operations, with values for the TI-99 format.
*/
{"cls", PARAMLESS, OP_CLS},
{"pic", ACTNUM, OP_SHOW_PIC},
{"inv", PARAMLESS, (OP_BASE+0xd6)},
{"!inv", PARAMLESS, (OP_BASE+0xd7)},
{"ignore", PARAMLESS, (OP_BASE+0xd8)},
{"success", PARAMLESS, (OP_BASE+0xd9)},
{"try", IF, (OP_BASE+0xda)},
{"get", ACTOBJ, (OP_BASE+0xdb)},
{"drop", ACTOBJ, (OP_BASE+0xdc)},
{"goto", ACTROOM, (OP_BASE+0xdd)},
{"zap", ACTOBJ, (OP_BASE+0xde)},
{"die", PARAMLESS, (OP_BASE+0xe5)},
{"move", ACTROOMOBJ, (OP_BASE+0xe6)},
{"quit", PARAMLESS, (OP_BASE+0xe7)},
{".score", PARAMLESS, (OP_BASE+0xe8)},
{".inv", PARAMLESS, (OP_BASE+0xe9)},
{"refill", PARAMLESS, (OP_BASE+0xea)},
{"save", PARAMLESS, (OP_BASE+0xeb)},
{"steal", ACTOBJ, (OP_BASE+0xed)},
{"same", ACTOBJOBJ, (OP_BASE+0xee)},
{"nop", PARAMLESS, (OP_BASE+0xef)},
{".room", PARAMLESS, (OP_BASE+0xf0)},
{".timer", PARAMLESS, (OP_BASE+0xf4)},
{"timer", ACTNUM, (OP_BASE+0xf5)},
{".noun", PARAMLESS, (OP_BASE+0xfb)},
{".noun_nl", PARAMLESS, (OP_BASE+0xfc)},
{".nl", PARAMLESS, (OP_BASE+0xfd)},
{"delay", PARAMLESS, (OP_BASE+0xfe)},
{"end", PARAMLESS, (OP_BASE+0xFF)},
};
/*
* This table contains keywords which are format-independent.
*/
static Keyword keywords[] = {
{"on", ACTFLAG, 0},
{"off", ACTFLAG, 1},
{"add", TIMER, 0},
{"sub", TIMER, 1},
/*
* Keywords for generic operations. The value is not used.
*/
{"swap", SWAP, 0},
/*
* Keywords. The value is not used.
*/
{"noun", KW_NOUN, 0},
{"verb", KW_VERB, 0},
{"item", KW_OBJECT, 0},
{"room", KW_ROOM, 0},
{"act", KW_ACTION, 0},
{"alias", KW_MESSAGE, 0},
{"flag", KW_FLAG, 0},
{"timreg", KW_TIMREG, 0},
{"roomreg", KW_ROOMREG, 0},
/*
* All directions. The value is used to index into the room
* index table.
*/
{"n_to", DIRECT, 0},
{"s_to", DIRECT, 1},
{"e_to", DIRECT, 2},
{"w_to", DIRECT, 3},
{"u_to", DIRECT, 4},
{"d_to", DIRECT, 5},
/* player, void and any */
{"void", VOID, 0},
{"limbo", VOID, 0},
{"player", PLAYER, 0},
/* parameters */
{"initial", PARSTART, 0},
{"treasure", PARTREASURE, 0},
{"light_time", PARLIGHT, 0},
{"max_load", PARCARRY, 0},
{"word_length", PARABBREV, 0},
{"title_screen", PARTITLE, 0},
{"rm_ZERO", ROOM, 0}
};
/*
* All labels for verbs, nouns, flags, and items which must have
* a special number.
*/
static Keyword labels[] = {
/* Verbs. */
{"go", VLABEL, VERB_GO},
{"get", VLABEL, VERB_GET},
{"drop", VLABEL, VERB_DROP},
/* Direction nouns. */
{"north", NLABEL, 1},
{"south", NLABEL, 2},
{"east", NLABEL, 3},
{"west", NLABEL, 4},
{"up", NLABEL, 5},
{"down", NLABEL, 6},
/* The light-source item. */
{"light", OLABEL, 9},
/* The special flags. */
{"night", FLABEL, 15},
{"runout", FLABEL, 16}
};
void init(void) /* install constants and built-ins in table */
{
Symbol *s;
int i;
/*
* Install all words used in actions. Since their actual value
* depends on the output format, the format-specific translate()
* function will be called.
*/
for (i = 0; i < ARRAYSIZE(actions); i++) {
s = install(&main_table, actions[i].name, actions[i].token);
s->value = translate(actions[i].value);
}
/*
* Install the keywords for the main table.
*/
install_keywords(&main_table, keywords, ARRAYSIZE(keywords));
/*
* Install the keywords for the label table.
*/
install_keywords(&label_table, labels, ARRAYSIZE(labels));
/* installs rm_ZERO */
MakeRoom(NULL, NULL);
/*
* Install the first verb ("auto") into the verb table.
*/
s = install(&verb_table, "auto", VERB);
s->value = 0;
NumberVerb(VERB_AUTO);
SetVerb(s, PRIMARY);
/*
* Install the first noun ("any") into the noun table.
*/
s = install(&noun_table, "any", NOUN);
s->value = 0;
NounNo(0);
SetNoun(s, PRIMARY);
}
/*
*----------------------------------------------------------------------
*
* install_keywords --
*
* This procedure install keywords into a symbol table.
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
install_keywords(
Symbol** table, /* Symbol table to install keywords in. */
Keyword* keywords, /* Pointer to keyword table. */
int size) /* Size of keyword table. */
{
Symbol* s;
int i;
for (i = 0; i < size; i++)
{
s = install(table, keywords[i].name, keywords[i].token);
s->value = keywords[i].value;
if(verbose)
printf("installing : %s\n", keywords[i].name);
}
}
void printtok(int t, YYSTYPE val) /* print token symbolically */
{
int i;
switch(t) {
case TESTOBJ:
case TESTROOM:
case TESTFLAG:
case PARAMLESS:
case TESTNUM:
case IF:
case ACTOBJ:
case ACTROOM:
case ACTROOMOBJ:
case ACTOBJOBJ:
case ACTNUM:
for (i = 0; keywords[i].value != yylval.n; i++)
;
printf("action '%s'", keywords[i].name);
break;
case TIMER:
case ACTFLAG:
printf("action");
break;
case UNDEF:
printf("identifier '%s'", yylval.sym->name);
break;
case STRING:
fprintf(stderr, "\"...\"");
break;
case NUMBER:
printf("'%d'", yylval.n);
break;
case ROOM:
printf("room '%s'", yylval.sym->name);
break;
case VERB:
printf("verb #%d", yylval.n);
break;
case NOUN:
printf("noun #%d", yylval.n);
break;
case OBJECT:
printf("object #%d", yylval.n);
break;
case MESSAGE:
printf("message #%d", yylval.n);
break;
case FLAG:
printf("flag #%d", yylval.n);
break;
default:
printf("token %d", t);
break;
}
}