Previous Previous chapter · Next Next chapter · Contents Table of Contents

Chapter 4 : OPERATORS

Following are lists of all the unary and binary operators in SNOBOL4. Unused operators may be attached to program-defined functions using the OPSYN function. Unary operators have equal precedence among themselves, and higher precedence than binary operators. Operators of higher precedence are performed first, unless reordered by parentheses. Where several instances of operators with the same priority appear, associativity specifies which one is performed first.

4.1 UNARY OPERATORS

All unary operators are left-associative: if several appear together, they are performed left-to-right.
    Graphic        Name                  Definition
    =======  =================    ==============================
      +      plus                 arithmetic positive
      -      minus                arithmetic negative
      .      period               name of object (address)
      $      dollar sign          indirect reference through object
      *      asterisk             unevaluated expression
      &      ampersand            keyword
      ~      tilde                negation of success/failure
      ?      question mark        interrogation
      @      at sign              cursor position assignment
      /      slash                <none>
      ^, !   caret, exclamation   <none>
      %      percent              <none>
      #      pound sign           <none>
      |      vertical bar         <none>

4.1.1 Indirect Reference and Case-Folding

The indirect reference operator ($) converts a string to a variable name. When case-folding is in effect, the string characters are treated as upper-case letters when producing the name. The string itself is not modified. Thus,

    $('abc')
references variable ABC when case-folding, and variable abc when not.

4.2 BINARY OPERATORS

    Graphic    Name            Definition       Precedence Associates
    ======= =================  ===============  ========== ==========
      ~     tilde              <none>                 12      right
      ?     question mark      <none>                 12      left
      .     period             conditional assignment 11      left
      $     dollar sign        immediate assignment   13      left
      ^, !  caret, exclamation exponentiation         12      right
      **    double asterisk    exponentiation         12      right
      %     percent            <none>                 11      left
      *     asterisk           multiplication         10      left
      /     slash              division                9      left
      #     pound sign         <none>                  8      left
      +     plus               addition                7      left
      -     minus              subtraction             7      left
      @     at sign            <none>                  6      left
      blank blank              concatenation           5      left
      tab   tab                concatenation           5      left
      |     vertical bar       alternation             4      left
      &     ampersand          <none>                  3      left
      =     equal sign         assignment              1      right

Previous Previous chapter · Next Next chapter · Contents Table of Contents