-
Notifications
You must be signed in to change notification settings - Fork 0
/
spittext.gpm
4310 lines (4306 loc) · 166 KB
/
spittext.gpm
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{Hl 1,Introduction}{Ls 1}
MACRO~SPITBOL is an implementation of the SNOBOL4 computer
language which was coded during 1974/75. In speed and external style
{Index IBM}{Index UNIVAC}
it resembles the earlier SPITBOL implementations for the IBM~360 and
UNIVAC~1100 series computers but internally it differs considerably
from
these since the source code is converted to a reverse polish string
which is then used to drive interpretive routines.
MACRO~SPITBOL is available with a high degree of compatibility
on a range of computers running under widely differing operating systems.
This report reflects the above fact by providing in its first nine
sections
such documentation and information for users as is substantially machine
independent, with a final section giving essential information peculiar
to each particular implementation. It is assumed that the reader is
familiar
with the standard version, referred to simply as SNOBOL4 in the remainder
of the report and described in the essential reference book
"The SNOBOL4 Programming Language" by Griswold, Poage and Polonsky,
Addison Wesley, 1971. Version 3.4 of SNOBOL4 is the reference version for
comparison. There are several minor incompatibilities and some
features are not implemented. There are several additions to the language
in this implementation.
{p}
{Ls 1}In general an attempt has been made to retain upward compatibility
wherever possible. Most SNOBOL4 programs which operate correctly using
SNOBOL4 should operate correctly when compiled and executed using
MACRO~SPITBOL. For brevity,
in the remainder of the report MACRO~SPITBOL
will be referred to simply as SPITBOL.
{Ls 2}{nfj}
SPITBOL was initially designed and implemented by:-
{Ls 1}
Professor Robert B. K. Dewar,
Courant Institute of Mathematical Sciences,
251 Mercer Street,
NEW YORK, N.Y. 10012.
U.S.A.
{Ls 1}
It has been further developed and is now maintained by:-
{Ls 1}
Dr. Anthony P. McCann,
Department of Computer Studies,
University of Leeds,
LEEDS, LS2 9JT,
England.
{Ls 2}
The VAX/VMS Version is the work of and is maintained by:
{Ls 1}Steven G. Duff
c/o Dewar Information Systems Corporation
221 West Lake Street
Oak Park, Illinois 60302
{fj}{Ls 1}Which should be contacted to report problems or
for information on distribution.
{Ls 1}The implementor gratefully acknowledges the assistance of
Thagard Research in providing development facilities for the
VAX/VMS Version of SPITBOL.
{Set Subtitle,Summary of Differences}
{p}
{Hl 1,Summary of Differences}
{Ls 1}The principal differences between SPITBOL and SNOBOL4
are summarised here.
{Hl 2,<Features not Implemented>}
{List 1}
{Listelem Redefinition}The capability to redefine
standard system functions and predefined operators.
{index pre-evaluation}
This restriction permits compile time pre-evaluation of a wider range
of expressions
and patterns than would otherwise be possible.
It affects the OPSYN function (see {SEC_FUNC} for details).
{index VALUE}
{index BACKSPACE}
{Listelem VALUE and BACKSPACE Functions}The VALUE and BACKSPACE functions.
{index &STFCOUNT}
{index &FULLSCAN}
{Listelem &STFCOUNT and &FULLSCAN}The keywords &STFCOUNT and &FULLSCAN .
{index QUICKSCAN}
The heuristics associated with the QUICKSCAN mode of pattern matching
are complex and for many programs do not result in a significant increase
{index FULLSCAN}
in speed. Accordingly only FULLSCAN matching is provided and no
heuristics are applied.
In particular deferred expressions are not assumed to match at least
one character.
{index BLOCK}
{index SNOBOL4B}
{Listelem BLOCK Datatype}The BLOCK datatype as in SNOBOL4B .
{index PUNCH}
{Listelem PUNCH Association}The
variable PUNCH has no predefined association to a punch
stream. If required, the programmer should include a
statement such as OUTPUT(.PUNCH,3) in his program.
{Listelem Real Exponentiation}SPITBOL
does not permit exponentiation of two real numbers.
{Listelem Real Arithmetic}For small machines, versions of SPITBOL in which all
real arithmetic capability is omitted are available - see {SEC_IMPL}.
{index real arithmetic}
{Listelem Features Omitted}Some
implementations may omit a few features. A list is given in
{SEC_IMPL}.
{Endlist}
{p}
{Hl 2,<Features Implemented Differently>}
{Ls 1}Some of the differences here may necessitate program changes.
{List}
{index &ANCHOR}
{Listelem &ANCHOR}In SPITBOL the value of &ANCHOR is obtained only at the start
of
the match. In SNOBOL4, changing the value during a match can lead
to unexpected results.
{index ABORT}
{index ARB}
{index BAL}
{index FAIL}
{Listelem Pattern-Valued Variables}The
pattern valued variables ABORT, ARB, BAL, FAIL
{index FENCE}
{index REM}
{index SUCCEED}
FENCE, REM, SUCCEED are write protected so that attempts
to assign to them will fail.
{Listelem Pattern Stack}The
same stack is used for pattern matching and for function calls.
Thus the
diagnostic issued for an infinite pattern recursion is simply the
standard
stack overflow message.
{index SETEXIT}
{Listelem Execution Error Recovery}Recovery from execution errors (see function SETEXIT ).
{Listelem I/O}Input/Output. In particular, FORTRAN I/O is not provided.
Dynamic association to files is possible through the third argument
and statement failure is possible if a file cannot be found as in
-
{brk}
~~~~~INPUT(.IN,3,'INFIL') :F(NOFILE)
{index TABLE}
{Listelem Tables}The TABLE function is implemented so that table elements
can be rapidly accessed by the efficient technique of hashing.
{index hashing}
In order to set a suitable
size for the hash table it is important to choose a reasonable value
for the argument of TABLE. Use of an inappropriate value will not
cause program failure but may delay access to elements or waste memory.
{Listelem Datatype Conversions}SPITBOL
allows some datatype conversions not allowed in SNOBOL4.
{index datatype conversions}
For example a real value may be used in patterns and
is converted to a string. In general objects will be converted to
an appropriate
datatype if at all possible.
{Listelem Name Operator}The
unary . (name) operator applied to a natural variable yields
{index NAME}
a NAME rather than a
STRING. Since this NAME is converted to a STRING when
necessary, the difference is not normally noticed. The only points
at which
{index IDENT}
{index DIFFER}
the difference will be apparent is in use of the IDENT, DIFFER
{index DATATYPE}
and DATATYPE functions
{index TABLE}
and when used as a TABLE subscript.
{Listelem Numeric Conversion}SPITBOL
permits leading and trailing blanks on numeric strings
which are to be converted to
{index NUMERIC}
NUMERIC .
{Listelem Built-in Functions}Several
of the built-in functions are slightly different. They
are identified
by a * on their names in {SEC_FUNC}.
{Listelem Statement Counting}The
count of statements executed includes labelled null statements
and
{index END}
the END statement.
{Listelem Optimization}Constant
sub-expressions and patterns are pre-evaluated at compile
time.
{index pre-evaluation}
This may occasionally result in execution errors (e.g. integer overflow)
being reported during compilation. Significant speed increases may
be
obtained by ensuring that in-line patterns are constant so that they
may be pre-evaluated. Patterns built from pattern valued variables
(e.g. ARB)
and pattern functions with constant arguments (e.g. ANY(*ARG),
RTAB(0)) are themselves constant.
{Listelem &MAXLNGTH}A
compact and fast garbage collector is used which needs to distinguish
{index garbage collection}
between small integers and memory addresses. This effectively restricts
the
maximum size
{index maximum size}
of any SPITBOL object (string, array, table, code or expression block)
{index MXLEN}
to be less than a value subsequently referred to as MXLEN .
This is in practice little restriction on most host computers.
Where, because of implementation needs, it might prove restrictive,
a run time option is generally
provided for setting this value to suit a user's requirements (see
{SEC_IMPL}.
where an indication of the default initial setting of MXLEN is also
given).
{index &MAXLNGTH}
Since the value of MXLEN is used to initialise &MAXLNGTH ,
printing &MAXLNGTH during execution gives its exact value.
A user may subsequently assign a smaller value to this keyword but
values exceeding that of MXLEN may not be assigned to it.
{index &TRIM}
{Listelem &TRIM}A value of zero for &TRIM does not necessarily imply that
trailing blanks will be added to records in which they are not originally
present - see {SEC_IMPL}.
{Endlist}
{Hl 2,<Additional Features>}
{Ls 1}The following SPITBOL features are not found in SNOBOL4.
{List}
{index BREAKX}
{index EJECT}
{index EXIT}
{index HOST}
{index LEQ}
{index LGE}
{Listelem Additional Functions}The
functions BREAKX, EJECT, EXIT, HOST, LEQ, LGE,
{index LLE}
{index LLT}
{index LNE}
{index LPAD}
{index REVERSE}
{index RPAD}
LLE, LLT, LNE, LPAD, REVERSE, RPAD,
{index RSORT}
{index SETEXIT}
{index SORT}
{index SUBSTR}
RSORT, SETEXIT, SORT, SUBSTR .
The sorting functions, the
extended break pattern BREAKX, and the output formatting
functions LPAD and RPAD are especially useful. See {SEC_FUNC} for details
of all these functions.
{index &ERRTEXT}{index &PROFILE}
{Listelem &ERRTEXT}The keywords &ERRTEXT and &PROFILE.
{Listelem Dumping}The
symbolic dump optionally includes elements of arrays, tables
{index DUMP}
and programmer defined datatypes. (See DUMP ).
{Listelem Access Trace}An
access trace mode is provided in addition to the other standard
modes.
{index TRACE}
(See TRACE ).
{index selection}
{index alternative}
{Listelem Selection}A selection or alternative feature is provided.
{index CONVERT}
{Listelem NUMERIC Datatype}The second argument of CONVERT may be 'NUMERIC'.
{index =}
{Listelem Additional Operators}The
assignment symbol , = , is treated as an ordinary binary
operator
{index ?}
and the binary operator , ? , is given a defined meaning as a pattern
matching operator.
{index pattern matching operator}
{Listelem Listing Options}If
running SPITBOL from an on-line terminal, options may be selected
{index on-line terminal}
to reduce the amount of listing information sent to the terminal or to
restrict this to compilation errors only. (See {SEC_IMPL} for details).
{Listelem TERMINAL}Reflecting the fact that many current computer systems
{index TERMINAL}
have good online terminal capabilities, the name TERMINAL
is available with pre-association for input and output to a
terminal on such systems - see {SEC_IMPL}.
{brk}
T~~~~~TERMINAL = EVAL(TERMINAL) :S(T)
{brk}
acts as a desk calculator. TERMINAL may be
detached but may not then be re-associated. If this
feature is unimplemented,
TERMINAL acts as an ordinary variable.
{Index Control Cards}
{Listelem Control Cards}Several
additional control cards may be used to select various
compile time and run time options.
{Index Character Set}
{Listelem Character Set Extensions}An
extended character set is available in some implementations.
Where lower case letters are provided names such as "INPUT" and "input"
{index gotos}
are distinct. In gotos :f and :s mean the same as :F and :S.
{index Tab character}
The Tab character, if available, is syntactically identical with blank.
See {SEC_IMPL}.
{index &STLIMIT}
{Listelem Statement Count Checking}The
assignment &STLIMIT = -1 inhibits all checks on
numbers of statements executed.
{index SORT}{index RSORT}
{Listelem SORT & RSORT}Built-in functions are available for sorting
the elements of tables and arrays.
{Endlist}
{p}
{Hl 2,<Syntax Differences>}{Ls 1}
This section describes differences in syntax
between SPITBOL and SNOBOL4. such differences should not
generally affect existing SNOBOL4 programs.
{List}
{Listelem ITEM}Reference to elements of arrays which are themselves elements of
{index ITEM}
arrays is possible without using the ITEM function. Thus the following
are equivalent --
{brk}
~~A<<J>><<K>> = B<<J>><<K>>;~~~~~~~ITEM(A<<J>>,K) = ITEM(B<<J>>,K)
{Listelem Real Constants}The
compiler permits real constants to be followed by a FORTRAN
style
exponent E+xxx.
{index selection}
{index alternative}
{Listelem Selection}A
selection or alternative construction may be written anywhere
that a value is permitted. It consists of a series of expressions
separated by
commas and enclosed in parentheses:
{brk}
~~(e1,e2,e3,....,en)
{brk}
The semantics is to evaluate the expressions from left to right until
one succeeds
and then use its value. Failure is signalled if all evaluations fail.
This feature trivially provides an "or" function for predicates and
also has
many other uses as shown by the following examples:
{brk}
{nfj}
~~A = (EQ(B,3),GT(B,20)) B + 1
~~NEXT = (INPUT,'%EOF')
~~MAXAB = (GT(A,B) A,B)
{brk}
{fj}
{index IF-THEN-ELSE}
The alternative structure provides an IF-THEN-ELSE capability,
and as such is a useful programming feature. Note incidentally that
the semantics of ordinary
parentheses is a correct degenerate case of an alternative structure
with one alternative.
{index []}
{index <<>>}
{Listelem Array Brackets}The
array brackets [] may be used instead of <<>> if desired.
Thus X[I,J] and X<<I,J>> are equivalent.
{index =}
{Listelem Assignment Operator}By
treating = as a right associative operator of lowest priority,
multiple assignments within a single statement may be coded. The value
returned
by an assignment is that of its right hand side. After obeying
{brk}
~~A[I = INPUT] = INPUT
{brk}
I is the index of the element of the array into
which data has been read.
{index ?}
{Listelem Pattern-Matching Operator}?
is defined to be an explicit pattern matching operator.
It is left associative and has priority lower than that of all operators
except = .
It returns as its value the substring matched from its left argument
(a string)
by its right argument (a pattern).
Thus
{nfj}
~~'ABCD' ? LEN(3) $ OUTPUT ? LEN(1) REM $ OUTPUT
causes printing of
~~ABC
~~BC
{fj}
{Endlist}
{Set Subtitle,Datatypes and Conversion}
{p}
{Hl 1,Datatypes and Conversion}
{Ls 1}This section details the datatypes available in SPITBOL
and the conversions which may be performed amongst them.
{Hl 2,<Available Datatypes>}
{List}
{index STRING}
{Listelem STRING}STRING
{brk}
{index MXLEN}
Strings range in length from 0 (null string) to MXLEN characters
{index &MAXLNGTH}
(subject to the setting of &MAXLNGTH). Any characters from the
hardware set of the computer used to run SPITBOL can appear in a string.
{index INTEGER}
{Listelem INTEGER}INTEGER
{brk}
Integers are generally stored in the hardware complement form for
the computer used to run SPITBOL and usually occupy a single word.
See {SEC_IMPL} for range.
{index REAL}
{Listelem REAL}REAL
{brk}
Available if floating point hardware is available
(sec 10.2.4).
Stored according to the usual hardware conventions of the computer
on which SPITBOL is run.
{index ARRAY}
{Listelem ARRAY}ARRAY
{brk}
{index MXLEN}
Arrays may not exceed MXLEN words in total size. 10 to 15
words must be allowed for housekeeping information.
{index TABLE}
{Listelem TABLE}TABLE
{brk}
{index MXLEN}
A table may have up to MXLEN elements. Any SPITBOL object may
be used as the name of a table element, including the null string.
See {SEC_FUNC} for details.
{index PATTERN}
{Listelem PATTERN}PATTERN
{brk}
Pattern structures may be arbitrarily large within the limits imposed
by
total available memory.
{index NAME}
{Listelem NAME}NAME
{brk}
A name can be obtained from any variable. Note that in SPITBOL
, the name operator (unary dot) applied to a natural variable yields
a name,
not a string as is the case with SNOBOL4.
Use of names as arguments to the indirection operator (unary $) is
much faster than the use of string arguments. Names can also be
used advantageously in statements such as~~INPUT(.IN)
{p}
{index EXPRESSION}
{Listelem EXPRESSION}EXPRESSION
{brk}
Any expression may be deferred by using the unary * operator.
{index CODE}
{Listelem CODE}CODE
{brk}
A string representing a valid program can be compiled at
execution time. The resulting CODE object
may be executed in the same manner as the original program.
{Endlist}
{p}
{Hl 2,<Possible Datatype Conversions>}
{Ls 1}As far as possible SPITBOL converts from one datatype to another
as required.
The following table shows which conversions are possible.
{index datatype conversions}
Blank entries indicate that the conversions are impossible,
A indicates that conversion is always possible, and U indicates conversion
is usually possible, depending on the value involved.
{nfj}
{Ls 1}
~~CONVERT TO:
{Ls 1}
~~~S I R A T P N E C
+-----------------<->
S! A U U A A U U
I! A A A A A A
R! A U A A A A
CONVERT A! A U
FROM: T! A A
P! A
N! U U U U A U U
E! A
C! A
{Ls 1}
S STRING
I INTEGER
R REAL
A ARRAY
T TABLE
P PATTERN
N NAME
E EXPRESSION
C CODE
{fj}
{p}
{Hl 2,<Conversion Details>}
{Ls 1}This section gives detailed descriptions for each of the possible
conversions.
{index datatype conversions}
{List}
{index STRING}
{Listelem STRING->INTEGER}STRING --> INTEGER
{Ls 1}Leading and trailing blanks are ignored. A leading sign is
optional. The sign, if present, must immediately precede the digits.
A null or all blank string is converted to zero.
{Listelem STRING->REAL}STRING --> REAL
{Ls 1}Leading and trailing blanks are ignored. A leading sign if present,
must immediately precede the number. The number itself may
be written in standard FORTRAN type format with an optional exponent.
The conversion is always accurate, the last bit being correctly rounded.
A null or blank string is converted to 0.0 .
{Listelem STRING->PATTERN}STRING --> PATTERN
{Ls 1}A pattern is created which will match the string value.
{Listelem STRING->NAME}STRING --> NAME
{Ls 1}The result is the name of the natural variable which has the given
string as its name. This is identical to the result of applying the
unary dot operator to the variable in question. The null string
cannot be converted to a name.
{Listelem STRING->EXPRESSION}STRING --> EXPRESSION
{Ls 1}The string must represent a legal SPITBOL expression. The compiler
is used to convert the string into its equivalent expression and the
result can be used anywhere an expression is permitted.
{Listelem STRING->CODE}STRING --> CODE
{Ls 1}The string must represent a legal SPITBOL program, complete with
labels, and using semicolons to separate statements. The compiler
is used to convert the string into executable code. The resulting
code can be
executed by transferring to it with a direct GOTO or by a normal
transfer to a label within the code.
{p}
{index INTEGER}
{Listelem INTEGER->STRING}INTEGER --> STRING
{Ls 1}The result has no leading or trailing blanks and leading zeros
are suppressed. A minus sign is prefixed to negative values.
Zero is converted to "0".
{Listelem INTEGER->REAL}INTEGER --> REAL
{Ls 1}A real number is obtained by adding a zero fractional part.
Note that it is possible to lose significance in this conversion if
the mantissa of the real representation has fewer digits than are
available for an integer.
{Listelem INTEGER->PATTERN}INTEGER --> PATTERN
{Ls 1}First convert to a STRING and then treat as STRING to PATTERN.
{Listelem INTEGER->NAME}INTEGER --> NAME
{Ls 1}First convert to STRING and then treat as STRING to NAME.
{Listelem INTEGER->EXPRESSION}INTEGER --> EXPRESSION
{Ls 1}The result is an EXPRESSION which when evaluated yields the INTEGER
as its value.
{index REAL}
{Listelem REAL->STRING}REAL --> STRING
{Ls 1}The real number is converted to its standard character representation.
Fixed type format is used if possible, otherwise an exponent (using
E)
is supplied. Seven significant digits are generated, the last being
correctly
rounded for all cases. Trailing insignificant zeros are suppressed
after
rounding has taken place.
{Listelem REAL->INTEGER}REAL --> INTEGER
{Ls 1}This conversion is only possible if the REAL is in the range permitted
for integers.
in this case, the result is obtained by truncating the fractional
part.
{Listelem REAL->PATTERN}REAL --> PATTERN
{Ls 1}First convert to STRING and then treat as STRING to PATTERN.
{Listelem REAL->NAME}REAL --> NAME
{Ls 1}First convert to STRING and then treat as STRING to NAME.
{Listelem REAL->EXPRESSION}REAL --> EXPRESSION
{Ls 1}The result is an expression which when evaluated yields the
REAL as its value.
{index ARRAY}
{Listelem ARRAY->TABLE}ARRAY --> TABLE
{Ls 1}The array must be two dimensional with a second dimension of 2
or an error occurs. For each value of the first subscript, J ,
a table entry using the (J,1) entry as name and the (J,2) entry
as value is created. The table built has a number of hash headers
(see TABLE in {SEC_FUNC}) equal to the first dimension.
{index TABLE}
{Listelem TABLE->ARRAY}TABLE --> ARRAY
{Ls 1}The table must have at least one element which is non-null otherwise
statement failure occurs.
The array generated is two dimensional with the first dimension
equal to the number of non-null entries in the table and the second
dimension is two. For each entry, the (J,1) element in the array
is the the name and the (J,2) element is the value.
{index NAME}
{Listelem NAME->STRING}NAME --> STRING
{Ls 1}A NAME can be converted to a STRING only if it is the name of a natural
variable.
The resulting string is the character name of the variable.
{Listelem NAME-><INTEGER, REAL, PATTERN, EXPRESSION, CODE>}NAME --> INTEGER,
REAL, PATTERN, EXPRESSION, CODE
{Ls 1}The NAME is first converted to a STRING (if possible)
and then the conversion proceeds as described for STRING.
{Endlist}
{Set Subtitle,Operators and Functions}
{p}
{Hl 1,Operators and Functions}
{Hl 2,<Operators>}
{index operators}
{Ls 1}SPITBOL operators are listed without any detailed descriptions since
they correspond, with a few exceptions noted in the description
of differences, to those of SNOBOL4.
{Hl 3,Unary Operators}
{Ls 1}Unary operators all have equal priority which is greater than that
of any binary operator.
{Ls 1}
{nfj}
OPERATOR DESCRIPTION
{Ls 1}
{index ?}
? Interrogation - null if operand succeeds
{index &}
& Keyword
{index +}
+ Indicates postive numeric operand
{index -}
- Negates numeric operand
{index *}
* Defers evaluation of expression
{index $}
$ Indirection
{index .}
. Returns a name
{Tset Hs,`}
{index ~}
~ Negates failure or success of its operand
{Restore Hs}
{index <@>}
@ Assigns cursor position to its operand
{Ls 1}
{index !}
{index %}
{index /}
{index ~}
{index =}
Unused unary operator symbols are ! % / # =
{fj}
{p}
{Hl 3,Binary Operators}
{Ls 1}Several of the associativites and priorities differ from those of
SNOBOL4.
{nfj}
{Ls 1}
OP. ASSOCY. PRIO. DEFINITION
{Ls 1}
= right 0 Assignment
? left 1 Pattern match
{index |}
| right 3 Pattern alternation
blank right 4 Concatenation or pattern match
+ left 6 Arithmetic addition
- left 6 Arithmetic subtraction
/ left 8 Arithmetic division
* left 9 Arithmetic multiplication
{index !}
! or ** right 11 Arithmetic exponentiation
$ left 12 Immediate pattern assignment
. left 12 Conditional pattern assignment
{Ls 1}
& left 2 Undefined
@ right 5 Undefined
{Tset Hs,*}
~ left 7 Undefined
{Restore Hs}
% left 10 Undefined
_ right 13 Undefined
{fj}
{p}
{Hl 2,<Functions>}
{index functions}
{Ls 1}This section defines the built-in functions of SPITBOL, the descriptions
being given in alphabetical order. In most cases, the arguments
are pre-converted to some particular datatype. This is indicated in
the function header by the notation --
{brk}
~~FUNCTION(STRING,INTEGER,....)
{brk}
If the corresponding argument cannot be converted to the indicated
datatype,
an error occurs. Sometimes the range of arguments permitted is restricted,
in which case arguments outside the range cause an error. The usage
"ARGUMENT" implies that the argument can be of any datatype.
"NUMERIC" implies that either REAL or INTEGER arguments are acceptable.
{index ARRAY}
{index DATA}
{index DEFINE}
{Ls 1}In functions such as ARRAY, DATA, DEFINE with a string
prototype argument, the string should not contain non-significant
blanks.
{index ANY}
{Hl 3,ANY -- Pattern to Match Selected Character}
{Ls 1}
ANY(STRING) or ANY(EXPRESSION)
{Ls 1}This function returns a pattern which will
match a single character selected from the characters in the argument
string.
A null argument is not permitted.
If an expression argument is used, then the expression is evaluated
during pattern matching and must yield a non-null string result.
{index APPLY}
{Hl 3,APPLY * -- Apply function}
{Ls 1}
APPLY(NAME,ARG,ARG,...)
{Ls 1}The first argument is the name of a function to be applied to the
(possibly null) list of arguments following. Unlike SNOBOL4,
SPITBOL does not require the number of arguments to match the function
definition, extra arguments being ignored and missing arguments being
supplied
as null strings.
{index ARBNO}
{Hl 3,ARBNO -- Pattern for Iterated Match}
{Ls 1}
ARBNO(PATTERN)
{Ls 1}This function returns a pattern which will match an arbitrary number
of
occurrences of the pattern argument, including zero occurrences (this
resulting in matching of the null string).
{p}
{index ARG}
{Hl 3,ARG * -- Obtain Argument Name}
{Ls 1}
ARG(NAME,INTEGER)
{Ls 1}The first argument represents the name of a function.
The integer is the index of a formal argument to this function.
The NAME of the selected argument is returned (this is converted
to a string on output).
ARG fails if the integer is out of range of the number of formal arguments.
{index ARRAY}
{Hl 3,ARRAY -- Generate Array Structure}
{Ls 1}
ARRAY(STRING,ARG) or ARRAY(INTEGER,ARG)
{index arrays}
{Ls 1}The string represents the protoype of an array to be allocated.
This is in the form
{brk}
~~~"LBD1:HBD1,LBD2:HBD2,...."
{brk}
where LBD1,HBD1 etc. are integers specifying low and high bounds.
The low bound (LBD) may be omitted for some or all of the dimensions,
in
which case the colon may also be omitted and a low bound of 1 is assumed.
The second argument (of any datatype) is the initial value of all
the
elements in the array. If it is omitted, the initial value of all
the
elements will be the null string.
The second form of the call may be used to create one dimensional
arrays (vectors) with a low bound of 1. SPITBOL optimises accesses
to elements
{index vectors}
of vectors.
{index BREAK}
{Hl 3,BREAK -- Construct Scanning Pattern}
{Ls 1}
BREAK(STRING) or BREAK(EXPRESSION)
{Ls 1}This function returns a pattern which will match any string up
to the point preceding any character which occurs in the argument
string.
A null argument is not permitted.
If an expression argument is given, the resulting pattern causes
the expression to be evaluated during pattern matching. In this case,
the evaluated result must be a non-null string.
{p}
{index BREAKX}
{Hl 3,BREAKX * -- Construct Scanning Pattern}
{Ls 1}
BREAKX(STRING) or BREAKX(EXPRESSION)
{Ls 1}BREAKX returns a pattern whose initial match is the
same as a corresponding
BREAK pattern. However, BREAKX has implicit alternatives which on
subsequent match failure permit scanning past the first break character
found
and up to the next break character. Note that BREAKX may be used to
{index ARB}
replace ARB
in many situations where BREAK cannot be used easily. For example
the following replacement can be made --
{brk}
~~~ARB ('CAT' ! 'DOG') --> BREAKX('CD') ('CAT' ! 'DOG')
{Brk}In the case of an expression argument, the expression is evaluated
during
pattern matching and must yield a non-null string. Note that evaluation
of the expression is not repeated on rematch attempts by extension.
{index CLEAR}
{Hl 3,CLEAR * -- Clear Variable Storage}
{Ls 1}
CLEAR(STRING)
{Ls 1}This function causes the values of variables to be set to null.
In the simple case, where the argument is omitted or null, the action
is
the same as in SNOBOL4 (i.e. all variables cleared to null).
An extension is available in SPITBOL. The first argument may be a
string
which is a list of variable names separated by commas. These represent
the
names of variables whose values are to be left unchanged. For example
--
{brk}
~~~CLEAR('ABC,CDE,EFG')
{brk}
would cause the value of all variables except ABC, CDE, EFG
to be set to the null string.
{index CODE}
{Hl 3,CODE * -- Compile Code}
{Ls 1}
CODE(STRING)
{Ls 1}The effect of this function is to convert the argument to type CODE
as described
in the section on type conversion. The STRING must represent a valid
SPITBOL
program complete with labels and using semicolons (;) to separate
statements.
The call to CODE fails if syntactic errors are found.
{index &ERRTEXT}
In this case it is possible to inspect &ERRTEXT to find the
error message. e.g.
{brk}
~~~~~~~C = CODE(CD) :F<<CODE(' OUTPUT = &ERRTEXT')>>
{brk}
{index SETEXIT}
SETEXIT may also be used to intercept these errors.
Another extension over SNOBOL4 is that the code string may contain
{index -LIST}
embedded control cards (notably -LIST to cause listing of the
code) and comments
delimited by semicolons.
{p}
{index COLLECT}
{Hl 3,COLLECT -- Initiate Storage Regeneration}
{Ls 1}
COLLECT(INTEGER)
{index garbage collection}
{Ls 1}The COLLECT function forces a garbage collection which retrieves
unused storage
and returns it to the block of available storage. The integer argument
represents a minimum number of words to be made available.
If this amount of storage cannot be obtained, the COLLECT function
fails.
On successful return, the result is the number of words actually obtained.
Although the implementation of COLLECT is the same as in SNOBOL4,
the values obtained will be quite different due to different internal
data representations.
Furthermore, the organization of SPITBOL is such that forcing garbage
collections
to occur before they are required increases execution time.
{index CONVERT}
{Hl 3,CONVERT * -- Convert Datatypes}
{Ls 1}
CONVERT(ARGUMENT,STRING)
{Ls 1}The returned result is obtained by converting the first argument
to the type indicated by
the string name of the datatype given as the second argument.
The permitted conversions are described in the section on
type conversion.
Any conversions which are not permitted cause failure of the CONVERT call.
The second argument may be 'NUMERIC' , in which case the argument
is converted to INTEGER or REAL according to its form.
{index COPY}
{Hl 3,COPY * -- Copy Structure}
{Ls 1}
COPY(ARGUMENT)
{Ls 1}The COPY function returns a distinct copy of the object presented
as its argument.
This is only useful for arrays, tables and
program defined datatypes. Note that SPITBOL permits copying of TABLES
unlike SNOBOL4.
{p}
{index DATA}
{Hl 3,DATA -- Create Datatype}
{Ls 1}
DATA(STRING)
{index program defined datatypes}
{Ls 1}The argument to DATA is a prototype for a program defined datatype
in the form of a function
call with arguments e.g. DATA('CMPLX(RE,IM)').
The function name in the string is the name of the new datatype.
The argument names in the string are the names of field selector
functions used to access the fields of the new datatype. Increased
efficiency is obtained by avoiding the use of duplicate field names
for different
datatypes, although such multiple use is not forbidden.
{index DATATYPE}
{Hl 3,DATATYPE * -- Obtain Datatype}
{Ls 1}
DATATYPE(ARGUMENT)
{Ls 1}DATATYPE returns the formal identification of the datatype of its
argument.
{index DATE}
{Hl 3,DATE * -- Obtain Date}
{Ls 1}
DATE()
{Ls 1}DATE returns a string giving the current date and
possibly also clock-on-the-wall-time (see {SEC_IMPL}.)
{index DEFINE}
{Hl 3,DEFINE -- Define a Function}
{Ls 1}
DEFINE(STRING) or DEFINE(STRING,NAME)
{Ls 1}The DEFINE function is used to create program defined functions
according to the prototype supplied as the argument.
The second argument if supplied, names the label at the entry to the
function.
{index DETACH}
{Hl 3,DETACH -- Detach I/O Association}
{Ls 1}
DETACH(NAME)
{Ls 1}NAME is the name of a variable which has previously been input or
output associated
{index INPUT}
{index OUTPUT}
by appearing as the first argument of INPUT or OUTPUT.
DETACH cancels the association of the variable but does
not affect the file to which it was associated.
{p}
{index DIFFER}
{Hl 3,DIFFER * -- Test for Arguments Differing}
{Ls 1}
DIFFER(ARGUMENT,ARGUMENT)
{Ls 1}DIFFER is a predicate function which fails if its two arguments are
identical objects.
In SPITBOL
{brk}
~~~DIFFER(.ABC,'ABC')
{brk}
succeeds since .ABC is a NAME. DIFFER and IDENT are the only functions
in which the different implementation of the name operator (unary
dot) may give rise to problems.
{index DUMP}
{Hl 3,DUMP * -- Dump Storage}
{Ls 1}
DUMP(INTEGER)
{Ls 1}The DUMP function causes a dump of current values to occur.
After the dump is complete, execution continues unaffected (the DUMP
function returns the null string). If the argument is 1, then the
dump includes values of
all non-constant keywords and all non-null natural variables.
If the argument is 2, then the dump also includes values of all non-null
array
and table elements and non-null field values of program defined datatypes.
The format of the latter dump is self explanatory and avoids printing
any structure
more than once.
A call to DUMP with a zero argument is ignored. This allows use of
a switch
value which can be turned on and off globally.
A call to DUMP with an argument greater than 2 produces a core dump
in the same
format as that produced by a system abnormal end and should
therefore be used with discretion.
{index DUPL}
{Hl 3,DUPL * -- Duplicate String or Pattern}
{Ls 1}
DUPL(STRING,INTEGER) or DUPL(PATTERN,INTEGER)
{Ls 1}DUPL returns a result obtained by duplicating the first argument
the number of
times indicated by the second.
A null string is returned if INTEGER is zero and statement
failure occurs if it is negative.
{index EJECT}
{Hl 3,EJECT * -- Eject to new page}
{Ls 1}
EJECT(INTEGER) or EJECT(STRING)
{Ls 1}The argument must have previously appeared as the second argument
of a call of
{index OUTPUT}
OUTPUT to identify an output channel. An eject to the top of the
next
page of the output file occurs.
A null or absent argument causes an eject on the standard output file.
{p}
{index ENDFILE}
{Hl 3,ENDFILE * -- Close a File}
{Ls 1}
ENDFILE(INTEGER) or ENDFILE(STRING)
{Ls 1}The argument must have previously appeared as the second argument
of a call of
{index INPUT}
{index OUTPUT}
INPUT or OUTPUT
to identify an input/output channel. The file attached to the channel
is closed, associated storage is
released and all variables associated with the file are detached.
Thus ENDFILE
should be used only when no further use is to be made of the file.
If the file is to be reread or rewritten, use REWIND (if the implementation
supports this function - see {SEC_IMPL}).
{Hl 3,EQ -- Test for Equal}
{Ls 1}
EQ(NUMERIC,NUMERIC)
{Ls 1}EQ is a predicate function which succeeds if its two arguments are
equal.
{index EVAL}
{Hl 3,EVAL * -- Evaluate Expression}
{Ls 1}
EVAL(EXPRESSION)
{Ls 1}EVAL returns the result of evaluating its expression argument. Note
that a string
can be converted into an expression by compiling it into CODE. Thus
EVAL
in SPITBOL is compatible with SNOBOL4 and handles strings in the same
way. If an error occurs in evaluating the argument,
{index &ERRTEXT}
&ERRTEXT is set and EVAL fails. To avoid such errors passing
{index SETEXIT}
unnoticed, it may be well to use SETEXIT to intercept them,
{index -NOFAIL}