

DEFINITION MODULE MYSTR;

(* TYPE CHARSET = SET OF CHAR;                             VERSION SUN *)

FROM SYSTEM  IMPORT UNSIGNED_16;         

CONST                                                      (*  SOLARIS *)
   maxcharsinset= 1024;
   bits= 32;            (* VAX *)(* bits= 16; (* PDP *) *)
   words= maxcharsinset DIV bits;

TYPE  
   CharSet= ARRAY[ 0.. words- 1] OF BITSET;                (*  SOLARIS *)

 (* A 16/32 bit machine is assumed. A set of 256 characters is implemented. *)  

VAR s0: CharSet; (* empty set *)                           (*  SOLARIS *)  



PROCEDURE Append (VAR Res: ARRAY OF CHAR;
                  Source : ARRAY OF CHAR);


PROCEDURE Caps (VAR Source : ARRAY OF CHAR);


PROCEDURE Compare (S1, S2: ARRAY OF CHAR): INTEGER;


PROCEDURE Concat (VAR Res : ARRAY OF CHAR;
                  S1, S2  : ARRAY OF CHAR);


PROCEDURE Copy (VAR Dest : ARRAY OF CHAR;
                Source   : ARRAY OF CHAR);


PROCEDURE Delete (VAR S : ARRAY OF CHAR;
                  index : CARDINAL;
                  len   : CARDINAL);


PROCEDURE Insert (VAR Res : ARRAY OF CHAR;
                  Source  : ARRAY OF CHAR;
                  Pos     : CARDINAL);


PROCEDURE Item (VAR R : ARRAY OF CHAR;
                S     : ARRAY OF CHAR;
                T     : CharSet;
                N     : CARDINAL);


PROCEDURE ItemS (VAR R : ARRAY OF CHAR;
                 S     : ARRAY OF CHAR;
                 T     : ARRAY OF CHAR;
                 N     : CARDINAL      );


PROCEDURE Length (S : ARRAY OF CHAR): CARDINAL;


PROCEDURE Match (Source, Pattern : ARRAY OF CHAR) : BOOLEAN;


PROCEDURE Slice (VAR R: ARRAY OF CHAR;
                 S    : ARRAY OF CHAR;
                 P, L : CARDINAL);


PROCEDURE Subst (VAR Source : ARRAY OF CHAR;
                 OldPattern : ARRAY OF CHAR;
                 NewPattern : ARRAY OF CHAR);


PROCEDURE Position (Substring  : ARRAY OF CHAR;
                    Source     : ARRAY OF CHAR;
                    at         : CARDINAL;
                    VAR pos    : UNSIGNED_16;
                    VAR found  : BOOLEAN );


PROCEDURE StrToInt
      (S : ARRAY OF CHAR;  b : INTEGER;  VAR OK : BOOLEAN) : LONGINT;


(********************** SET OF CHAR (SOLARIS)**********************)

PROCEDURE set (VAR s: CharSet; 
               ch   : CHAR);

PROCEDURE setn (VAR s: CharSet; 
                ch   : ARRAY OF CHAR);

PROCEDURE inset (VAR s: CharSet; 
                 ch   : CHAR): BOOLEAN;

PROCEDURE insetn (VAR s: CharSet; 
                  ch   : ARRAY OF CHAR): BOOLEAN;

PROCEDURE addset (VAR s,s1,s2: CharSet);

PROCEDURE inclset (VAR s,s1: CharSet);

PROCEDURE subset (VAR s,s1,s2: CharSet);

PROCEDURE exclset (VAR s,s1: CharSet);

PROCEDURE genset (VAR s,s1: CharSet; 
                  ch      : CHAR);

PROCEDURE gensetn (VAR s,s1: CharSet; 
                   ch      : ARRAY OF CHAR);

PROCEDURE InCharSet (CH: CHAR; 
                     S :  CharSet): BOOLEAN;
   (*  InCharSet is true if and only if CH belongs to S. *)

PROCEDURE CharSetUnion (A    : CharSet; 
                        B    : CharSet; 
                        VAR C: CharSet);
   (* C becomes the union of A and B. *)

PROCEDURE CharSetDifference (A    : CharSet; 
                             B    : CharSet; 
                             VAR C: CharSet);
   (* C becomes the set difference of A and B  (C=  A`B). *)

PROCEDURE CharSetIntersection (A    : CharSet; 
                               B    : CharSet; 
                               VAR C: CharSet);
   (* C becomes the intersection of A and B. *)

PROCEDURE CharSetSymmetricDifference (A    : CharSet; 
                                      B    : CharSet; 
                                      VAR C: CharSet);
   (* C becomes the symmetric differende of A and B. *)

PROCEDURE DefineCharSet (Constructor    : ARRAY OF CHAR; 
                         VAR S          : CharSet;
                         VAR ErrorNumber: CARDINAL);
   (*  Defines the set of characters S by means of Constructor.

     The syntax of Constructor in EBNF notation is:

     Set=            ElementarySet {',' ElementarySet}
     ElementraySet=  [ PointSet [ '..' PointSet ] ]
     PointSet=       '(' CHAR ')' | '[' Number ']'
     Number=         [ Digit ] [ Digit ] Digit

     The meanings of PointSet and ElementarySet are:

     PointSet

     a set with one element.  As an instance both (0) and [48] denote
     the character '0', if the ordinals follow the ASCII convention.

     ElementarySet

     a simply connecetd set of characters.  As an instance [49]..[55] or
     (1)..(7) or [49]..(7) or (1)..[55] all denote the set of all characters
     between '1' and '7'.

     Remark: blank, which are not enclosed in parentheses are ignored.

     Examples:

     DefineCharSet('(a), (f), (r)..(z)', S, ErrorNumber) defines S as
     the set containing the characters 'a', 'f' and all characters
     between 'r' and 'z'.

     DefineCharSet('[48]..[57], ( ), (A)..(Z), (.)', S, ErrorNumber) defines
     S as the set of all numerals, blank, all upper case characters and
     the point.

     ErrorNumber reports errors which occur when Constructor does not
     follow the syntax, given above.

     0)   No error
     1)   Extra garbage in Constructor.
     2)   Two points are required to separate PointSets when building
          an ElementarySet.
     3)   Unexpected end of Constructor.
     4)   ) Expected.
     5)   ] Expected.
     6)   Digit expected.
     7)   Number too large.

 *)

END MYSTR.
