Notes compiled by Professor Elizabeth Adams from

The SNOBOL4 PROGRAMMING LANGUAGE , 2ND edition, by Griswold, Poage, & Polansky

 

Developed  at Bell Telephone Laboratories, Incorporated in 1962 by Ralph Griswold

 

 

four types of statements

  1. assignment statement
    • simple shown in first.sno
    • input and output with looping shown in second.sno

                                                               i.      labels start in column 1

                                                             ii.      success, failure statements:      :S(gohere)F(gothere)

                                                           iii.      loop:     (gotolabel)

                                                            iv.      to indicate end of keyboard input:        <ctrl> z

  1. pattern matching statement
    • has form  subject pattern                      shown in four.sno
    • pattern formed by concatenation does not need parentheses  shown in five.sno
    • subject formed by concatenation does need parentheses  shown in six.sno
    • patterns can be formed by alternation as well as concatenation   shown in nine.sno
  2. replacement statement
    • has form subject pattern = object  shown in seven.sno
    • can delete by having object as null shown in eight.sno
  3. end statement
    • end in column 1

 

Comments require an * in column 1 and the entire line is a comment

 

to run:              snobol4 filename.sno

to run and produce lst file  snobol4 /L filename.sno  (see three.lst)

to indicate end of keyboard input:        <ctrl> z

 

 

conditional value assignment

  • pattern . variable
  • . associates to the left and has higher precedence than concatenation and alternation
  • you know when . is an operator because it has to be surrounded by blanks when it is

 

flow of control

  • shown in previous programs

 

 

indirect reference

  • shown by the unary operator #
  • given
    • month - 'april'
    • $month = 'cruel' is equivalent to april = 'cruel'

 

primitive functions - NOTE: arguments to all functions are passed by value

  • SIZE -form: SIZE (string_literal_or_string_variable_or_string_expression) - has a single string argument and returns as value the integer specifying the number of characters in the string
  • DUPL. - form : DUPL (string, integer) - has two arguments a string and an integer and returns as value a string that consists of  a number of duplications of the string argument; returns the null string if the second argument is 0; fails it the second argument is negative.
  • DEFINE - will be discussed shortly
  • DATA - will be discussed shortly
  • ARRAY - will be discussed shortly
  • TABLE - will be discussed shortly

 

 

predicates

  • is a function or operation that returns the null string as value if a given condition is satisfied. Otherwise it fails.
  • LE  (all of the relational predicates only work properly with numbers
    • LE(Number1,Number2)
      • returns the null string if Number1 is less than or equal to Number2
  • LT
  • DIFFER
    • DIFFER(ST1, ST2)
      • returns the null string as value if the values of the two aguments are not identical

 

user defined functions

  • form:  define(function prototype, entry point)
  • prototype is like the ada specification
  • function returns value by assigning value to be returned to function name
  • return from a function is accomplished by transfer to system label return
  • if the second argument is omitted from the define, the entry point is the same as the function name

 

keywords

  • &dump = 1
    • if value of &dump is nonzero when program terminates, dump of natural variables is produced
  • &trim = 1
    • if the value of &trim is nonzero, trailing blanks from input string are deleted
    • note that input string, by default, is 80 characters long

 

 

 

 

 

arrays

  • can be created using the primitive function ARRAY
  • V = ARRAY(10,1.0)
    • assigns to V a on dimensional array of 10 variables each initialized to 1.0
    • elements referenced as V<I> where I in range 1..10
  • N = ARRAY('3,5')
    • assigns to N a two dimensional array of variables having null string as initial values

 

tables

  • like arrays but indexes can be any data object
  • T = TABLE()
    • creates a table and assigns it as a value of T
  • T<'B'> = 5
    • assigns value 5 to element T<'B'>
  • tables have varying length and are dynamically extended if necessary
  • can specify initial table size by
    • S = TABLE(N)

 

programmer-defined data types

  • DATA ('NODE(VALUE,LINK)')  is an example of a node consisting of  a value field and a link field
  • P = NODE ('S',)
    • creates a node with a value field S and the null string in the link
    • P is a data object with two fields that can be reference by means of function calls
      • VALUE(P)
      • LINK(P)
  • P = NODE ('T',P)
    • inserts a node with value T at the head of the list
  • P = LINK(P)
    • deletes a note from the head of the list

 

Excerpted from GenTran.doc which comes from Vanilla Snobol

 

%TRIM           -- Trims trailing spaces from all lines (the default).

 

%LTRIM          -- Trims leading spaces and tabs from all lines.

 

%ATRIM          -- Trims both leading and trailing spaces from all lines.

                   The same as entering:

                   %TRIM

                   %LTRIM

                   in the .TTI file.

 

%COMPRESS       -- Compresses multiple spaces and tabs from all lines.

 

%COLLAPSE       -- Trims leading and trailing spaces and compresses multiple

                   spaces and tabs from all lines.

                   The same as entering:

                   %TRIM                                %ATRIM

                   %LTRIM               or              %COMPRESS

                   %COMPRESS

 

%TRACE          -- Displays the result of the translation to the terminal,

                   in addition to writing the translation to the output

                   file.

 

Binary Operators file

 

Data Type Conversions

 

Error Messages