SNOBOL - Introduction
In this series we’ll look at SNOBOL, a unique pattern matching language, and its implementation on MTS.
SNOBOL overview
SNOBOL (StriNg Oriented and symBOlic Language) was developed at Bell Labs in the 1960s to help with a symbolic manipulation project. It had powerful pattern matching and string manipulation features but had a simple syntax: it has no control flow instructions apart from goto and variables are dynamically typed and don’t need declarations. It started to spread to other sites and was taught at some universities in the 197-s. The original implementation was for the IBM 7090 but versions were ported to the IBM S/360 and DEC PDP/10. Its use started to die out in the 1980s but its creators went on to work on the ICON language and it influenced later text manipulation languages such as AWK and Perl.
SNOBOL on MTS
The main implementation that we will run here is the *SNOBOL4
interpreter. Also available on the D6.0 tapes is *SNOBOL4B
which has an extension to the core language for printing blocks, two- and three-dimensional visualisations of data.
MTS originally had a number of other implementations of SNOBOL that are not available on the D6.0 tapes due to copyright reasons:
*SPITBOL
- a fast SNOBOL 4 compiler from the Illinois Institute of Technology.*SNOSTORM
- a SNOBOL preprocessor written at UM to add structured programming features
(Note that SPITBOL/360 has now been GPL’d and should be eligible for inclusion in future distributions of MTS - see here.)
Prerequisites
No special installation instructions to get SNOBOL running - just do the standard D6.0 setup as described in this guide and then sign on as a regular user such as ST01
.
Using *SNOBOL
*SNOBOL4
will read the source code for the program and then any input from unit 5 (by default *source*
ie standard input). If you want to take the source code from a file prog.sn
and then enter input from the keyboard you could do something like:
# $run *snobol4 5=prog.sn+*source*
Other parameters to *SNOBOL4
are listed in MTS Volume 9.
Hello world
Here’s a transcript of a session where we run a Hello world program. This assumes the source code is contained in the file hello.sn
. Note that the code is not free format: only goto labels and comments (starting with *
) are allowed in the first column.
# $list hello.sn
1 * SNOBOL program to print Hello World
2 I = 1
3 LOOP OUTPUT = "Hello, world!"
4 I = I + 1
5 LE(I, 5) : S(LOOP)
6 END
# $run *snobol4 5=hello.sn
SNOBOL4 (VERSION 3.10, APRIL 1, 1973)
(MTS IMPLEMENTATION MAY 1, 1975)
* SNOBOL program to print Hello World
*1 I = 1
*2 LOOP OUTPUT = "Hello, world!"
*3 I = I + 1
*4 LE(I, 5) : S(LOOP)
*5 END
0 SYNTACTIC ERROR(S) IN SOURCE PROGRAM
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
NORMAL TERMINATION AT LEVEL 0
LAST STATEMENT EXECUTED WAS 4
SNOBOL4 STATISTICS SUMMARY
5 MS. COMPILATION TIME
2 MS. EXECUTION TIME
16 STATEMENTS EXECUTED, 1 FAILED
5 ARITHMETIC OPERATIONS PERFORMED
0 PATTERN MATCHES PERFORMED
0 REGENERATIONS OF DYNAMIC STORAGE
0 READS PERFORMED
5 WRITES PERFORMED
0.13 MS. AVERAGE PER STATEMENT EXECUTED
Further information
MTS Volume 9 describes the SNOBOL compilers available on MTS and includes a basic tutorial on the language.
snobol4.org has lots of information about SNOBOL’s history, implementations and links to books including the main reference manual for the language, “The SNOBOL4 Programming Language”.