The Best of Creative Computing Volume 2 (published 1977)

Page 36 << PREVIOUS >> NEXT Jump to page:
Go to contents Go to thumbnails
This book is also available for the Kindle

SNOBOL (About the SNOBOL programming language)
by David Touretzky

graphic of page

SNOBOL

by David Touretzky

SNOBOL is a string processing, pattern matching language, that breaks all the
restrictions associated with numerical languages like FORTRAN or dp languages
like COBOL. Here are some key points:

1. No fixed data types. A variable's type is determined by its values. Changing
the value changes the type. The datatypes available are: string, integer, real,
double precision, array, table, pattern, name, and compiled code. The table is a
type of hash table: its subscript is a string instead of an integer.

2. The heart of SNOBOL is the concept of pattern matching. A SNOBOL statement is
made up of one or more of the following fields:

label string pattern =

string branch

Every pattern match either fails or succeeds. The branch section causes
branching to a specified label based on the results of the pattern match. For
example:

MYLABLE CARD 'CAT' I 'DOG' =

'ANIMAL' :S(L1)

ln statement MYLABEL, the variable CARD is searched for any occurrence of 'CAT'
or 'DOG'. lf the test succeeds, the string which was matched is replaced by the
string 'ANlMAL', and, since the match succeeded, the program would branch to L1.
lf the test failed, the program would continue with the next statement. Pattern
matching can be much more complex, and can include many levels of alternatives,
calls to user or system functions, recursive pattern definitions, and
self-modifying patterns. Many special characters are used in pattern matching
operations. For
example, the $ is an assignment operator.

TEXT SPAN('A') $ C =

will match the first contiguous string of A's in TEXT and assign that string to
the variable C. ln addition, the string will be deleted from TEXT, since a null
expression appears to the right of the equals sign.

3. Concatenation is accomplished by writing expressions next to each other. For
example:

MESSAGE = 'THE BILL IS'

(COST * 1.05)  '.'

In this case, COST would be multiplied by 1.05, converted to a string, and
concatenated with the other strings in the expression. Strings may be of any
length. They expand and contract through pattern matches or assignments.

4. Complete debugging tools are available, including traces, variable dumps, and
program controlled error handling. Interactive implementations, such as SITBOL,
allow convenient debugging as the program executes.

5. As you have seen, SNOBOL has no verbs, no data restrictions, and no
artificial constructs like blocks, procedures, or cases. The language is based
on special symbols, such as =$.*?&:()@, and system functions which generate
patterns (such as CONVERT). There are also some system variables, such as
&ALPHABET which contains every possible character, &STLlMlT, the maximum number
of statements that may be executed and &ERRNO, the code number of the most
recent error interrupt.

6. SNOBOL is available on many machines, including the IBM 360, the DEC system
10, and UNIVAC 1108. Two extended versions are commonly in use: SPITBOL and
SITBOL. The best introduction to the language I have seen is
the SNOBOL 4 PRIMER, by Ralph and Madge Griswold, published by Prentice-Hall.

7. SNOBOL can be used for many things, including file manipulation, database
editing, music generation, language analysis and translation, game theory,
computer assisted instruction, and the simulation of automata.

©CREATIVE COMPUTING

[image]  "And where were you when the FORTRAN hit the fan?"

Page 36 << PREVIOUS >> NEXT Jump to page:
Go to contents Go to thumbnails
This book is also available for the Kindle