anchor.diff:                  x
                   |> List.map(fun s -> s.text) |> String.concat "\n"
                   |> printfn "Lost sources after frontend or conversion %s:\n %s" name
  +
       checkSources frontend.Name !ilTree
  -
       // Apply Conversions
  -    let apply_Conversion (convNameWithParams:string) (ilTree:Definition.t<Source.t,Source.t>) = 
  -        let parameters = convNameWithParams.Split(' ')
  -            //printfn "Conversion: %s" convNameWithParams
  -        if parameters.Length = 0 then failwith "Missing Conversion name"
  +    for conv in conversions do
  +        ilTree := applyConversion conv !ilTree
  +        checkSources conv !ilTree
  +
  +let gen grammarFile frontendName generatorName generatorParams conversions userDefs generateToFile = 
  +    try
  +        let frontend = getFrontend frontendName
  +        let ilTree = getIlTreeFromFile grammarFile frontend userDefs
  +        applyConversions ilTree frontend conversions
  +        let generator = prepareGenerator generatorName
  +        let checkedIl = checkIlTree ilTree generator
  +        if generateToFile then
  +            genToFile generator generatorParams checkedIl
           else
  -            {ilTree with grammar = match Seq.tryFind (fun (elem : Conversion) -> elem.Name = parameters.[0]) (Addin.GetConversions()) with 
  -                                   | Some conv -> conv.ConvertGrammar (ilTree.grammar, parameters.[1..parameters.Length - 1])
  -                                   | None -> failwith <| "Conversion not found: " + parameters.[0]
  -            }
  -
  -    for conv in conversions do
  -        ilTree := apply_Conversion conv !ilTree
  -        checkSources conv !ilTree
  -
  -    let gen =
  -        let _raise () = InvalidGenName generatorName |> raise
  -        if Array.exists (fun (elem : Generator) -> elem.Name = generatorName) (Addin.GetGenerators())
  -        then              
  -            try
  -                match Array.tryFind (fun (elem : Generator) -> elem.Name = generatorName) (Addin.GetGenerators()) with
  -                | Some gen -> gen
  -                | None -> failwith "TreeDump is not found."
  -            with
  -            | _ -> _raise ()
  -        else _raise ()
  -                               
  -    // Generate something
  -    let result =  
  -        if not (IsSingleStartRule !ilTree) then
  -           raise <| CheckerError "Input grammar should contains only one start rule."
  -        try
  -            //let gen = new Yard.Generators.RNGLR.RNGLR()
  -            for constr in gen.Constraints do
  -                let grammar = ilTree.Value.grammar
  -                if not <| constr.Check grammar then
  -                    eprintfn "Constraint %s: applying %s..." constr.Name constr.Conversion.Name
  -                    ilTree := {!ilTree with grammar = constr.Fix grammar}
  -
  -            match generatorParams with
  -            | None -> 
  -                gen.Generate(!ilTree, generateToFile)
  -            | Some genParams -> gen.Generate(!ilTree, generateToFile, genParams)
  -        with
  -            | e -> GenError e.Message |> raise
  -//                | Yard.Generators.GNESCCGenerator.StartRuleNotFound 
  -//                    -> GenError "Start rule cannot be found in input grammar. Please, specify start rule."
  -//                       |> raise
  -    result
  -
  -let gen grammarFile frontendName generatorName generatorParams conversions userDefs generateToFile = 
  -    try
  -        run grammarFile frontendName generatorName generatorParams conversions userDefs generateToFile
  +            genToObj generator generatorParams checkedIl
       with
       | InvalidFEName frontendName as e  -> 
           "Frontend with name " + frontendName + " is not available. Run \"Main.exe -af\" for get all available frontends.\n" 
  
positive.code:         (fun (rule, got, expected) -> sprintf "%s(%d,%d): %d (expected %d)" rule.text rule.startPos.line rule.startPos.column got expected)
          eol
  
      let lostSources = ref false
      // Let possible to know, after what conversion we lost reference to original code
      let checkSources name il = 
  
negative.code: 
  let eol = System.Environment.NewLine
  
  let getFrontend frontendName =
      let fen = (Addin.GetFrontends())
      let _raise () = InvalidFEName frontendName |> raise
      if Array.exists (fun (elem : Frontend) -> elem.Name = frontendName) (Addin.GetFrontends())
      then
          try
              match Array.tryFind (fun (elem : Frontend) -> elem.Name = frontendName) (Addin.GetFrontends()) with
              | Some fe -> fe
              | None -> failwith "Frontend is not found."
          with
          | _ -> _raise ()
      else _raise ()
  
  let getIlTreeFromFile grammarFile (frontend : Frontend) userDefs = 
      try
          let defStr = String.concat ";" userDefs
          if System.String.IsNullOrEmpty defStr
          then grammarFile
          else grammarFile + "%" + defStr
          |> frontend.ParseGrammar
          |> ref
      with
      | e -> FEError (e.Message + "\nFailed parsing grammar file: " + e.StackTrace) |> raise
  
  let getIlTreeFromStr grammarStr (frontend : Frontend) = 
      try
          ref (frontend.ParseGrammarFromStr grammarStr)
      with
      | e -> FEError (e.Message + "\nFailed parsing grammar string: " + e.StackTrace) |> raise
  
  let processErrors (errorList : (_ * 'a list) list) msg map delimiter =
      if errorList.Length > 0 then
          eprintfn  "%s" msg
          errorList |> List.iter (fun (m, rules) ->
              rules
              |> List.map map
              |> String.concat delimiter
              |> eprintfn "Module %s:%s%s" (getModuleName m) eol
          )
  
  let dealWithErrors ilTree = 
      let repeatedInnerRules, repeatedExportRules, undeclaredRules = GetUndeclaredNonterminalsList !ilTree
      processErrors undeclaredRules
          "Input grammar contains some undeclared nonterminals:"
          (fun rule -> sprintf "%s (%s:%d:%d)" rule.text rule.file rule.startPos.line rule.startPos.column)
  