SNOBOL4 - PowerPoint PPT Presentation

About This Presentation
Title:

SNOBOL4

Description:

Programmer-Defined Functions. Array, Table and Defined Data Types. Introduction ... programmer-defined function. DEFINE(PROTOTYPE, ENTRYLABEL) ... – PowerPoint PPT presentation

Number of Views:626
Avg rating:3.0/5.0
Slides: 28
Provided by: Jinhy
Learn more at: https://www.nku.edu
Category:

less

Transcript and Presenter's Notes

Title: SNOBOL4


1
SNOBOL4
  • CSC 507
  • Hwan-Jun, Lee
  • 11/29/2005

2
Content of Presentation
  • Introduction
  • Significant Features of SNOBOL
  • Pattern Matching
  • Primitive Functions
  • Predicates
  • Programmer-Defined Functions
  • Array, Table and Defined Data Types

3
Introduction
  • SNOBOL StriNg Oriented symBOlic
    Language
  • Developed by Ralph Griswold aad associates at
    Bell Labs (where C/C) in 1963
  • SNOBOL is a special purposed language developed
    to provide a powerful means for the manipulation
    of strings of symbols
  • Evolved throughout 1960s ( latest version SNOBOL4
    )

4
Evolution of PLs
5
Significant Features of SNOBOL
  • String Manipulation Operations - allow a string
    to be tested and make replacement.
  • Built-In string pattern-matching examine the
    occurrence of specified pattern.
  • Dynamically Typed
  • No type declaration,
  • No restrictions on the data type of the value
    of any variable.

6
Significant Features of SNOBOL cont
  • Interpretive language compiler translates the
    program into a notation that interpreter execute.
  • Garbage-collected
  • Suitable for text-manipulation and processing
  • Pattern matching, goto and label

7
Pattern Matching
  • Pattern Matching Statement
  • No explicit pattern matching operator
  • Form subject pattern
  • Example
  • TRADE PROGRAMMER
  • TRADE GRAM

8
Pattern Matching cont
  • Replacement Statement
  • Form subject pattern object
  • Example
  • WORD GRID
  • WORD I OU
  • I is replaced by OU
  • WORD gt GROUD

9
Pattern Matching cont
  • Alternation - Builds a new pattern from its
    alternatives.
  • P3 P1 P2
  • Builds a new pattern and assigns it as the value
    of P3.

10
Pattern Matching cont
  • Concatenation Concatenate strings or
    patterns.
  • P6 P4 P5
  • No explicit operator
  • Expressions are separated by one or more blanks.

11
Pattern Matching cont
  • Example
  • P BE BEA BEAR
  • Q RO ROO ROOS
  • R DS D
  • S TS T
  • PAT P R Q S
  • ( same as PAT (P R) (Q S), concatenation has
    higher precedence than alternation )
  • PAT matches the followings
  • BEDS BED BEADS BEAD BEARDS BEARD
  • ROTS ROOT ROT ROOSTS ROOTS ROOST

12
Pattern Matching cont
  • Conditional value Assignment
  • BR (B R) . FIRST
  • Upon successful completion of pattern matching,
    the substring matched becomes
  • the values of FIRST
  • Immediate Value Assignment
  • BR B FIRST E SECOND
  • Whenever B matches, the substring immediately
    becomes the value of FIRST
  • Example
  • BR (B R) . FIRST (E EA) (D
    DS) . LAST
  • BED BR FIRST I LAST ( gt replacement )
  • BED changed into BID

13
Pattern Matching cont
  • Primitive Functions
  • LEN(integer) matches any string of
  • specified length.
  • SPAN(string) - matches runs of characters
  • BREAK(string) matches everything upto.
  • Ex
  • IT RUNS. BREAK( ) SPAN( ) BREAK(.) .
  • gt Pattern matches.

14
Pattern Matching cont
  • Primitive Functions
  • ANY(string) matches any single chracters
  • EX ANY(AEIOU) gtmatch any vowel
  • same as A E I O U
  • NOTANY(string)
  • TAB(interger) matches all characters from the
    current cursor position up to integer

15
Pattern Matching cont
  • Example
  • reformatting 1290 SEP. 27
  • 1293 MAY 20
  • to SEP. 27, 1290
  • MAY 20, 1293

  • ANCHOR 1
  • DATE LEN(4) . YR LEN(4) . MO
    LEN(2) . DAY
  • LOOP CARD INPUT F(END)
  • CARD DATA MO DAY , YR
    F(ERROR)
  • OUTPUT CARD (LOOP)
  • ERROR OUTPUT CARD IMPROPERLY FORMATTED.
    (LOOP)
  • END


16
Primitive Functions
  • LEN(), SPAN(), BREAK(), ANY(), NOTANY(), TAB()
  • IDENT(arg1,arg2)
  • Argument can be any type
  • On success, arg1 becomes the value of function
    call
  • On fail, function call fails.
  • IDENT(APPLE) gt fails
  • IDENT(3, 3.0) gt fails
  • DIFFER(BCD,B CD) gtfails
  • SIZE(abc) gt 3
  • NEW_S REPLACE(S, .,?!, ) gt
    replace all punctuation marks in S with blanks
    and return it.
  • NEW_S TRIM(ABC ) gt remove trailing blanks.
  • DUPL(ABC, 10) gt duplicate ABC 10 times.
  • OUPUT DUPL(DUPL( ,10 SIZE(ABC)) ABC,
    5)
  • gt 5 lines of ABC
  • OUTPUT REMDR(15,2) gt prints 1
  • OUTPUT REMDR(15, -4) gt prints 3 (the sign of
    REMDR is the sign of f.a

17
Predicates
  • Testing relations b/w arguments
  • On success, null for the call
  • GE(17.0, 3) gt succeeds
  • LT(17.0, 3) gt fails
  • EQ(2) gt fails, EQ(2, NULL) EQ(2, 0)
  • Numerical predicates are used for loop
  • LOOP N LT(N, M) N 1 S(LOOP)F(OUT)

18
Programmer-Defined Functions
  • call primitive function DEFINE() to define
  • programmer-defined function.
  • DEFINE(PROTOTYPE, ENTRYLABEL)
  • DEFINE() must be executed before the call is
    made.
  • Example
  • DEFINE(F(X,Y)L1, L2, FENTRY)
  • DEFINE(G(Z), GENT)
  • DEFINE(MARK())

19
Programmer-Defined Functionscont
  • Before execution of function begins
  • The name of the function
  • All formal arguments
  • All local variables are saved
  • It is possible for a function to be recursive
  • New values are assigned to variables as follows
  • The name of the function is assigned null
  • Formal arguments are assigned their values
  • All local variables are assigned null

20
Programmer-Defined Functionscont
  • Example
  • DEFINE(UNION(X,Y)CH,UN)
  • ZSET Z SET1 UNION(SET2, SET3) SET4
  • UN UNION X
  • ULOOP Y LEN(1) . CH F(RETURN)
  • UNION BREAK(CH) S(ULOOP)
  • UNION UNION CH (ULOOP)

21
Programmer-Defined Functionscont
  • Example Decimal to Binary Conversion,
    Using Recursion
  • DEFINE(BINARY(N)) F(BINEND)
  • BINARY BINAY GT(N,1) BINARY(N/2) REMDR(N,2)
  • S(RETURN)
  • BINARY N (RETURN)
  • BINEND
  • GT(N,1) TESTS THE CASES N 0 OR 1
  • N / 2 RETURNS INTEGER

22
Array, Table and Defined Data Types
  • ARRAY(prototype, initValue)
  • Indexing starts at 1
  • Each element may have any type ( integer,
    pattern..
  • VECTOR ARRAY(10)
  • gt one-dimensional array of length 10, null
  • LINE ARRAY(-55)
  • gt one-dimensional array, upper bound 5,
    lower bound -5
  • BOARD ARRAY(3,3,X)
  • gt three-by-three array
  • A1 ARRAY(5)
  • A2 ARRAY(5, A1)
  • Each element of A2 has the same array A1.
  • OUPUT BOARDlt2,3gt gtprints out the value of 2,3
    element

23
Array, Table and Defined Data Types
  • ARRAY
  • A ARRAY(3)
  • B A
  • gt A and B have the same array ( like pointers
    pointing at the same object)
  • COPY function produces a copy of an array.
  • A ARRAY(3)
  • Alt2gt TWO
  • B COPY(A)
  • Blt2gt SIX
  • gt A and B point two distinct physical objects

24
Array, Table and Defined Data Types
  • TABLE(N,M)
  • Default of N,M 10
  • Similar to a one-dimensional array but variable
    in a table can be referenced by an y data object.
    ( array integer reference )
  • N initial size of the table
  • M - of additional variables if needed
  • TABLE(20, 15) gt20, 35, 50,
  • T TABLE()
  • TltAgt 3

25
Array, Table and Defined Data Types
  • Programmer-Defined Data Type
  • DATA(P) defines a new data type.
  • Example
  • DATA(COMPLEX(R,I))
  • gt creates a new type COMPLEX which has
  • two fields (R, I)
  • gt No limit to the number of fields.
  • C COMPLEX(1.5, 2.0)
  • A R(C) gt the first field is referenced
  • R(C) 3.2 gt assign value to the first field

26
SNOBOL4 Interpreters
  • The Minnesota SNOBOL4 Interpreter
  • Runs SNOBOL4 under the IBM Disk Operating System
    (IBM DOS), MS DOS, OS/2, Windows 95 and others.

27
Reference
  • http//www.snobol4.org/
  • http//www.sachsdavis.clara.net
  • http//www.atariarchives.org
  • http//calico.org/journalarticles
Write a Comment
User Comments (0)
About PowerShow.com