summaryrefslogtreecommitdiff
path: root/lang/lisp/1.8.7/src/lisp.2
blob: 28e692410c95ae4f339f9a970c2a3a0af4a5524b (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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
PACKET character buffer                            (* Autor : J.Durchholz *) 
                                                   (* Datum : 09.05.1984  *) 
    DEFINES                                        (* Version 1.7.2       *) 
                                      (* 21.2.83. hey 293, 450,97,361 *)
  get char, 
  line nr, 
  init char buffer: 
 
 
TEXT VAR buffer; 
INT VAR pointer, 
        line; 
 
 
INT PROC line nr: 
  line 
END PROC line nr; 
 
 
PROC init char buffer: 
  buffer := ""; 
  pointer := 1; 
  line := 0; 
END PROC init char buffer; 
 
 
PROC get char (FILE VAR f, TEXT VAR char): 
  IF buffer empty THEN 
    try to find nonempty line and put it into buffer; 
    char := " "; 
    pointer := 1 
  ELSE 
    char := buffer SUB pointer; 
    pointer INCR 1 
  FI. 
 
buffer empty: 
  pointer > length (buffer). 
 
try to find nonempty line and put it into buffer: 
  REP 
    IF eof (f) THEN 
      char := ""; 
      LEAVE get char 
    FI; 
    get line (f, buffer); 
    line INCR 1 
  UNTIL buffer <> "" PER. 
 
END PROC get char; 
 
 
END PACKET character buffer; 
 
 
 
 
PACKET lisp io                                      (* Autor: J.Durchholz *) 
                                                    (* Datum: 10.09.1982  *) 
    DEFINES                                         (* Version 4.1.3      *) 
                                                    (* Änderung: notebook *)
  put,  note,                                       (*    13.3.86  I. Ley *)
  verbose lisp output, 
  get, 
  get all: 
 
 
BOOL VAR verbose :: FALSE; 
 
 
PROC verbose lisp output (BOOL CONST b): 
  verbose := b 
END PROC verbose lisp output; 
 
BOOL PROC verbose lisp output: 
  verbose 
END PROC verbose lisp output; 
 
 
PROC put (SYM CONST sym): 
  IF atom (sym) THEN 
    put atom 
  ELSE 
    put structure 
  FI. 
 
put atom: 
  IF is named atom (sym) THEN 
    put (name (sym)) 
  ELIF is int pair (sym) THEN 
    put (int 1 (sym)) 
  ELIF is text (sym) THEN 
    IF verbose THEN 
      TEXT VAR buffer :: text (sym); 
      change all (buffer, """", """"""); 
      buffer CAT """"; 
      put ("""" + buffer) 
    ELSE 
      write (text (sym)) 
    FI 
  ELIF is character (sym) THEN 
    IF verbose THEN 
      buffer := "'"; 
      buffer CAT code (character (sym)); 
      buffer CAT "'"; 
      put (buffer) 
    ELSE 
      out (code (character (sym))) 
    FI 
  ELSE 
    put (""15"UNBEKANNTER_ATOM_TYP"14"") 
  FI. 
 
put structure: 
  put ("("); 
  SYM VAR actual node := sym; 
  REP 
    put (head (actual node)); 
    actual node := tail (actual node) 
  UNTIL atom (actual node) PER; 
  IF NOT null (actual node) THEN 
    put ("."); 
    put (actual node) 
  FI; 
  put (")"). 
 
END PROC put; 
 
PROC put (FILE VAR f, SYM CONST sym): 
  IF atom (sym) THEN 
    put atom 
  ELSE 
    put structure 
  FI. 
 
put atom: 
  IF is named atom (sym) THEN 
    put (f, name (sym)) 
  ELIF is int pair (sym) THEN 
    put (f, int 1 (sym)) 
  ELIF is text (sym) THEN 
    IF verbose THEN 
      TEXT VAR buffer :: text (sym); 
      change all (buffer, """", """"""); 
      buffer CAT """"; 
      put (f, """" + buffer) 
    ELSE 
      put (f, text (sym)) 
    FI 
  ELIF is character (sym) THEN 
    IF verbose THEN 
      buffer := "'"; 
      buffer CAT code (character (sym)); 
      buffer CAT "'"; 
      put (f,  buffer) 
    ELSE 
      put (f,  code (character (sym))) 
    FI 
  ELSE 
    put ( f, ""15"UNBEKANNTER_ATOM_TYP"14"") 
  FI. 
 
put structure: 
  put (f, "("); 
  SYM VAR actual node := sym; 
  REP 
    put (f, head (actual node)); 
    actual node := tail (actual node) 
  UNTIL atom (actual node) PER; 
  IF NOT null (actual node) THEN 
    put (f, "."); 
    put (f, actual node) 
  FI; 
  put (f, ")"). 
 
END PROC put; 
 
 PROC note (SYM CONST sym): 
  IF atom (sym) THEN 
    note atom 
  ELSE 
    note structure 
  FI. 
 
note atom: 
  IF is named atom (sym) THEN 
    note ( name (sym)) 
  ELIF is int pair (sym) THEN 
    note (int 1 (sym)) 
  ELIF is text (sym) THEN 
    IF verbose THEN 
      TEXT VAR buffer :: text (sym); 
      change all (buffer, """", """"""); 
      buffer CAT """"; 
      note ( """" + buffer) 
    ELSE 
      note ( text (sym)) 
    FI 
  ELIF is character (sym) THEN 
    IF verbose THEN 
      buffer := "'"; 
      buffer CAT code (character (sym)); 
      buffer CAT "'"; 
      note ( buffer) 
    ELSE 
      note ( code (character (sym))) 
    FI 
  ELSE 
    note ( ""15"UNBEKANNTER_ATOM_TYP"14"") 
  FI. 
 
note structure: 
  note ( "("); 
  SYM VAR actual node := sym; 
  REP 
    note ( head (actual node)); 
    actual node := tail (actual node) 
  UNTIL atom (actual node) PER; 
  IF NOT null (actual node) THEN 
    note ( "."); 
    note ( actual node) 
  FI; 
  note ( ")"). 
 
END PROC note; 
 
PROC get (FILE VAR f, SYM VAR s): 
  initialize scanner (f); 
  IF NOT get s expression (s) THEN 
    error ("LISP-Ausdruck erwartet") 
  FI; 
  scanner postprocessing (f) 
END PROC get; 
 
 
(**************************** parser for 'get' ****************************) 
 
 
LET end of file type = 0, 
    name type = 1, 
    text type = 2, 
    character type = 3, 
    int type = 4, 
    other char type = 5; 
 
 
BOOL PROC get s expression (SYM VAR s): 
  (* The boolean result indicates wether the error has not occurred that  *) 
  (* 'get next symbol' was called, but then the symbol was not expected   *) 
  (* and thus could not be processed.                                     *) 
  get next symbol; 
  SELECT symbol type OF 
    CASE end of file type: FALSE 
    CASE name type: s := new atom (symbol); TRUE 
    CASE text type: s := sym (symbol); TRUE 
    CASE character type: s := sym character (code (symbol)); TRUE 
    CASE int type: s := sym (int (symbol), -1); TRUE 
    CASE other char type: get structure 
    OTHERWISE error ("EINLESEFEHLER: unbekannter Symboltyp: " + 
                     text (symbol type)); TRUE 
  END SELECT. 
 
get structure: 
  IF symbol <> "(" THEN 
    FALSE 
  ELSE 
    get list; 
    IF symbol type <> other char type OR symbol <> ")" THEN 
      error (">> ) << erwartet"); 
      FALSE 
    ELSE 
      TRUE 
    FI 
  FI. 
 
get list: 
  SYM VAR father, son; 
  IF get s expression (son) THEN 
    get list elements; 
  ELSE 
    s := nil 
  FI. 
 
get list elements: 
  father := cons (son, nil); 
  s := father; 
  WHILE get s expression (son) REP 
    set tail (father, cons (son, nil)); 
    father := tail (father) 
  PER; 
  IF symbol type = other char type AND symbol = "." THEN 
    IF get s expression (son) THEN 
      set tail (father, son); 
      get next symbol 
    ELSE 
      error ("LISP-Ausdruck nach dem Punkt erwartet") 
    FI 
  FI. 
 
END PROC get s expression; 
 
 
(********************* scanner for 'get x espression' *********************) 
 
 
FILE VAR infile; 
 
 
PROC initialize scanner (FILE CONST f): 
  infile := f; 
  no input errors := TRUE; 
  init char buffer; 
  get char (infile, actual char) 
END PROC initialize scanner; 
 
 
PROC scanner postprocessing (FILE VAR f): 
  f := infile 
END PROC scanner postprocessing; 
 
 
TEXT VAR symbol; INT VAR symbol type; 
 
 
PROC get next symbol: 
  skip blanks; 
  IF actual char = "" THEN 
    symbol := "DATEIENDE"; 
    symbol type := end of file type 
  ELIF is letter THEN 
    get name 
  ELIF is digit or sign THEN 
    get integer 
  ELIF is double quote THEN 
    get text 
  ELIF is single quote THEN 
    get character 
  ELSE 
    get other char 
  FI .
 
is letter: 
  IF "a" <= actual char AND actual char <= "z" THEN 
    actual char := code (code (actual char) - code ("a") + code ("A")); 
    TRUE 
  ELSE 
    "§" <= actual char AND actual char <= "Z" 
  FI. 
 
get name: 
  symbol type := name type; 
  symbol := actual char; 
  REP 
    get char (infile, actual char); 
    IF is neither letter nor digit THEN 
      LEAVE get name 
    FI; 
    symbol CAT actual char 
  PER. 
 
is neither letter nor digit: 
  NOT (is letter OR is digit OR is underscore). 
 
is digit: 
  "0" <= actual char AND actual char <= "9". 
 
is underscore: 
  actual char = "_". 
 
is digit or sign: 
  is digit OR actual char = "+" OR actual char = "-". 
 
get integer: 
  symbol type := int type; 
  IF actual char = "+" THEN 
    get char (infile, actual char); 
    skip blanks; 
    symbol := actual char 
  ELIF actual char = "-" THEN 
    symbol := "-"; 
    get char (infile, actual char); 
    skip blanks; 
    symbol CAT actual char 
  ELSE 
    symbol := actual char 
  FI; 
  REP 
    get char (infile, actual char); 
    IF NOT is digit THEN 
      LEAVE get integer 
    FI; 
    symbol CAT actual char 
  PER. 
 
is double quote: 
  actual char = """". 
 
get text: 
  symbol := ""; 
  symbol type := text type; 
  REP 
    get char (infile, actual char); 
    IF is double quote THEN 
      get char (infile, actual char); 
      IF NOT is double quote THEN LEAVE get text 
      FI 
    ELIF actual char = ""    THEN LEAVE get text  (*hey*)
    FI; 
    symbol CAT actual char 
  PER. 
 
is single quote: 
  actual char = "'". 
 
get character: 
  symbol type := character type; 
  get char (infile, symbol); 
  get char (infile, actual char); 
  IF actual char <> "'" THEN 
    error (">> ' << erwartet") 
  ELSE 
    get char (infile, actual char) 
  FI. 
 
get other char: 
  symbol type := other char type; 
  symbol := actual char; 
  get char (infile, actual char). 
 
END PROC get next symbol; 
 
 
TEXT VAR actual char; 
 
 
PROC skip blanks: 
  INT VAR comment depth :: 0; 
  WHILE is comment OR actual char = " " REP 
    get char (infile, actual char) 
  PER. 
 
is comment: 
  IF actual char = "{" THEN 
    comment depth INCR 1; 
    TRUE 
  ELIF actual char = "}" THEN 
    IF comment depth = 0 THEN 
      error (">> { << fehlt") 
    ELSE 
      comment depth DECR 1 
    FI; 
    TRUE 
  ELSE 
    IF comment depth > 0 THEN 
      IF actual char = "" THEN 
        error ("DATEIENDE im Kommentar"); 
        FALSE 
      ELSE 
        TRUE 
      FI 
    ELSE 
      FALSE 
    FI 
  FI. 
 
END PROC skip blanks; 
 
 
BOOL VAR no input errors; 
FILE VAR errors; 
 
 
PROC error (TEXT CONST error message): 
  out ("FEHLER in Zeile "); 
  out (text (line nr)); 
  out (" bei >> "); 
  out (symbol); 
  out (" << : "); 
  out (error message); 
  line; 
  IF no input errors THEN 
    no input errors := FALSE; 
    errors := notefile; modify(errors);
    headline (errors, "Einlesefehler"); output(errors)
  FI; 
  write (errors, "FEHLER in Zeile "); 
  write (errors, text (line nr)); 
  write (errors, " bei >> "); 
  write (errors, symbol); 
  write (errors, " << : "); 
  write (errors, error message); 
  line (errors) 
END PROC error; 
 
 
PROC get (SYM VAR sym):     (*hey*)
  disable stop; 
  FILE VAR in  :: sequential file (modify, "LISP INPUT"), 
           out :: notefile; modify (out);
  headline (out,"LISP OUTPUT");
  headline (in, "LISP INPUT");
  noteedit (in);
  input (in); 
  get (in, sym); 
  WHILE NOT no input errors AND NOT is error REP 
    modify (errors);
    headline (errors, " LISP-Fehlermeldungen"); 
    headline (in, " Bitte KORREKTEN LISP-Ausdruck"); 
    noteedit (in); 
    headline (errors, "notebook"); 
    input (in); 
    get (in, sym) 
  PER; 
END PROC get; 
 
 
PROC get all (FILE VAR f, SYM VAR sym): 
  get (f, sym); 
  skip blanks; 
  IF NOT eof (infile) THEN 
    error ("Hinter dem letzten Symbol des LISP-Ausdruck stehen noch Zeichen") 
  FI 
END PROC get all; 
 
 
END PACKET lisp io; 
 
 
 
PACKET lisp integer                                 (* Autor: J.Durchholz *) 
                                                    (* Datum: 30.08.1982  *) 
    DEFINES                                         (* Version 1.1.2      *) 
 
  sum, 
  difference, 
  product, 
  quotient,
  remainder:
 
SYM PROC sum (SYM CONST summand list): 
  INT VAR result := 0; 
  SYM VAR list rest := summand list; 
  WHILE NOT atom (list rest) REP 
    result INCR int 1 (head (list rest)); 
    list rest := tail (list rest) 
  PER; 
  IF NOT null (list rest) THEN 
    error stop ("Summandenliste endet falsch") 
  FI ;
  sym (result, -1) 
END PROC sum; 
 
 
SYM PROC difference (SYM CONST minuend, subtrahend): 
  sym (int 1 (minuend) - int 1 (subtrahend), -1) 
END PROC difference; 
 
 
SYM PROC product (SYM CONST factor list): 
  INT VAR result := 1; 
  SYM VAR list rest := factor list; 
  WHILE NOT atom (list rest) REP 
    result := result * int 1 (head (list rest)); 
    list rest := tail (list rest) 
  PER; 
  IF NOT null (list rest) THEN 
    error stop ("Faktorenliste endet falsch") 
  FI; 
  sym (result, -1) 
END PROC product; 
 
 
SYM PROC quotient (SYM CONST dividend, divisor): 
  sym (int 1 (dividend) DIV int 1 (divisor), -1) 
END PROC quotient; 
 
 
SYM PROC remainder(SYM CONST dividend, divisor): 
  sym (int 1 (dividend) MOD int 1 (divisor), -1) 
END PROC remainder;
 
 
END PACKET lisp integer;