anchor.diff:   *)
   module Regex
     
  -(*
  - * Represents an NFA state plus zero or one or two arrows exiting.
  - * if c == Match, no arrows out; matching state.
  - * If c == Split, unlabeled arrows to out and out1 (if != NULL).
  - * If c < 256, labeled arrow with character c to out.
  - *)
  +/// Represents an NFA state plus zero or one or two arrows exiting.
  +/// if c == Match, no arrows out; matching state.
  +/// If c == Split, unlabeled arrows to out and out1 (if != NULL).
  +/// If c < 256, labeled arrow with character c to out.
   type NFAState=
       | Char of char
       | Match //=256
  
positive.code:     )
      ()
  
  (* Join the two lists l1 and l2, returning the combination. *)
  let append(l1,l2)= l1 @ l2
  
  (*
   * Convert postfix regular expression to NFA.
   * Return start state.
   *)
  let post2nfa (rs:RegexState) (postfix:string):State option=
      let mutable p:string=""
      let stack = new System.Collections.Generic.Stack<Frag>()
  
negative.code:     new () =
          new RegexState({c=Match;out=None;out1=None;lastList=0} (* matching state *), 0)
  
  /// Allocate and initialize State
  let state (g:RegexState) (c:NFAState,out:State option,out1:State option) : State=
      g.nstate_plus_plus()
      let s = { lastList=0; c=c; out=out; out1=out1 }
      s
  
  type RewriteState=
      | State_out1 of State
      | State_out of State
  /// A partially built NFA without the matching state filled in.
  /// Frag.start points at the start state.
  /// Frag.out is a list of places that need to be set to the
  /// next state for this fragment.
  type Frag(start:State, out:RewriteState list)=
      member val start=start
      member val out=out
  
  /// Initialize Frag struct. 
  let frag(start:State, out:RewriteState list)=
      let n=new Frag(start=start, out=out)
      n
  
  /// Create singleton list containing just outp. 
  let list1 (outp:RewriteState) : RewriteState list= 
      [outp]
  /// Patch the list of states at out to point to start.
  let patch (list : RewriteState list, s: State) =
      list |> List.iter (fun next->
          match next with
  