How to run SNOBOL4 programs


To invoke the Minnesota SNOBOL4.2 interpreter, you enter the DOS command: SNOBOL4 <program> <file-assignments> <options> <;user-string> Where <program> is the name of the file containing the SNOBOL4.2 program. A default extension of .SNO is added to this name unless an extension is explicitly given. Therefore the name "mypgm" will case SNOBOL4.2 to read "mypgm.sno" and "mypgm.x" will cause it to read "mypgm.x". The program file is attached to 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: SNOBOL4 ENGLISH or SNOBOL4 ENGLISH.SNO or SNOBOL4 5=ENGLISH or SNOBOL4 5=ENGLISH.SNO or SNOBOL4 and be prompted for the program file. Where <file-assignments> is one or more unit-number-to-file assignments of the form: <unit-number=filename>. The filename can have file modifiers appended to it (see #### section below on file modifiers). It is important to understand that SNOBOL4 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 DOS command line invoking DOS, or at run time using the fourth parameter of the INPUT or OUTPUT functions. To read or write a file, a variable name must be associated with the unit number also. SNOBOL4 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 32. The SNOBOL4 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: SNOBOL4 XREF 1=ENGLISH.SNO 6=LPT1 Where <options> are either /Q for quiet or /D for dump or both:

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

2: /Q command option (quiet) causes no information about file assignments to be displayed, turns listing off initially (-UNLIST) and sets &STAT to zero so that no execution statistics are given.

Where <user-string> is additional information on the command line you may wish to pass to the SNOBOL4.2 program. The semicolon ";" keeps SNOBOL4.2 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 after the command SNOBOL4. For example the following program residing in file program.sno:

&PARM ';' REM . X OUTPUT = EVAL(X) END would print 132 as the answer to 11 multiplied by 12 when invoked with the command line: SNOBOL4 program /q;11 * 12

Example SNOBOL4 run

The command SNOBOL4 is used to run SNOBOL4 programs. The 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. So in the simplest case, when you issue the command:

snobol4 english you should get output at the terminal which looks like Figure 1.

Note that the compilation and execution times are real time (as opposed to cpu time) and include any waiting time during input or output.

The Minnesota SNOBOL4.2 Interpreter: Version 2.03 (C)Copyright Viktors Berstis 1984, 1996, all rights reserved. Command parameter string &PARM = " english.sno " Size of dynamic storage area in bytes = 477216 Floating point available, math co-processor present I/O unit number 5 assigned to english.sno * Program to parse simple English sentences with following grammar: 1 Noun = 'DOG ' | 'CAT ' | 'RAT ' | 'MALT ' 2 Verb = 'WORRIED ' | 'KILLED ' | 'ATE ' 3 Verb.Phrase = Verb *Noun.Phrase | Verb 4 Adjective.Clause = 'THAT ' Verb.Phrase 5 Noun.Phrase = 'THE ' Noun Adjective.Clause | 'THE ' Noun 6 Sentence = Noun.Phrase Verb.Phrase 7 8 &FULLSCAN = 1; &ANCHOR = 1; &TRIM = 1 11 NEXT TEXT = INPUT :F(END) 12 (TEXT ' ') Sentence 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 SNOBOL4.2 Statistics summary: 60 MS. Compilation time 30 MS. Execution time 31 Statements executed, 3 Failed 0 Arithmetic operations performed 7 Pattern matches performed 0 Regenerations of dynamic storage 8 Reads performed 7 Writes performed
Figure 1. Output from ENGLISH.SNO sample program

Input from the keyboard

If CON: is specified for a filespec, the input is from the keyboard (and output is to the display monitor screen). When SNOBOL4 is ready for some input from the keyboard, a question mark appears on the screen. You can then enter a line of data and press the return key when you have finished typing the line. The DOS editing functions are available when you enter this line. This means that you can backspace to correct characters, for example. See the DOS manual for a complete description of these editing functions.

To indicate an end of file from the keyboard, press the Ctrl key and while holding it down press the Z key.

Interrupting your program

Sometimes you may wish to stop a running SNOBOL4 program before it is finished. You can do this by pressing the Ctrl key and while holding it down, pressing the Break key. The SNOBOL4 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 SNOBOL4 variables is printed at the end of the run, even when ended with Ctrl-Break.

Prior Page, Next Page, First Page of the Minnesota SNOBOL4 Reference