# SNOBOL4(1) | CSNOBOL4B 2.0 | January 1, 2015

## NAME

snobol4 – SNOBOL4 interpreter

## DESCRIPTION

This manual page describes CSNOBOL4, a port of the original Bell Telephone Labs (BTL) Macro Implementation of SNOBOL4 to the C language.

The language and its implementation are described in [Griswold1971] and [Griswold1972].

For command line options see snobol4cmd(1).

Extensions from Catspaw SNOBOL4+, SPITBOL and SITBOL have been added, see snobol4ext(1).

### Changes

The following behaviors have been changed from the original Macro SNOBOL4 in ways that might effect old programs:

INTEGER exceptions
  INTEGER math can never cause expression failure.

Listings are disabled by default
  Default listing side (when enabled by -LIST or the -l command line option is LEFT. Listings are directed to standard error (or file specified by the -l command line option.

Messages
  The the startup banner and statistics (if enabled) are directed to standard error.

  Compilation error messages (including erroneous lines) appear on standard error. Error messages reference the source file name and line number.

Character set
  see below.

INPUT() and OUTPUT()
  FORTRAN formats are not used to control I/O. The 3rd argument to the OUTPUT() and INPUT() functions is interpreted as a string of I/O options, The 4th argument is used to specify a file name, see snobol4io(1) for details.

PUNCH variable
  The PUNCH output variable no longer exists, the TERMINAL variable has been added in it's place, see snobol4io(1).

Statement separator
  Control lines and comment characters are valid after the (;) statement separator. Listing statement numbers show the statement number of the LAST statement on the line (rather than the first).

&STLIMIT
  &STLIMIT defaults to -1, see snobol4key(1).

Tracing
  VALUE tracing applies to variables modified by immediate value assignment ($ operator) and value assignment (. operator) during pattern matching.

### Extensions

Further additions are documented in snobol4ext(1).

### Character set

snobol4(1) is 8-bit clean, and uses the native character set. Any 8-bit byte is accepted as a SNOBOL datum or in a string constant of a SNOBOL source program. The value of the SNOBOL protected keyword &ALPHABET is a 256-character string of all bytes from 0 to 255, in ascending order.

On ASCII-based systems, any character with the 8th bit set is treated as “alphabetic”, and can start, or be used in identifiers and labels. This includes characters from the “upper half” of national character sets and all bytes resulting from the UTF-8 encoding of Unicode characters. Include file utf.sno implements pattern matching functions for UTF-8 sequences.

Programs may be entered in mixed case; By default lower case identifiers are folded to upper case (see &CASE and –CASE). Case folding is performed by using the C library islower(3) test, and then using toupper(3) to convert the lower-case characters to upper case. When using UTF-8 encoded characters in code, case folding should be disabled, to prevent any bytes which appear to be lower case in the current locale from being modified.

The following operator character sequences are permitted and represent a cross between PDP-10 Macro SNOBOL, SITBOL and Catspaw SPITBOL usage:

Exponentiation: | ^ **
Alternation: | | !
Unary negation: | ~ \
Assignment: | = _
Comment line: | * # | ; !
Continuation line: | + .

Both square brackets ([]) and angle brackets (<>) may be used to subscript arrays and tables. The TAB (ASCII 9) character is accepted as whitespace.

Underscore (_) and period (.) are legal within identifiers and labels.

Note that the use of the pound sign for comments allows use of the script interpreter (hash-bang) sequence at the top of a file marked as executable: “#!/usr/local/bin/snobol4” or “#!/usr/bin/env snobol4”

## DIRECTORY SEARCH LIST

A directory search list is used for files specified in -INCLUDE directives and LOAD() function calls is constructed from:

Any directories specified on the command line using -I options, in the order specified.

Directories from the the SNOPATH environment variable (see below), if defined.

If SNOPATH is not defined, the SNODIR environment variable (or a compiled in default) is used as base to add the following directories:

- . (the current working directory)
- base/version/lib
- base/version/local
- base/local

The LOAD() function will also check for the file in shared subdirectory in each directory in the search path.

## ENVIRONMENT

SNOPATH
  Is a list of directories delimited by colons (semi-colons on VMS and Windows) appended to the Directory Search List (see above).

SNOLIB
  SNOLIB is used to establish the base libary path if SNOPATH is not defined. See Directory Search List above. SNOLIB was the sole search directory in versions of CSNOBOL4 prior to version 1.5.

SNOBOL_PRELOAD_PATH
  Is a list of source files delimited by colons (semi-colons on VMS and Windows) that will be read before the program source. Using SNOBOL_PRELOAD_PATH will make your code less portable.

## SEE ALSO

sdb(1) | SNOBOL4 Debugger
snobol4cmd(1) | command line options
snobol4ctrl(1) | control lines
snobol4error(1) | &ERRTYPE and &ERRTEXT values
snobol4ext(1) | extensions to BTL SNOBOL4
snobol4func(1) | built-in function list
snobol4io(1) | input/output
snobol4key(1) | keywords
snobol4op(1) | operators
snobol4blocks(1) | SNOBOL4B BLOCKS extension
snopea(1) | convert snopea documentation to roff and HTML
snobol4dirs(3) | directory access functions
snobol4ffi(3) | Foreign Function Interface functions
snobol4fork(3) | subprocess interface functions
snobol4logic(3) | bit logic & formatting functions
snobol4ndbm(3) | keyed file access functions
snobol4random(3) | pseudo-random numbers functions
snobol4readline(3) | input with line editing
snobol4setup(3) | loadable module builder
snobol4sprintf(3) | formatting function
snobol4sqlite3(3) | SQLite database interface functions
snobol4sqlite3dbm(3) | DBM interface using SQLite
snobol4stat(3) | file metadata functions
snobol4stcl(3) | Tcl/Tk interface functions
snobol4time(3) | date/time functions
snolib(3) | misc library functions
snopea(7) | A little “Plain Old Documentation” format for SNOBOL4

http://www.snobol4.org
  All things SNOBOL4 related.

http://www.snobol4.com
  Catspaw: commercial SPITBOL implementations, Free SNOBOL4+ for DOS.

http://www.snobol4.org/doc/burks/tutorial/contents.htm
  SNOBOL4 language tutorial (from Catspaw Vanilla SNOBOL4)

[Griswold1971]
  R. E. Griswold, J. F. Poage, and I. P. Polonsky, The SNOBOL4 Programming Language, 2nd ed., Prentice-Hall Inc., 1971. (aka the “green book”) http://www.snobol4.org/docs/books.html#green

[Griswold1972]
  R. E. Griswold, The Macro Implementation of SNOBOL4, W. H. Freeman and Co., 1972. Book describing the implementation techniques used in Macro SNOBOL4. http://www.snobol4.org/docs/books.html#macro

http://www.snobol4.org/doc/burks/manual/contents.htm
  Catspaw Vanilla SNOBOL4 manual.

ftp://ftp.snobol4.com/spitman.pdf
  Catspaw Macro SPITBOL manual

http://www.snobol4.org/docs/books.html#orange
  Algorithms in SNOBOL4, James F. Gimpel, Wiley, New York, 1976.

## AUTHORS

Ralph E. Griswold, James F. Poage, Ivan P. Polonsky, et al (Macro SNOBOL4)

Philip. L. Budne (CSNOBOL4)

Mark Emmer (code from SNOBOL4+)

Viktors Berstis (code from Minnesota SNOBOL4)

James F. Gimpel (SNOBOL4B)

## BUGS

I/O is still tied to unit numbers.

I/O retains some record oriented flavor (maximum line length on input).

“Dynamic” storage cannot be expanded after startup.

Integer math can never fail, even on overflow.

Oversize integer constants may not be detected.