Docsity

SNOBOL Issues - Programming Languages - Lecture Slides, Slides of Programming Languages

Partial preview of the text

Download SNOBOL Issues - Programming Languages - Lecture Slides and more Slides Programming Languages in PDF only on Docsity!

Indirect Reference

MONTH = ‘APRIL’

$MONTH = ‘FOOL’

APRIL = ‘FOOL’

Unary operator $operand

Is equivalent to saying

Indirect Reference

RUN = 10

WORD = ‘RUN’

$(WORD) = $(WORD) + 1

Increments the value of RUN

Functions

  • Primitive
    • Built into the language
  • User defined
    • Defined by the programmer

Functions

PART1 = “NUT”

OUTPUT = SIZE(PART1)

PART2 = “BOLT”

N = 64

OUTPUT = SIZE(‘PART’ N + 36)

SIZE(TEXT)

OUTPUT = 3

OUTPUT = 7 PART100 64+36 = 100

Arrays

  • Data stored in an array is not necessarily of the same type

V = ARRAY(10, 1.0)

  • creates and assigns to V a one-dimensional array of 10 elements, eachassigned to the real value of 1.

X = ARRAY(‘2:9’)

  • creates a one-dimensional array X of 8 elements with the lower index being2 and the upper index being 9

N = ARRAY(‘3,5’)

  • Creates a two dimensional array of 3 x 5
  • Each cell is initialized to NULL string A = ARRAY(INPUT)
  • Size and initial value of the array is determined by the input

Example

&TRIM = 1

i = 1 ST = ARRAY(INPUT)

MORE ST = INPUT :F(GO)

i = i + 1 :(MORE)

GO

ST<1> = input from user

When index ‘i’ exceeds its range, jump to label ‘GO’

Take input from user

Example

&TRIM = 1 WORDPAT = BREAK(&LCASE &UCASE) SPAN(&LCASE &UCASE "'-"). WORD COUNT = ARRAY('3:9',0) READ LINE = INPUT :F(DONE) NEXTW LINE WORDPAT = :F(READ) COUNT<SIZE(WORD)> = COUNT<SIZE(WORD)>+ 1 :(NEXTW) DONE OUTPUT = "WORD LENGTH NUMBER OF OCCURRENCES" I = 2 PRINT I = I + 1 OUTPUT = LPAD(I,5) LPAD(COUNT,20) :S(PRINT) END

SNOBOL Features

  • Dynamic typing
  • Mixing arithmetic and string operations
  • String operations including concatenation
  • GOTO control structure
  • Overloaded operators
  • ‘$’, ‘space’ as an operator
  • Run-time compilation
    • code can be embedded in data, allowing easy run-time extension of programs
  • Variable length strings
  • Array tables and record type objects
  • Absence of declaration

Issues

  • Crucial aspects of development process, such as documentation, were overlooked
  • The lack of formal documentation led the initial version of SNOBOL to minimal use
  • Another design problem was that developers treated language semantics casually. Such a poor practice hindered other programmers from understanding the meaning of the program

Issues

  • Choice of operators
  • Poor readability and writability
  • Dynamic typing – debugging was difficult
  • Mixing arithmetic and string operations
  • String operations including concatenation
  • GOTO control statements
  • Overloaded operators