anchor.diff:              let newAstNodes = curTokens.Value.Tokens |> Array.mapi (fun i _ -> tokens.Count + i |> box)
               let oldTokens = !curTokens
               curTokens.Value.Tokens |> Array.iter (fun t -> tokens.Add t.Token)
  -            if enum.MoveNext() then
  -                curTokens := processChunk enum.Current
  +            let flg = 
  +                //enum.MoveNext() |> ref
  +                ref false
  +            //let actualVertices = usedStates |> Seq.map (fun x -> stateToVertex.[x].Level) |> Array.ofSeq
  +            while (flg := enum.MoveNext(); !flg) && fst (!rangeToSkip) < (fst enum.Current) && (fst enum.Current) < snd (!rangeToSkip) do printfn "sckiped %A"  (fst enum.Current)
  +            if !flg then
  +                curTokens := processChunk enum.Current                
                   curLvl := (!curTokens).CurLvl
  -                isEOF :=
  -                    curTokens.Value.Tokens.Length = 0
  -                    || (curTokens.Value.Tokens.Length = 1
  -                        && parserSource.TokenToNumber curTokens.Value.Tokens.[0].Token = parserSource.EofIndex )
  +                isEOF := 
  +                    curTokens.Value.Tokens.Length = 0 
  +                    || (curTokens.Value.Tokens.Length = 1 
  +                        && parserSource.TokenToNumber curTokens.Value.Tokens.[0].Token = parserSource.EofIndex ) 
               else
                   isEOF := true
               let oldPushes = !pushes |> Array.map (fun p -> p.ToArray())
               for i in 0..oldTokens.Tokens.Length-1 do
                   let newAstNode = newAstNodes.[i]
                   let oldPushes = oldPushes.[i]
  -                let num = oldTokens.Tokens.[i].NxtLvl
  +                let num = oldTokens.Tokens.[i].NxtLvl                
                   if pushesMap.ContainsKey num
  -                then
  -                    pushesMap.[num].Add((oldPushes,newAstNode))
  +                then 
  +                    pushesMap.[num].Add((oldPushes,newAstNode)) 
                   else pushesMap.Add(num,new ResizeArray<_>([|oldPushes,newAstNode|]))
               pushesInitFun curTokens.Value.Tokens.Length
  -
  -        let print fName =
  + 
  +        let print (fName:PrintfFormat<_,_,_,_>) =
   #if DEBUG
  -            try
  -                let path = fName |> string |> System.IO.Path.GetDirectoryName
  -                if path |> System.IO.Directory.Exists |> not
  -                then System.IO.Directory.CreateDirectory path |> ignore
  -                let vertices = usedStates.ToArray() |> Array.map (fun i -> stateToVertex.[i])
  -                drawDot parserSource.TokenToNumber tokens parserSource.LeftSide vertices parserSource.NumToString parserSource.ErrorIndex
  -                <| sprintf fName !curLvl
  -            with
  -            | _ -> ()
  +            let path = fName.Value |> System.IO.Path.GetDirectoryName
  +            if path |> System.IO.Directory.Exists |> not
  +            then System.IO.Directory.CreateDirectory path |> ignore
  +            let vertices = usedStates.ToArray() |> Array.map (fun i -> stateToVertex.[i])
  +            drawDot parserSource.TokenToNumber tokens parserSource.LeftSide vertices parserSource.NumToString parserSource.ErrorIndex
  +                        <| sprintf fName !curLvl
   #endif
               ()
   
           let mutable errorList = []
           let errorRuleExist = parserSource.ErrorRulesExists
  -        let mutable wasError = ref false
  +        let mutable wasError = false
           let lastErr = ref -1
           let pushesBackup = ref [||]
   
  -        while not !isEnd && not !wasError do
  -
  +        let errors = new ResizeArray<_>()
  +        
  +        let restorePushes () =
  +          if pushesMap.ContainsKey !curLvl
  +          then
  +              for vertex in usedStates do
  +                  stateToVertex.[vertex] <- null
  +              usedStates.Clear()
  +              for oldPushes,newAstNode in pushesMap.[!curLvl] do
  +                  for (vertex, state) in oldPushes do
  +                      let newVertex = addVertex [|state, !curLvl,  Some (vertex, newAstNode)|]
  +                      addSimpleEdge vertex newAstNode simpleEdges.[state]
  +              pushesMap.Remove(!curLvl) |> ignore
  +
  +        let erTok () = 
  +            //let shiftBase = tokens.Count - (!pushesBackup).Length 
  +            //let x = !pushesBackup |> Array.mapi (fun i (a:Stack<_>) -> if a.Count = 0  then Some (tokens.Item(shiftBase + i)) else None)
  +            rangeToSkip := !curLvl, try pushesMap.Keys |> Seq.min with _ -> !curLvl
  +            let x = !pushesBackup |> Array.mapi (fun i (a:Stack<_>) -> if a.Count = 0  then Some (curTokens.Value.Tokens.[i].Token) else None)
  +            x |> Array.choose id
  +            |> errors.AddRange
  +            //(try curTokens.Value.Tokens.[0].Token with _ -> tokens.[tokens.Count-1])
  +
  +        while not !isEnd && not wasError do
  +            print @"dot\stack_%A_1"
               if usedStates.Count = 0 && reductions.Count = 0
               then
  -                let errInfo = !curTokens
  -                errorList <- errInfo :: errorList
  -                wasError <- ref true
  +                if pushesMap.Count = 0
  +                then
  +                  let errInfo = !curTokens
  +                  errorList <- errInfo :: errorList
  +                  wasError <- true
  +                else
  +                    pushesBackup := !pushes
  +                    erTok()
  +                    curLvl := pushesMap.Keys |> Seq.min
  +                    restorePushes ()
  +                    makeReductions ()
  +                    attachEdges()
  +                    if not !isEOF then shift()
               else
  -                print "dot\stack_2_%A"
  +                print @"dot\stack_%A_2"
                   if !isEOF
                   then
  -                    try
  -                        for vertex in usedStates do
  -                            stateToVertex.[vertex] <- null
  -                        usedStates.Clear()
  -                        for  oldPushes,newAstNode in pushesMap.[!curLvl] do
  -                            for (vertex, state) in oldPushes do
  -                                let newVertex = addVertex [|state, !curLvl,  Some (vertex, newAstNode)|]
  -                                addSimpleEdge vertex newAstNode simpleEdges.[state]
  -                        pushesMap.Remove(!curLvl) |> ignore
  -                        makeReductions ()
  -                        attachEdges()
  -                        print "dot\stack_5_%A"
  -                    with _ -> ()
  +                    restorePushes ()
  +                    makeReductions()
  +                    attachEdges()
  +                    print @"dot\stack_%A_3"               
                       isEnd := true
                   else
  -                    print "dot\stack_3_%A"
  +                    print @"dot\stack_%A_4"
                       if !curLvl > 0
                       then
                           if pushesMap.ContainsKey !curLvl
  -                        then
  -                            for vertex in usedStates do
  -                                stateToVertex.[vertex] <- null
  -                            usedStates.Clear()
  -                            for  oldPushes,newAstNode in pushesMap.[!curLvl] do
  -                                for (vertex, state) in oldPushes do
  -                                    let newVertex = addVertex [|state, !curLvl,  Some (vertex, newAstNode)|]
  -                                    addSimpleEdge vertex newAstNode simpleEdges.[state]
  -                            pushesMap.Remove(!curLvl) |> ignore
  +                        then restorePushes ()
                           else
                               for vertex in usedStates do
                                   stateToVertex.[vertex] <- null
                               usedStates.Clear()
                       makeReductions ()
                       attachEdges()
  -                    if !pushes |> Array.exists (fun x -> x.Count = 0)
  -                    then 
  -                        wasError := true
  -                        pushesBackup := !pushes
  +                    let bad, good = !pushes |> Array.partition (fun x -> x.Count = 0)
  +                    if bad.Length > 0 || good.Length = 0
  +                    then
  +                        //()
  +                        pushesBackup := !pushes 
  +                        erTok ()
  +//                    if good.Length = 0
  +//                    then 
  +//                        //wasError <- true
  +//                        pushesBackup := !pushes
  +//                        erTok ()
  +//                        if pushesMap.Count > 0 
  +//                        then ()
  +//                          //curLvl := pushesMap.Keys |> Seq.min
  +//                          //restorePushes ()
  +//                        //else wasError <- true
                       shift ()
   
  -        let isAcceptState() =
  -            usedStates.ToArray()
  -            |> Array.exists (fun state -> parserSource.AccStates.[state])                  
  +        let isAcceptState() = 
  +            let flag = ref false
  +            for state in usedStates do
  +                if not !flag 
  +                then
  +                    flag := parserSource.AccStates.[state]
  +            !flag
   
           // if finish isn't accepting state then error
  -        if !isEnd && usedStates.Count > 0 && not <| isAcceptState()
  +        if !isEnd && usedStates.Count > 0 && not <| isAcceptState() 
           then
               //recovery()
  -            makeReductions ()
  +            makeReductions()
               attachEdges()
   
           let lastTokens count =
  
positive.code:                                         for (prod, pos) in arr do
                                              reductions.Push (newVertex, prod, pos, Some (final, box edgeLabel))
                                  else
                                      for tok in curTokens.Value.Tokens do
                                          let arr = parserSource.Reduces.[state].[tok.CurNum]
                                          if arr <> null then
                                              for (prod, pos) in arr do
  
negative.code: open Yard.Generators.RNGLR.AST
  open System.Collections.Generic
  open Yard.Generators.RNGLR.DataStructures
  open Yard.Generators.RNGLR.Parser 
  open Microsoft.FSharp.Collections
  
  
  [<Struct>]
  type TokenWithInfo<'token> =
      val Token  : 'token    
      val NxtLvl : int
      val CurNum : int
      new (t,nl,cn) = {Token=t;NxtLvl=nl;CurNum=cn}
  