summaryrefslogtreecommitdiff
path: root/web/spiderweb/src/c/new.spider
blob: d361bb99a94cbab30d21b37050bd908c22b4c4ef (plain)
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
Return-Path: <smith%zeus@harvard.harvard.edu>
Received: by jumbo.pa.dec.com; id AA01901; Thu, 26 Jul 90 08:43:40 -0700
Received: by decpa.pa.dec.com; id AA11390; Thu, 26 Jul 90 08:43:34 -0700
Received: from cs.Princeton.EDU by Princeton.EDU (5.61++/2.48/princeton)
	id AA16823; Thu, 26 Jul 90 11:43:18 -0400
Received: by cs.Princeton.EDU (5.57/1.105)
	id AA04017; Thu, 26 Jul 90 11:43:53 EDT
Received: from harvard.harvard.edu by Princeton.EDU (5.61++/2.48/princeton)
	id AA16820; Thu, 26 Jul 90 11:43:07 -0400
Message-Id: <9007261543.AA16820@Princeton.EDU>
Received: by harvard.harvard.edu (5.54/a0.25)
	(for nr@princeton.edu) id AA00320; Thu, 26 Jul 90 11:43:21 EDT
Date: Thu, 26 Jul 90 11:43:21 EDT
Received: by zeus.HARVARD.EDU; Thu, 26 Jul 90 11:41:04 EDT
From: smith%zeus@harvard.harvard.edu (Steven Smith)
To: nr@Princeton.EDU
Subject: Spidery WEB

Prof. Ramsey:

FYI: I've been using your Spidery WEB system and have introduced the
followng changes to c.spider:

1) c.spider hung on the declaration (cf. K&R p. 123)

	struct {
	  int x;
	  int *y;
	} *p;

I fixed this by changing

	[ struct_head ] simp --> decl_head simp

to
	[ struct_head ] (math|simp) --> decl_head (math|simp)


2) I introduced the category `asterisk' so that `*' can be used as the
\mathbin `*' or the \mathord `{*}' by TeX, depending on the context.
Search for `asterisk' below to see the changes.

Steven Smith
smith@sandalphon.harvard.edu


The file c.spider:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Cut Here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Copyright 1989 by Norman Ramsey, Odyssey Research Associates
# Not to be sold, but may be used freely for any purpose
# For more information, see file COPYRIGHT in the parent directory
#
# Alterations:
# 7/25/90 Steven T. Smith; Allowed declaration of ptr to structures.
# 7/25/90 Steven T. Smith; Introduced `asterisk' category.
# 7/25/90 Steven T. Smith; Changed `->' to different \mathord. 
language C extension c

at_sign @

comment begin <"/*"> end <"*/">

default translation <*> mathness yes

token identifier category simp mathness yes
token number category math mathness yes
token newline category newline mathness maybe translation <>
token pseudo_semi category semi mathness maybe translation <"\\relax">

module definition stmt use math

token + category unorbinop
token - category unorbinop
token * category asterisk tangleto <space-"*">
#					avoid inadvertant /*
token / category dot
token < category less translation <>
token > category greater translation <>
token = category equals translation <"\\leftarrow"> tangleto <"="-space>
#					avoid inadvertant =-
token . category dot
token ~ category unop translation <"\\TI">
token & category unorbinop translation <"\\amp">
token ^ translation <"\\^"> category binop
token | category binop
token ? translation <"\\?"> category question
token % translation <"\\%"> category binop
token # translation <"\\#"> category sharp
token ! category unop translation <"\\neg">
token \ category backslash translation <"\\backslash">
token ( category open
token ) category close
token [ category open
token ] category close
token { translation <"\\{"-indent> category lbrace
token } translation <"\\}"> category rbrace
token , category comma translation <",\\;">
token ; category semi
token : category colon
token ++ category unop translation <"\\PP">
token -- category unop translation <"\\MM">
token != translation <"\\I"> category binop
token <= translation <"\\L"> category binop
token >= translation <"\\G"> category binop
token == translation <"\\S"> category binop
token && translation <"\\W"> category binop
token || translation <"\\V"> category binop
token -> translation <"\\MG"> category binop
token >> translation <"\\GG"> category binop
token << translation <"\\LL"> category binop

macros begin
\def\CC{\mathrel{:{:}}}
\def\CCE{\mathrel{:{:}=}}
\def\FE{\mathrel{/=}}
\def\PP{\mathord{++}}
\def\PE{\mathrel{+=}}
\def\MM{\mathord{--}}
\def\ME{\mathrel{-=}}
\def\MG{\mathord{-\!\triangleright}}
#\def\MG{\mathrel{\to}}
\def\GG{\mathrel{>\!>}}
\def\LL{\mathrel{<\!<}}
\def\TE{\mathrel{\ast=}}
\def\CE{\mathrel{\%=}}
\def\HE{\mathrel{\uparrow=}}
\def\AE{\mathrel{\&=}}
\def\OE{\mathrel{|=}}
\let\openbraces=\{
\let\closebraces=\}
\def\{{\ifmmode\openbraces\else$\openbraces$\fi}
\def\}{\ifmmode\closebraces\else$\closebraces$\fi}
\def\?{\mathrel?}
\def\s{\ }
macros end

default translation <*-"\\"-space>

ilk case_like category case
ilk int_like category decl_head translation <*>
ilk else_like category else
ilk enum_like category enum
ilk if_like category if
ilk for_like category for
ilk do_like category do
ilk sizeof_like category sizeof
ilk struct_like category struct
ilk switch_like category switch
ilk typedef_like category typedef

default translation <*>

reserved auto ilk int_like
reserved break ilk case_like
reserved case ilk case_like
reserved char ilk int_like
reserved continue ilk case_like
reserved default ilk case_like
reserved do ilk do_like
reserved double ilk int_like
reserved else ilk else_like
reserved enum ilk enum_like
reserved extern ilk int_like
reserved float ilk int_like
reserved for ilk for_like
reserved goto ilk case_like
reserved if ilk if_like
reserved int ilk int_like
reserved long ilk int_like
reserved register ilk int_like
reserved return ilk case_like
reserved short ilk int_like
reserved sizeof ilk sizeof_like
reserved static ilk int_like
reserved struct ilk struct_like
reserved switch ilk switch_like
reserved typedef ilk typedef_like
reserved union ilk struct_like
reserved unsigned ilk int_like
reserved void ilk int_like
reserved while ilk for_like

# we indulge in a trick to avoid treating
#	ASCII (*fp)(); 
# as a statement (function call). We use instead
#	ASCII ===> (*fp)();
token ===> translation <"\\relax"> tangleto <space> category decl_head


# 
? ignore_scrap --> #1
#  dropped, because we've overflowed yacc!     
#### DON'T DO THIS!  it makes it impossible to add translation on the left
#### ignore_scrap ? --> #2


# because of declarations, we have to be very careful about converting
# simp to math

(math|simp) unop --> math
math (binop|unorbinop) (math|simp) --> math
math [ asterisk ] (math|simp) --> math binop (math|simp)
math comma <opt-9> (math|simp) --> math
# we're not allowed math simp --> statement because math simp could be fn_decl
math math --> math
(math|simp) semi --> stmt
# so to hack the omission above, we include (usually a cast)
math <"\\"-space> stmt --> stmt

(open|simpopen|question|unop|unorbinop|case) [ simp ] --> (open|simpopen|question|unop|unorbinop|case) math
[ simp ] binop --> math binop
# old: 
# [ simp ] equals --> math equals
# math [ equals ] --> math binop

simp* colon --> tag

# can't have simp open --> open because that causes ( to eat all id's to its left.
simp open --> simpopen

(open|simpopen) math close --> math
(open|simpopen) <"\\,"> close --> math
# following needed for for statements
open stmt <"\\"-space> --> open

# here we try to deal with casts and argument lists, e.g.
#	(ASCII *) malloc(sizeof (ASCII *));
#	char *malloc(int);

# If the type is predefined, we know we have a cast
(open|simpopen) decl_head close --> cast
(open|simpopen) [ decl_head (unorbinop|math|simp) ] --> (open|simpopen) decl_head
(open|simpopen) [ decl_head <"\\"-space-"{"> asterisk <"}"> ] --> (open|simpopen) decl_head_ptr
decl_head_ptr <"{"> asterisk <"}"> --> decl_head_ptr
decl_head_ptr --> decl_head
(open|simpopen) decl_head comma --> arglist
arglist (decl_head|unorbinop|math) --> arglist
arglist close --> math

# and here are some common cases of casts with non-predefined types
# for other cases you'll have to use "declares"
(open|simpopen) math <"\\"-space> unorbinop comma --> arglist
(open|simpopen) math <"\\"-space> unorbinop unorbinop comma --> arglist
(open|simpopen) math <"\\"-space> unorbinop unorbinop unorbinop comma --> arglist
(open|simpopen) math <"\\"-space> unorbinop close --> cast
(open|simpopen) math <"\\"-space> unorbinop unorbinop close --> cast
(open|simpopen) math <"\\"-space> unorbinop unorbinop unorbinop close --> cast

# the math here seems to be a cast.  We don't convert to cast because it looks
# too much like a cycle
(open|simpopen) [ math <"\\"-space> simp ] --> (open|simpopen) math

# Here is the destiny of casts
cast <"\\"-space> (math|simp) --> math
cast (newline|ignore_scrap) --> cast
cast --> math



question math colon --> binop

unop math --> math
<"{"> unorbinop <"}"> math --> math
<"{"> asterisk <"}"> (math|simp) --> math
<"\\buildrel"> (binop|unorbinop) <"\\over{"> equals <"}"> --> binop
[ asterisk ] equals --> unorbinop equals
equals --> binop
sizeof (math|simp) --> math

(simp|decl_head) <"\\"-space> decl_head --> decl_head
[ simp ] math (equals|comma|semi) --> decl_head math (equals|comma|semi)
[ (decl_head|simp) simp ] (simp|math) --> decl_head (simp|math)
(simp|decl_head) <"\\"-space> (simp|math)* comma --> decl_head
(simp|decl_head) <"\\"-space> (simp|math)* semi --> decl
(simp|decl_head) <"\\"-space> (simp|math)* equals --> decl_equals
decl_equals math comma --> decl_head
decl_equals math semi --> decl
decl_equals [ simp ] --> decl_equals math

struct simp* <"\\"-space> lbrace --> structbrace
struct lbrace --> structbrace
structbrace [ simp ] --> structbrace decl_head
structbrace <force> decl --> structbrace
structbrace <outdent-force> rbrace --> struct_head
[ struct_head ] (math|simp) --> decl_head (math|simp)
# N.b. K&R p. 123.
# some people say e.g. struct blah {...};    is this K&R?
struct_head semi --> decl
struct [ simp (newline|ignore_scrap) ] --> struct simp
struct simp --> decl_head
decl_head <"\\"-space> struct --> struct

# enumeration types are like structures and unions, but they have math
# instead of many decls...
enum simp* <"\\"-space> lbrace --> enumbrace
enum lbrace  --> enumbrace
enumbrace math rbrace <outdent> --> enum_head
[ enum_head ] simp --> decl_head simp
enum_head semi --> decl
enum [ simp (newline|ignore_scrap) ] --> enum simp
enum simp --> decl_head
decl_head <"\\"-space> enum --> enum

typedef [ simp ] --> typedef decl_head
typedef decl --> decl




[ math* <indent> ] (lbrace|decl_head|decl) --> fn_decl (lbrace|decl_head|decl)
[ (simp|decl_head) <"\\"-space> math* <indent> ] (lbrace|decl_head|decl) --> fn_decl (lbrace|decl_head|decl)
fn_decl <force> decl --> fn_decl
# The following statment will always have braces and never be tagged
fn_decl <outdent-force> stmt --> function
# include stmt here to cover module definition
(stmt|decl|function) <big_force> function --> function
function <big_force> decl --> decl

(stmt|decl) <force> decl --> decl
decl <big_force> stmt --> stmt
decl <outdent-big_force> tagged_stmt --> stmt


lbrace <outdent-force> rbrace --> stmt
lbrace <force> stmt --> lbrace
lbrace <outdent-force> tagged_stmt --> lbrace
lbrace (math|simp) <outdent> rbrace --> math

# if math can be followed by a brace, or no.
# ifmath and ifbrace can have an attached else or else if clause
# else, for, and while are formatted like if, but can't have an
# attached else clause, so we use formath and forbrace

if math --> ifmath
ifmath <"\\"-space> lbrace --> ifbrace
ifbrace <force> stmt --> ifbrace
ifbrace <outdent-force> tagged_stmt --> ifbrace
ifbrace [ rbrace (newline|ignore_scrap) ] --> ifbrace rbrace
ifbrace rbrace [ else (newline|ignore_scrap) ] --> ifbrace rbrace else
ifbrace <outdent-force> rbrace <"\\"-space> else if --> if
ifbrace <outdent-force> rbrace <"\\"-space> else lbrace --> forbrace
ifbrace <outdent-force> rbrace <"\\"-space> else --> formath
ifbrace <outdent-force> rbrace --> stmt

# Assume simple statements attached to if will never be tagged

ifmath [ stmt (newline|ignore_scrap) ] --> ifmath stmt
ifmath stmt [ else (newline|ignore_scrap) ] --> ifmath stmt else
ifmath <indent-force> stmt <outdent-force> else if --> if
ifmath <indent-force> stmt <outdent-force> else lbrace --> forbrace
ifmath <indent-force> stmt <outdent-force> else --> formath
ifmath <indent-force> stmt <outdent> --> stmt

for math --> formath
formath <"\\"-space> lbrace --> forbrace
forbrace <force> stmt --> forbrace
forbrace <outdent-force> tagged_stmt --> forbrace
forbrace <outdent-force> rbrace --> stmt
formath <indent-force> stmt <outdent> --> stmt

# we need an extra indent for switch, becuase the cases will be backed out
switch math lbrace <indent> --> switchbrace
switchbrace <outdent-force> tagged_stmt --> switchbrace
# This next should never happen
switchbrace <force> stmt --> switchbrace
switchbrace <outdent-outdent-force> rbrace --> stmt



# handle do-while (while has category for)
do lbrace --> dobrace
dobrace <force> stmt --> dobrace
dobrace <outdent-force> tagged_stmt --> dobrace
dobrace rbrace for --> math
do <indent-force> stmt <outdent-force> for --> math

case semi --> stmt
case math semi --> stmt
case colon --> tag
case math colon --> tag
tag <force> tag --> tag
tag <indent-force> stmt --> tagged_stmt

stmt <force> stmt --> stmt
stmt <outdent-force> tagged_stmt --> stmt
semi --> stmt

# control sequence \8 puts things on the left margin
<force-"\\8"> sharp <"{\\let\\\\=\\bf"-space> (simp|if|else) <"}"-indent-"{}"-space> --> preproc
preproc backslash <force-"\\8\\hskip1em"-space> newline --> preproc
preproc <force-outdent> newline --> ignore_scrap
preproc !(less|lesssimp|backslash|newline) --> preproc
newline --> ignore_scrap

less simp --> lesssimp
lesssimp dot simp --> lesssimp
<"\\LN"> lesssimp greater <"\\RN"> --> math
<"<"> lesssimp --> unop
less <"<"> --> binop
greater <">"> --> binop
dot --> binop

macros begin
\let\LN\langle
\let\RN\rangle
macros end