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: 
  let eol = System.Environment.NewLine
  
  
  let run grammarFile frontendName generatorName generatorParams conversions userDefs generateToFile =
      let frontend =
          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 ()
  
      // Parse grammar
      let ilTree =
          try
              let defStr = String.concat ";" userDefs
              if System.String.IsNullOrEmpty defStr
              then grammarFile
              else grammarFile + "%" + defStr
              |> frontend.ParseGrammar
              |> ref
          with
          | e -> FEError (e.Message + " " + e.StackTrace) |> raise
      Namer.initNamer ilTree.Value.grammar
  
      let repeatedInnerRules, repeatedExportRules, undeclaredRules = GetUndeclaredNonterminalsList !ilTree
  
      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
              )
                      
      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)
  
negative.code:         (fun (rule, got, expected) -> sprintf "%s(%d,%d): %d (expected %d)" rule.text rule.startPos.line rule.startPos.column got expected)
          eol
  
  let applyConversion (convNameWithParams : string) (ilTree : Definition.t<Source.t, Source.t>) = 
      let parameters = convNameWithParams.Split(' ')
      if parameters.Length = 0 then failwith "Missing Conversion name"
      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]
          }
  
  let prepareGenerator generatorName =
      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 ()
  
  let checkIlTree ilTree (gen : Generator) =  
      if not (IsSingleStartRule !ilTree) then
          raise <| CheckerError "Input grammar should contains only one start rule."
      try
          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}
          ilTree
      with
          | e -> GenError e.Message |> raise
  
  let genToFile (generator : Generator) genParams ilTree =
      try
          match genParams with
          | None -> generator.Generate(!ilTree, true)
          | Some x -> generator.Generate(!ilTree, true, x)
      with
          | e -> GenError e.Message |> raise
  
  let genToObj (generator : Generator) genParams ilTree =
      try
          match genParams with
          | None -> generator.Generate(!ilTree, false)
          | Some x -> generator.Generate(!ilTree, false, x) 
      with
          | e -> GenError e.Message |> raise
  
  let applyConversions (ilTree : Definition.t<Source.t, Source.t> ref) (frontend : Frontend) conversions =
      Namer.initNamer ilTree.Value.grammar
      dealWithErrors ilTree
      let lostSources = ref false
      // Let possible to know, after what conversion we lost reference to original code
      let checkSources name il = 
  