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
|
-- Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
-- All rights reserved.
-- Copyright (C) 2007-2011, Gabriel Dos Reis.
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are
-- met:
--
-- - Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
--
-- - Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in
-- the documentation and/or other materials provided with the
-- distribution.
--
-- - Neither the name of The Numerical Algorithms Group Ltd. nor the
-- names of its contributors may be used to endorse or promote products
-- derived from this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--
import utility
namespace BOOTTRAN
module tokens ($InteractiveMode)
++ If true, means the system is in interactive mode.
$InteractiveMode := false
++ converts `x', a 1-length symbol, to a character.
char x ==
stringChar(symbolName x, 0)
shoeStartsId x ==
alphabetic? x or x in [char "$", char "?", char "%"]
shoeIdChar x ==
alphanumeric? x or x in [char "'", char "?", char "%", char "!",char "&"]
++ return the sub-string of `s' starting from `f'.
++ When non-nil, `n' designates the length of the sub-string.
subString(s,f,n == nil) ==
n = nil => subSequence(s,f)
subSequence(s,f,f + n)
++ Table of Boot keywords and their token name.
shoeKeyWords == [ _
['"and","AND"] , _
['"by", "BY" ], _
['"case","CASE"] , _
['"catch","CATCH"], _
['"cross","CROSS"] , _
['"do", "DO" ], _
['"else", "ELSE"] , _
['"finally", "FINALLY"], _
['"for", "FOR"] , _
['"forall", "FORALL"] , _
['"has", "HAS"] , _
['"if", "IF"], _
['"import", "IMPORT"], _
['"in", "IN" ], _
['"is", "IS"], _
['"isnt", "ISNT"] , _
['"leave", "LEAVE"], _
['"macro", "MACRO"], _
['"module", "MODULE"], _
['"namespace", "NAMESPACE"], _
['"of", "OF"] , _
['"or", "OR"] , _
['"rem", "REM"], _
['"repeat", "REPEAT"] , _
['"return", "RETURN"], _
['"quo", "QUO"], _
['"structure", "STRUCTURE"], _
['"then", "THEN"], _
['"throw", "THROW"], _
['"try", "TRY"], _
['"until", "UNTIL"], _
['"where", "WHERE"], _
['"while", "WHILE"], _
['".", "DOT"], _
['":", "COLON"], _
['"::", "COLON-COLON"], _
['",", "COMMA"], _
['";", "SEMICOLON"], _
['"*", "TIMES"], _
['"**", "POWER"], _
['"/", "SLASH"], _
['"+", "PLUS"], _
['"-", "MINUS"], _
['"<", "LT"], _
['">", "GT"] , _
['"<=","LE" ], _
['">=","GE" ], _
['"=", "SHOEEQ"], _
['"^", "NOTRETIRED"], _
['"^=","SHOENERETIRED" ], _
['"~=","SHOENE" ], _
['"..","SEG" ], _
['"#", "LENGTH"], _
['"=>","EXIT" ], _
['"->", "ARROW"],_
['":=", "BEC"], _
['"+->", "GIVES"], _
['"==", "DEF"], _
['"<=>", "TDEF"], _
['"(", "OPAREN"], _
['")", "CPAREN"], _
['"(|", "OBRACK"], _
['"|)", "CBRACK"], _
['"[", "OBRACK"], _
['"]", "CBRACK"], _
['"suchthat","BAR"], _
['"'", "QUOTE"], _
['"|", "BAR"] ]
shoeKeyTableCons()==
KeyTable := makeTable function valueEq?
for st in shoeKeyWords repeat
tableValue(KeyTable,first st) := second st
KeyTable
shoeKeyTable:=shoeKeyTableCons()
shoeInsert(s,d) ==
l := #s
h := codePoint stringChar(s,0)
u := d.h
n := #u
k:=0
while l <= #u.k repeat
k:=k+1
v := newVector(n+1)
for i in 0..k-1 repeat
v.i := u.i
v.k := s
for i in k..n-1 repeat
v.(i+1) := u.i
d.h := v
s
shoeDictCons()==
l := HKEYS shoeKeyTable
d :=
a := newVector 256
b := newVector 1
b.0 := newString 0
for i in 0..255 repeat
a.i := b
a
for s in l repeat
shoeInsert(s,d)
d
shoeDict:=shoeDictCons()
shoePunCons()==
listing := HKEYS shoeKeyTable
a := makeBitVector 256
for i in 0..255 repeat
bitmask(a,i) := 0
for k in listing repeat
shoeStartsId k.0 => nil
bitmask(a,codePoint stringChar(k,0)) := 1
a
shoePun:=shoePunCons()
++ List of prefix operators.
for i in [ _
"NOT", _
-- "COLON", _
-- "SHOEEQ", _
"LENGTH" _
] _
repeat property(i,'SHOEPRE) := true
++ List of infix operators.
for i in [ _
["SHOEEQ" ,"="], _
["TIMES" ,"*"], _
["REM", "rem"],_
["QUO", "quo"],_
["PLUS" ,"+"], _
["IS" ,"is"], _
["ISNT" ,"isnt"], _
["AND" ,"and"], _
["OR" ,"or"], _
["SLASH" ,"/"], _
["POWER" ,"**"], _
["MINUS" ,"-"], _
["LT" ,"<"], _
["GT" ,">"], _
["LE" ,"<="], _
["GE" ,">="], _
["SHOENE" ,"~="] _
]_
repeat property(first i,'SHOEINF) := second i
++ List of monoid operations and their neutral elements.
++ Note that `CONS' is not a monoid operations but support
++ right reduction.
for i in [ _
["+", 0] , _
["gcd", 0] , _
["lcm", 1] , _
["STRCONC", '""] , _
["strconc", '""] , _
["CONCAT", '""] , _
["MAX", -999999] , _
["MIN", 999999] , _
["*", 1] , _
["times", 1] , _
["CONS", nil] , _
["append", nil] , _
["append!", nil] , _
["UNION", nil] , _
["UNIONQ", nil] , _
["union", nil] , _
["and", true] , _
["or", false] , _
["AND", true] , _
["OR", false] _
]
repeat property(first i,'SHOETHETA) := rest i
for i in [ _
["abs", "ABS"], _
["abstractChar", "CODE-CHAR"], _
["alphabetic?", "ALPHA-CHAR-P"], _
["alphanumeric?", "ALPHANUMERICP"], _
["and", "AND"] , _
["apply", "APPLY"] , _
["array?", "ARRAYP"] , _
["arrayRef", "AREF"] , _
["atom", "ATOM"] , _
["bitmask", "SBIT"] , _
["canonicalFilename", "PROBE-FILE"], _
["charByName", "NAME-CHAR"] , _
["charDowncase", "CHAR-DOWNCASE"], _
["charEq?", "CHAR=" ], _
["charUpcase", "CHAR-UPCASE"], _
["charString", "STRING"] , _
["char?", "CHARACTERP"] , _
["codePoint", "CHAR-CODE"], _
["cons?", "CONSP"] , _
["copy", "COPY"] , _
["copyTree", "COPY-TREE"] , _
["croak", "CROAK"] , _
["digit?", "DIGIT-CHAR-P"] , _
["drop", "DROP"] , _
["exit", "EXIT"] , _
["false", 'NIL] , _
["first", "CAR"] , _
["float?", "FLOATP"] , _
["flushOutput", "FORCE-OUTPUT"], _
["fourth", "CADDDR"] , _
["function","FUNCTION"] , _
["function?","FUNCTIONP"] , _
["gensym", "GENSYM"] , _
["genvar", "GENVAR"] , _
["integer?","INTEGERP"] , _
["LAST", "last"] , _
["list", "LIST"] , _
["listEq?", "EQUAL"] , _
["lowerCase?", "LOWER-CASE-P"], _
["makeSymbol", "INTERN"] , _
["maxIndex", "MAXINDEX"] , _
["mkpf", "MKPF"] , _
["newString", "MAKE-STRING"], _
["newVector", "MAKE-ARRAY"], _
["nil" ,NIL ] , _
["not", "NOT"] , _
["null", "NULL"] , _
["odd?", "ODDP"] , _
["or", "OR"] , _
["otherwise", "T"] , _
["property", "GET"] , _
["readInteger", "PARSE-INTEGER"], _
["readLispFromString", "READ-FROM-STRING"] , _
["readOnly?","CONSTANTP"], _
["removeDuplicates", "REMDUP"] , _
["rest", "CDR"] , _
["sameObject?", "EQ" ] , _
["scalarEq?", "EQL" ] , _
["scalarEqual?","EQL" ] , _
["second", "CADR"] , _
["setIntersection", "INTERSECTION"] , _
["setPart", "SETELT"] , _
["setUnion", "UNION"] , _
["strconc", "CONCAT"] , _
["stringChar", "SCHAR"] , _
["stringDowncase", "STRING-DOWNCASE"] , _
["string?", "STRINGP"] ,_
["stringEq?","STRING="] , _
["stringUpcase", "STRING-UPCASE"] , _
["subSequence", "SUBSEQ"] , _
["symbolScope", "SYMBOL-PACKAGE"] , _
["symbolEq?", "EQ"], _
["symbolFunction", "SYMBOL-FUNCTION"], _
["symbolName", "SYMBOL-NAME"], _
["symbolValue", "SYMBOL-VALUE"], _
["symbol?", "SYMBOLP"] , _
["take", "TAKE"] ,
["third", "CADDR"] , _
["toString", "WRITE-TO-STRING"], _
["true", "T"] , _
["upperCase?", "UPPER-CASE-P"], _
["valueEq?", "EQUAL"] , _
["vector?", "SIMPLE-VECTOR-P"], _
["vectorRef", "SVREF"] , _
["writeByte", "WRITE-BYTE"], _
["writeChar", "WRITE-CHAR"], _
["writeInteger", "PRINC"], _
["writeLine", "WRITE-LINE"], _
["writeNewline", "TERPRI"], _
["writeString", "WRITE-STRING"], _
["PLUS", "+"] , _
["MINUS", "-"] , _
["TIMES", "*"] , _
["POWER", "EXPT"] , _
['REM, 'REM],_
['QUO, 'TRUNCATE],_
["SLASH", "/"] , _
["LT", "<"], _
["GT", ">"] , _
["LE", "<="], _
["GE", ">="], _
["SHOEEQ", "EQUAL"], _
["SHOENE", "/="], _
["T", "T$"] _
]
repeat property(first i,'SHOERENAME) := rest i
for i in [ _
["setName", 0] , _
["setLabel", 1] , _
["setLevel", 2] , _
["setType", 3] , _
["setVar", 4] , _
["setLeaf", 5] , _
["setDef", 6] , _
["aGeneral", 4] , _
["aMode", 1] , _
["aModeSet", 3] , _
["aTree", 0] , _
["aValue", 2] , _
["args", "CDR"] , _
["attributes", "CADDR"] , _
["cacheCount", "CADDDDR"] , _
["cacheName", "CADR"] , _
["cacheReset", "CADDDR"] , _
["cacheType", "CADDR"] , _
["env", "CADDR"] , _
["expr", "CAR"] , _
["CAR", "CAR"] , _
["mmCondition", "CAADR"] , _
["mmDC", "CAAR"] , _
["mmImplementation","CADADR"] , _
["mmSignature", "CDAR"] , _
["mmTarget", "CADAR"] , _
["mmSource", "CDDAR"] , _
["mode", "CADR"] , _
["op", "CAR"] , _
["opcode", "CADR"] , _
["opSig", "CADR"] , _
["CDR", "CDR"] , _
["sig", "CDDR"] , _
["source", "CDR"] , _
["streamCode", "CADDDR"] , _
["streamDef", "CADDR"] , _
["streamName", "CADR"] , _
["target", "CAR"] _
] _
repeat property(first i,'SHOESELFUNCTION) := second i
|