Lecture 16 – October 19th

 

 

 

Discussed use of:

            SPAN

            BREAK

            ANY

            NOTANY

            GOTOs

 

           

                              Here’s Oct19.sno  - started in 2:00 class & modified in 3:30 class

 

    LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ'-"

          WORD = SPAN(LETTERS)

*

*         produce a suitable pattern in WORD.  To match the material

*         between words (white space, punctuation, etc.), use thepattern:

*

          GAP = BREAK(LETTERS)

         'SAMPLE LINE' WORD . OUTPUT

* 

         'PLUS TEN DEGREES' ' ' WORD . OUTPUT

         'PLUS TEN DEGREES' (' ' WORD) . OUTPUT

          GAPO = GAP . OUTPUT

          WORDO = WORD . OUTPUT

         ': ONE, TWO, THREE' GAPO WORDO GAPO WORDO

          DIGITS = '0123456789'

          INTEGER = (ANY('+-') | '') SPAN(DIGITS)

          'SET -43 VOLTS' INTEGER . OUTPUT

          'SET -43.625 VOLTS' INTEGER . OUTPUT

          REAL = INTEGER '.' (SPAN(DIGITS) | '')

          'SET -43.625 VOLTS' REAL . OUTPUT

          S = '0ZERO,1ONE,2TWO,3THREE,4FOUR,5FIVE,'

          S 4 BREAK(',') . OUTPUT

END         

 

 First 15 minute exercise

Write code to strip the words out of a sentence.  You do not know how many words are in the sentence.  You should output each one as you find it. 

       

         

                         This is Oct19a.sno 

         B = 'The BLUE BIRD'

         COLOR = ('GOLD' | 'BLUE ') . SHADE

         CRITTER = ('FISH' | 'BIRD') . ANIMAL

         BOTH = COLOR CRITTER

         B BOTH

         OUTPUT = SHADE

         OUTPUT = ANIMAL

         OUTPUT = 'Other tests '

         SHADE = 'A'

         ANIMAL = 'B'

         BOTH = CRITTER COLOR

         B BOTH  

         OUTPUT = SHADE

         OUTPUT = ANIMAL

 

         VOWEL = ANY('AEIOU')

         DVOWEL = VOWEL VOWEL

         NOTVOWEL = NOTANY('AEIOU')

         VACUUM = 'VACUUM'

         VACUUM VOWEL . OUTPUT = ''

         VACUUM VOWEL . OUTPUT

         VACUUM DVOWEL . OUTPUT

  

         VACUUM (VOWEL NOTVOWEL) . OUTPUT

 END 

 

                                                                                                                                                                 Arrays in Snobol are indexed only by integers

Unlike Pascal and FORTRAN,  Snobol arrays are potentially hetereogenous

No limit to the number of dimensions

In Snobol an array is defined during program execution, rather than at compilation time.

The ARRAY function initializes all array elements to the null string.

 

Second 15 minute exercise

Write code to strip the words out of  a sentence.  You do not know how many words are in the sentence,  You should declare an array and store each word as you get it in the array.  There will not be more than 15 words.  Print the contents of the array afterwards.

 

Homework:

  1. Study for exam
  2. Search the manual for directions on writing subprograms
  3. Do the Snobol program described below:to:

Write code to strip the words out of  a sentence.  You do not know how many words are in the sentence,  You should declare an array and store each word as you get it, in the array.  There will not be more than 15 words.  Print the contents of the array afterwards.

Then use a subprogram to sort the array in ASCENDING alphabetical order (a..z).  Finally, print the sorted array.  Note:  this is a program!  It requires documentation and comments.  It should be put in the drop box NOT ZIPPED as yourname6.sno.  If your name is longer than 5 characters just use the first 5.  Turn in the printout of the source code your input and the output produced when the program is run with your input in a folder.  Make another folder just in case Pascal Program 3 isn’t graded by class time on Tuesday which is when this program is due.

 

 

  1.