How to run SNOBOL5 programs


To invoke the Oregon SNOBOL5 interpreter, you enter the command: SNOBOL5 <program.sno> <file-assignments> <options> <:user-string> Where <program.sno> is the name of the file containing the SNOBOL5 program. In Minnesota SNOBOL4 a default extension of .SNO was added to this name unless an extension is explicitly given. SNOBOL5 no longer does that and requires the full file name. The program file is assigned to SNOBOL input/output unit 5 and is equivalent to making a file assignment to input/output unit 5. For example, to run the English parsing program you could use: SNOBOL5 ENGLISH.SNO or SNOBOL5 -5 ENGLISH.sno Where <file-assignments> is one or more unit-number-to-file assignments of the form: -<unit-number> filename <modifiers...> The filename can have file modifiers appended to it (see the section on input/output to see more about the modifiers. It is important to understand that SNOBOL5 uses an "input/output unit number" (or more briefly a "unit number") for every file it reads or writes. A file name is assigned to a unit number either by giving a "file assignment" on the command line, or at run time using the the INPUT() or OUTPUT() functions. To read or write a file, a variable name must be associated with the unit number also. SNOBOL5 has, by default, three preassigned variable names: "INPUT" to unit 5, "OUTPUT" to unit 6 and "PUNCH" to unit 7. Each unit number can be used only for reading or writing but not both at the same time. Unit numbers can be any integer from 1 through 999. The SNOBOL5 source program is read by the compiler using unit 5. Any additional lines of data after the END statement of the program can be read with the input variable "INPUT". For example, the following could be used to print the cross reference for the ENGLISH.SNO program: SNOBOL5 xref.sno -1 english.sno -6 listing.txt Where <options> are either:

1: -d command option sets &DUMP to 1 so that a dump will occur at termination.

2: -v command option causes source listing to be turned on turns listing on initially (-LIST) and sets &STAT to one so that execution statistics are given at the end of the run.

3: --work=nnn[b|k|m|g] command option allocates the specified size of the SNOBOL5 work area. The default is about 8m for 8 megabytes.

4: -ex command option says to execute the program even if there are syntatic errors in the source code.

Where <user-string> is additional information on the command line you may wish to pass to the SNOBOL5 program. The colon ":" keeps SNOBOL5 from looking any further for file assignments or command options. The program can look at this information (as well as the file assignments) using the keyword &PARM which is a string consisting of everything on the command line invoking SNOBOL5 (with token separated with zero bytes). For example the following program residing in file program.sno:

&PARM CHAR(0) ':' REM . X OUTPUT = EVAL(REPLACE(X,CHAR(0),' ')) END would print 132 as the answer to 11 multiplied by 12 when invoked with the command line: SNOBOL5 program.sno :"11 * 12" The quotes are required in Linux to keep the "*" from expanding into all of the current directory's file names.

Example SNOBOL5 run

The SNOBOL5 interpreter is used to run SNOBOL5 programs. The SNOBOL5 source program must be stored in a file, usually a file with an extension of ".sno". An example program resides in the file named english.sno which has its input data following the "END" statement of the SNOBOL5 program. So in the simplest case, when you issue the command:

snobol5 -v english.sno you should get output at the terminal which looks like shown below.

Note that the compilation and execution times are approximate wall clock time (as opposed to cpu time).

* Program to parse simple English sentences with following grammar: 1 N = 'DOG ' | 'CAT ' | 'RAT ' | 'MALT ' 2 V = 'WORRIED ' | 'KILLED ' | 'ATE ' 3 VP = V *NP | V 4 AC = 'THAT ' VP 5 NP = 'THE ' N AC | 'THE ' N 6 S = NP VP 7 8 &FULLSCAN = 1; &ANCHOR = 1; &TRIM = 1 11 NEXT TEXT = INPUT :F(END) 12 (TEXT ' ') S RPOS(0) :F(NO) 13 OUTPUT = '"' TEXT '." IS A SENTENCE.' :(NEXT) 14 NO OUTPUT = '"' TEXT '." IS NOT A SENTENCE.' :(NEXT) 15 END No syntax errors detected in source program "THE DOG ATE THE CAT." IS A SENTENCE. "THE CAT ATE THE RAT." IS A SENTENCE. "THE DOG WORRIED THE CAT THAT ATE THE RAT." IS A SENTENCE. "THE MALT THE ATE DOG." IS NOT A SENTENCE. "THE RAT THAT ATE THE MALT THAT WORRIED THE DOG KILLED THE CAT." IS A SENTENCE. "THE RAT MALT THE MALT THAT DOG THE WORRIED." IS NOT A SENTENCE. "THE RAT THAT ATE THE MALT THAT WORRIED THE DOG KILLED." IS A SENTENCE. Normal termination at level 0 Last statement executed was 11 SNOBOL5 Statistics summary: 0.00105927 Sec. Compilation time (wall clock) 0.000158019 Sec. Execution time (wall clock) 31 Statements executed, 3 Failed 0 Arithmetic operations performed 7 Pattern matches performed 0 Regenerations of dynamic storage 8 Reads performed 7 Writes performed 5097.41 nSec. Average per statement executed (wall clock) Output from ENGLISH.SNO sample program

Input from the keyboard

If "IN" is specified for a filename and the modifier is "-std", the input is from standard input, usually the keyboard. So you could run a simple one line program by typing:

snobol5 -5 IN -std OUTPUT = 123 * 456 ;END However, if no input is specified for unit number 5, then SNOBOL5 defaults to reading from standard input. The above could be more simply: snobol5 OUTPUT = 123 * 456 ;END

Interrupting your program

Sometimes you may wish to stop a running SNOBOL5 program before it is finished. You can do this by pressing the Ctrl-C key. The SNOBOL5 program will then terminate and indicate the statement that it was executing at the time. This is very useful when you suspect that the program is in an infinite loop. You may wish to set the keyword &DUMP = 1 at the beginning of any program you are debugging so that a dump of all of your SNOBOL5 variables is printed at the end of the run, even when ended with Ctrl-Break of Ctrl-C. Sometimes the program may be in some tight state where interrupts are not allowed. To stop the program even in those cases, press Ctrl-C ten times and this will force termination.

Prior Page, Next Page, First Page of the Oregon SNOBOL5 Reference