* First Snobol example 10/22/2002 * * in column-1: Comment * + in column-1: Continuation line when the current line * is a continuation of a statement that started * on a previous line * ;* The rest of the line is a comment. * Notice there is no space between the two. * A label of a statement must appear starting in column-1 * Four types of statements: * Label statement :(GOTO) :F(GOTO) :S(GOTO) * 1. assignment like * InX = input ;* a 80-column input line is read * output = Inx "Results of:" 100 / 2 * 2 - 10 + 20 * pat = 'A' | 'B' | 'A' "B" * RecPatt = pat | *RecPatt pat * 2. Pattern Matching * "SUBJECTSTRINGABC" pat ;* Success if &Anchor=0 * "LAMARUNIVERSITY" RecPatt ;* Success if &Anchor=0 * 3. Replacement (Pattern matching with replacement) * Subject = "(A+B)*(B+C*D)" * Subject Bal = "()" ;* Subject will become '()*(B+C*D)' * ;* Bal is a primitive pattern structure * that matches any of, if unanchored, * (A+B) * (A+B)* * (A+B)*(B+C*D) ;* Only first three if anchored * A * A+ * A+B * + * +B * B * * * (B+C*D) * B ;* And still some more * 4. End ;* must appear at the end of a program in * ;* columns 1-3 as if it were a label Subject = '((A+B)*D)*F' &anchor = 0 ;* Default output = "CHECKING THE POWER OF 'BAL' STRUCTURE" output = "SUBJECT STRING IS:::" SUBJECT subject bal $ output fail ;* Immediate assignment end