anchor.diff:                      setU.[index].Add (key, t)
                   setR.Enqueue(cntxt)  
           
  -        let getNodeP label (left : ExtensionTree) (right : ExtensionTree) =      
  -            let rExt = right.extension
  -            let condTemp = right.tree = null
  -            let mutable result = dummyAST
  -            if left.tree <> null
  -            then
  -                let lExt = left.extension
  -                if condTemp
  -                then
  -                    result <- new ExtensionTree(packExtension (getLeftExtension lExt) (getRightExtension lExt), (new IntermidiateNode(left.tree, right.tree, label)))
  -                else 
  -                    result <- new ExtensionTree(packExtension (getLeftExtension lExt) (getRightExtension rExt), (new IntermidiateNode(left.tree, right.tree, label)))
  +    let getNodeP label (left : ExtensionTree) (right : ExtensionTree) =      
  +        let rExt = right.extension
  +        let condTemp = right.tree = null
  +        let mutable result = dummyAST
  +        if left.tree <> null
  +        then
  +            let lExt = left.extension
  +            if condTemp
  +            then
  +                result <- new ExtensionTree(packExtension (getLeftExtension lExt) (getRightExtension lExt), (new IntermidiateNode(left.tree, right.tree, label)))
               else 
  -                result <- new ExtensionTree(packExtension (getLeftExtension rExt) (getRightExtension rExt), (new IntermidiateNode(left.tree, right.tree, label)))
  -            result
  +                result <- new ExtensionTree(packExtension (getLeftExtension lExt) (getRightExtension rExt), (new IntermidiateNode(left.tree, right.tree, label)))
  +        else 
  +            result <- new ExtensionTree(packExtension (getLeftExtension rExt) (getRightExtension rExt), (new IntermidiateNode(left.tree, right.tree, label)))
  +        result
                   
               
  -        let getNodeT index =
  -            if terminalNodes.Item index = Unchecked.defaultof<ExtensionTree>
  -            then
  -                let tree = new TerminalNode(index)
  -                let result = new ExtensionTree(packExtension index (index + 1), tree)
  -                terminalNodes.Set index result
  -                result
  -            else terminalNodes.Item index            
  +    let getNodeT index =
  +        if terminalNodes.Item index = Unchecked.defaultof<ExtensionTree>
  +        then
  +            let tree = new TerminalNode(index)
  +            let result = new ExtensionTree(packExtension index (index + 1), tree)
  +            terminalNodes.Set index result
  +            result
  +        else terminalNodes.Item index            
               
  -        let containsGSSNode l i =  
  -            let curLevel = gss.[i]
  -            let index = curLevel.FindIndex (fun v -> v.Label = l)
  -            if index = -1
  -            then
  +    let containsGSSNode l i =  
  +        let curLevel = gss.[i]
  +        let index = curLevel.FindIndex (fun v -> v.Label = l)
  +        if index = -1
  +        then
                      
  -                curLevel.Add <| new Vertex(i, l)   
  -                packVertex i (curLevel.Count - 1)
  -            else packVertex i index
  -
  -        let containsEdge (b : int64<vertex>) (e : int64<vertex>) (ast : INode) =
  -            let edges = gss.[getIndex2Vertex b].[getIndex1Vertex b].OutEdges
  -            edges.first <> Unchecked.defaultof<_> && (edges.first.Dest = e || (edges.other <> null && edges.other |> Array.exists (fun edge ->  edge.Dest = e)))
  -
  -        let findTree prod extension (family : Family) =            
  -            let result = 
  -                if astDictionary.ContainsKey extension
  +            curLevel.Add <| new Vertex(i, l)   
  +            packVertex i (curLevel.Count - 1)
  +        else packVertex i index
  +
  +    let containsEdge (b : int64<vertex>) (e : int64<vertex>) (ast : INode) =
  +        let edges = gss.[getIndex2Vertex b].[getIndex1Vertex b].OutEdges
  +        edges.first <> Unchecked.defaultof<_> && (edges.first.Dest = e || (edges.other <> null && edges.other |> Array.exists (fun edge ->  edge.Dest = e)))
  +
  +    let findTree prod extension (family : Family) =            
  +        let result = 
  +            if astDictionary.ContainsKey extension
  +            then
  +                let a = astDictionary.[extension]
  +                let eq (fam : Family) =
  +                    fam.prod = family.prod
  +                    && obj.ReferenceEquals(fam.node, family.node)                    
  +                    
  +                if not (eq a.first || (a.other <> null && a.other |> Array.exists eq))
                   then
  -                    let a = astDictionary.[extension]
  -                    let eq (fam : Family) =
  -                        fam.prod = family.prod
  -                        && obj.ReferenceEquals(fam.node, family.node)                    
  -                    
  -                    if not (eq a.first || (a.other <> null && a.other |> Array.exists eq))
  -                    then
  -                        if a.other <> null
  -                        then a.other <- Array.append a.other [|family|]
  -                        else a.other <- [|family|]
  -                    a
  -                else
  -                    let value = new AST(family, null)
  -                    astDictionary.Add(extension, value)
  -                    value
  +                    if a.other <> null
  +                    then a.other <- Array.append a.other [|family|]
  +                    else a.other <- [|family|]
  +                a
  +            else
  +                let value = new AST(family, null)
  +                astDictionary.Add(extension, value)
  +                value
               
  -            result
  -
  -        let create label (u : int64<vertex>) (index : int) (ast : ExtensionTree) = 
  -            let v = containsGSSNode label index
  -            if not (containsEdge v u ast.tree)
  -            then
  -                let newEdge = new Edge(u, ast)
  -               // edges.[gss.[getIndex2Vertex v].[getIndex1Vertex v].Level,gss.[getIndex2Vertex u].[getIndex1Vertex u].Level].Add(newEdge)
  -                if setP.ContainsKey v
  +        result
  +
  +    let create label (u : int64<vertex>) (index : int) (ast : ExtensionTree) = 
  +        let v = containsGSSNode label index
  +        if not (containsEdge v u ast.tree)
  +        then
  +            let newEdge = new Edge(u, ast)
  +            // edges.[gss.[getIndex2Vertex v].[getIndex1Vertex v].Level,gss.[getIndex2Vertex u].[getIndex1Vertex u].Level].Add(newEdge)
  +            if setP.ContainsKey v
  +            then
  +                let trees = setP.[v]
  +                let handleTree ast2 =
  +                        
  +                    let y = getNodeP label ast ast2
  +                    addContext label (getRightExtension ast2.extension) u y      
  +                trees |> ResizeArray.iter handleTree
  +            let vertex = gss.[getIndex2Vertex v].[getIndex1Vertex v]     
  +            if vertex.OutEdges.first <> Unchecked.defaultof<_>
  +            then
  +                if vertex.OutEdges.other <> null
  +                then vertex.OutEdges.other <- Array.append vertex.OutEdges.other [|newEdge|]
  +                else vertex.OutEdges.other <- [|newEdge|]
  +            else vertex.OutEdges.first <- newEdge
  +        v
  +
  +    let pop (u : int64<vertex>) (i : int) (z : AST) extension =
  +        let temp = 0
  +        if not (u = dummyGSSNode)
  +        then
  +            let vertex = gss.[getIndex2Vertex u].[getIndex1Vertex u]
  +            let temp = new ExtensionTree(extension, z)
  +            let label = vertex.Label
  +            if setP.ContainsKey u           //вот тут можно попробовать какой-нибудь tryGet
  +            then
  +                setP.[u].Add(temp)
  +            else 
  +                let value = new ResizeArray<ExtensionTree>(5)
  +                value.Add(temp)
  +                setP.Add(u, value)
  +            let processEdge (edge : Edge) =
  +                if not <| obj.ReferenceEquals(edge.Ast, dummyAST)
                   then
  -                    let trees = setP.[v]
  -                    let handleTree ast2 =
  -                        
  -                        let y = getNodeP label ast ast2
  -                        addContext label (getRightExtension ast2.extension) u y      ////ast2 or ast!!! temp
  -                    trees |> ResizeArray.iter handleTree
  -                let vertex = gss.[getIndex2Vertex v].[getIndex1Vertex v]     
  -                if vertex.OutEdges.first <> Unchecked.defaultof<_>
  -                then
  -                    if vertex.OutEdges.other <> null
  -                    then vertex.OutEdges.other <- Array.append vertex.OutEdges.other [|newEdge|]
  -                    else vertex.OutEdges.other <- [|newEdge|]
  -                else vertex.OutEdges.first <- newEdge
  -            v
  -
  -        let pop (u : int64<vertex>) (i : int) (z : AST) extension =
  -            let temp = 0
  -            if not (u = dummyGSSNode)
  -            then
  -                let vertex = gss.[getIndex2Vertex u].[getIndex1Vertex u]
  -                let temp = new ExtensionTree(extension, z)
  -                let label = vertex.Label
  -                if setP.ContainsKey u           //вот тут можно попробовать какой-нибудь tryGet
  -                then
  -                    setP.[u].Add(temp)
  -                else 
  -                    let value = new ResizeArray<ExtensionTree>(5)
  -                    value.Add(temp)
  -                    setP.Add(u, value)
  -                let processEdge (edge : Edge) =
  -                    if not <| obj.ReferenceEquals(edge.Ast, dummyAST)
  -                    then
  -                        let y1 = getNodeP label edge.Ast temp
  -                        addContext label i edge.Dest y1
  -                    else addContext label i edge.Dest (new ExtensionTree(extension, z))  
  -                processEdge vertex.OutEdges.first
  -                if vertex.OutEdges.other <> null 
  -                then vertex.OutEdges.other |> Array.iter processEdge
  -        let getIndex nTerm term = 
  -            let mutable index = nTerm
  -            index <- (index * (parser.IndexatorFullCount - parser.NonTermCount))
  -            index <- index + term - parser.NonTermCount
  -            index
  -        let curToken = parser.TokenToNumber tokens.[!currentIndex]
  -        let table = parser.Table
  -        let test nonTerm funName =
  -            if Array.exists (fun e -> e = funName) table.[getIndex nonTerm curToken]
  -            then
  -                true
  -            else false
  -
  -let buildAst<'TokenType> (parser : ParserSource2<'TokenType>) (tokens : seq<'TokenType>) (functions : (int -> int64<vertex> -> ExtensionTree -> ExtensionTree -> unit)[]) : ParseResult<_> = 
  -    let tokens = Seq.toArray tokens
  -    let inputLength = Seq.length tokens
  -    let nonTermsCountLimit = 1 + (Array.max parser.LeftSide)
  -    let resultAST = ref None
  -    let getEpsilon =
  -
  -         let epsilons = Array.init nonTermsCountLimit (fun i -> box (-i - 1))
  -         fun i -> epsilons.[i]
  -    if inputLength = 0 || parser.IndexEOF = parser.TokenToNumber tokens.[0] then
  -//        if parser.AcceptEmptyInput then
  -//            Success (new Tree<_>(null, getEpsilon startNonTerm, null))
  -//        else
  -        Error ("This grammar does not accept empty input.")     
  -    else
  -        let epsilon = new TerminalNode(-1)
  -        let setR = new Queue<Context>()   
  -        let setP = new System.Collections.Generic.Dictionary<int64<vertex>,ResizeArray<ExtensionTree>> ()
  -        let astDictionary = new System.Collections.Generic.Dictionary<int64<key>, AST> ()
  -        let setU = Array.init (inputLength + 1) (fun _ -> new Dictionary<_*_, ResizeArray<INode>>())
  -            
  -        let currentIndex = ref 0
  -
  -        let currentrule = parser.StartRule
  -        let dummy = null
  -        let dummyGSSNode = new Vertex(!currentIndex, (packLabel -1 -1))
  -        let currentLabel = ref <| packLabel currentrule 0
  -        let dummyAST = new ExtensionTree(packExtension -1 -1, dummy)
  -        let dummyFam = Family()
  -        let currentN = ref <| dummyAST
  -        let currentR = ref <| dummyAST
  -       // let edges = Array2D.init inputLength inputLength (fun _ _ -> new ResizeArray<Edge>())
  - 
  -        let gss = Array.init inputLength (fun _ -> new ResizeArray<Vertex>())
  +                    let y1 = getNodeP label edge.Ast temp
  +                    addContext label i edge.Dest y1
  +                else addContext label i edge.Dest (new ExtensionTree(extension, z))  
  +            processEdge vertex.OutEdges.first
  +            if vertex.OutEdges.other <> null 
  +            then vertex.OutEdges.other |> Array.iter processEdge
  +   
  +    let getIndex nTerm term = 
  +        let mutable index = nTerm
  +        index <- (index * (parser.IndexatorFullCount - parser.NonTermCount))
  +        index <- index + term - parser.NonTermCount
  +        index
  +    
  +    let curToken = parser.TokenToNumber tokens.[!currentIndex]
  +    let table = parser.Table
  +    
  +    let test nonTerm funName =
  +        if Array.exists (fun e -> e = funName) table.[getIndex nonTerm curToken]
  +        then
  +            true
  +        else false
  +
  +    let start =
           gss.[!currentIndex].Add dummyGSSNode
  -        let currentGSSNode = ref <| packVertex !currentIndex (gss.[!currentIndex].Count - 1)
  -        let dummyGSSNode = packVertex !currentIndex (gss.[!currentIndex].Count - 1)
  -        let currentContext = ref <| new Context(!currentIndex, !currentLabel, !currentGSSNode, dummyAST)
  -        let createdFamilies = Array.init parser.rulesCount (fun _ -> new Dictionary<int64<key>, ResizeArray<Family>>())  
  -
  -        let terminalNodes = new BlockResizeArray<ExtensionTree>()
  -        let finalExtension = pack3ToInt64 parser.StartRule 0 inputLength
  -
  -        let condition = ref false 
  -        let stop = ref false
  +
           while setR.Count <> 0 do
                   currentContext := setR.Dequeue()
                   currentIndex := currentContext.Value.Index
  
positive.code:                 currentN := currentContext.Value.Ast 
                  currentR := dummyAST
                  functions.[!currentLabel] !currentIndex !currentGSSNode !currentR !currentN
                        
          match !resultAST with
              | None -> Error ("String was not parsed")
              | Some res -> 
                      drawDot parser tokens "gss.dot" gss
                      let r1 = new Tree<_> (tokens, res, parser.rules)
                      Success (r1)       
  
negative.code:     | Success of Tree<'TokenType>
      | Error of string
  
  type buildAst<'TokenType>(parser : ParserSource2<'TokenType>, tokens : seq<'TokenType>, functions : (int -> int64<vertex> -> ExtensionTree -> ExtensionTree -> unit)[]) = 
      let tokens = Seq.toArray tokens
      let inputLength = Seq.length tokens
      let nonTermsCountLimit = 1 + (Array.max parser.LeftSide)
      let resultAST = ref None
      let epsilon = new TerminalNode(-1)
      let setR = new Queue<Context>()   
      let setP = new System.Collections.Generic.Dictionary<int64<vertex>,ResizeArray<ExtensionTree>> ()
      let astDictionary = new System.Collections.Generic.Dictionary<int64<key>, AST> ()
      let setU = Array.init (inputLength + 1) (fun _ -> new Dictionary<_*_, ResizeArray<INode>>())
              
      let currentIndex = ref 0
  
  