The text of the statements is assumed to be in columns 1 through 255 inclusive. The remaining data on the line is ignored. Labels always start in column one, must begin with an alphabetic character and end with the first blank. An asterisk (*) or vertical bar (|) in column one indicates that this is a comment line. A plus (+) or period (.) in column one indicates this is a continuation line for the previous statement (ignoring intermediate comment lines). A token (such as a name or string) cannot be split across a line boundary. A minus (-) in column one indicates that a listing control word follows the minus with no blank:
There is actually only one kind of SNOBOL4 statement. It just has many optional parts which cause various actions. Figure 2 gives the syntax for a SNOBOL4 program. The lower case names are metasymbols. The ::= indicates the definition of the metasymbol on the left is given on the right. The brackets [ ] indicate that what is contained within them is optional. Three dots after an item indicates repetition. The vertical bar "|" indicates choice between alternatives. The quoted strings indicate actual terminal text.
The label is always optional. The special label END marks the end of the program and must have no statement.
The goto is always optional and specifies where to go after the statement has been executed:
Numeric literals are just a series of digits. Floating point literals contain a decimal point but cannot begin with a decimal point (E notation as in FORTRAN is not valid). Character string literals must either start with a single or double quote and end with the same kind of quote. To embed quotes within character string literals, you must use the other kind of quote. For example the following concatenated literals:
Expressions follow the usual rules of other languages except that binary infix operators must have at least one blank on each side of the operator, and that unary prefix operators must have at least one blank on the left and no blanks on the right. Also a series of one or more blanks with no operator symbol implies the concatenation operator.
The pattern in a statement is optional and is delimited by the first zero level (parenthesis level) blank following the subject. The pattern is matched against the subject and if the match fails, the statement fails. If the match succeeds and there is no = with optional object, the statement succeeds. If the match succeeds and there is an = with optional object, the object is evaluated, and if the evaluation succeeds, the portion of the subject matched by the pattern is replaced by the object and the statement succeeds. If the evaluation of the object fails, the statement fails. If the object is missing but the = is present, then the value of the object is the null string.
If there is no pattern, the subject is evaluated and if it succeeds, then the object is evaluated (if present) and assigned to the subject (if object present). Otherwise the statement fails. If assignment is being performed, the subject must be a name. Note that if there is no pattern, and if the subject consists of concatenated parts, it must be enclosed in parenthesis.
The order of operations within expressions is according to precedence, parenthesis, deferral (see * prefix operator) and otherwise left to right. Expressions in statements are evaluated as follows during execution:
Prior Page, Next Page, First Page of the Minnesota SNOBOL4 Reference