anchor.diff:          )
       MultiMap.freeze lookaheads
   
  -/// <summary>Creates an LALR state table.</summary>
  -/// <param name="fResolveConflict">A function to choose the preferred action in case of a conflict.</param>
  -/// <param name="startSymbol">The start symbol.</param>
  -/// <param name="itemSets">The item sets of the grammar.</param>
  -/// <param name="lookaheadTables">The lookahead symbols that correspond to the items of each item set.</param>
  -let createLALRStates fResolveConflict startSymbol itemSets (lookaheadTables: Map<_, _>) =
  -    let getLookahead item idx =
  -        match lookaheadTables.TryGetValue((item, idx)) with
  -        | true, v -> v
  -        | false, _ -> Set.empty
  +/// Creates an LALR state table.
  +let createLALRStates fGetAllProductions fGetFirstSet fResolveConflict startSymbol itemSets (lookaheadTables: Map<_, _>) =
       itemSets
       |> Seq.map (fun itemSet ->
           let index = uint32 itemSet.Index
  +        // The book says we have to close the kernel under LR(1) to create the
  +        // action table. However, we have already created the GOTO table from the LR(0)
  +        // closure, and the only reason for the LR(1) closure is to find more lookahead
  +        // symbols or productions with no members. So it will be used only for the reductions.
  +        let closedItem =
  +            itemSet.Kernel
  +            |> Seq.map (fun kernelItem ->
  +                let lookahead =
  +                    match lookaheadTables.TryGetValue((kernelItem, int index)) with
  +                    | true, v -> v
  +                    | false, _ -> Set.empty
  +                kernelItem, lookahead)
  +            |> closure1 fGetAllProductions fGetFirstSet
  +            |> List.filter (fun x -> x.Item.IsAtEnd)
           let gotoActions =
               itemSet.Goto
               |> Seq.choose (function
  
positive.code:     let resolveConflict stateIndex term x1 x2 =
          LALRConflict.Create stateIndex term x1 x2 |> conflicts.Add
          x1
      match createLALRStates resolveConflict s' kernelItems lookaheads with
      | theGloriousStateTable when conflicts.Count = 0 ->
          Ok theGloriousStateTable
      | _ -> conflicts |> set |> BuildError.LALRConflict |> Error
  
negative.code:             match Seq.tryExactlyOne itemSet.Kernel with
              | Some k when k.IsAtEnd && k.Production.Head = startSymbol ->  Some LALRAction.Accept
              | _ ->
                  closedItem
                  |> Seq.choose (fun item ->
                      if Set.contains End item.Lookahead then
                          Some (LALRAction.Reduce item.Item.Production)
                      else
                          None)
                  |> List.ofSeq
  