code: def _create_mapping(grammar):
      # type: (Grammar) -> (Dict[int, Set[Type[Rule]]], Dict[int, Set[Type[Rule]]])
      
      termmap = dict()
      rulemap = dict()
      for r in grammar.rules:
          if len(r.right) == 1:
              # rule to terminal
              h = hash(r.toSymbol)
              if h not in termmap:
                  termmap[h] = set()
              termmap[h].add(r)
          else:
              # rule to two nonterms
              key = hash(tuple(r.right))
              if key not in rulemap:
                  rulemap[key] = set()
              rulemap[key].add(r)
      return (termmap, rulemap)
docs: Create mapping between symbols and rules rewritable to these symbols.
      :param grammar: Grammar to use.
      :return: Tuple of two dictionaries.
      First dictionary maps rule to terminal hash.
      Second dictionary maps rule to nonterminals hash.