code: def find_nonterminals_reachable_by_unit_rules(grammar):
      # type: (Grammar) -> UnitSymbolReachability
      
      # get nonterminals
      nonterminals = list(grammar.nonterminals)  # type: List[Type[Nonterminal]]
      count_of_nonterms = len(nonterminals)
      # create indexes for nonterminals
      nonterm_to_index = dict()  # type: Dict[Type[Nonterminal], int]
      for i in range(count_of_nonterms):
          nonterm_to_index[nonterminals[i]] = i
      # prepare matrix
      field = [[None for _ in nonterminals] for _ in nonterminals]  # type: MATRIX_OF_UNIT_RULES
      # fill existing unit rules
      for rule in grammar.rules:
          if _is_unit(rule):
              field[nonterm_to_index[rule.fromSymbol]][nonterm_to_index[rule.toSymbol]] = [rule]
      # run Floyd Warshall
      f = field
      for k in range(count_of_nonterms):
          for i in range(count_of_nonterms):
              for j in range(count_of_nonterms):
                  if f[i][k] is not None and f[k][j] is not None:
                      if f[i][j] is None or len(f[i][j]) > len(f[i][k]) + len(f[k][j]):
                          f[i][j] = f[i][k] + f[k][j]
      # return results
      return UnitSymbolReachability(f, nonterm_to_index)
docs: Get nonterminal for which exist unit rule
      :param grammar: Grammar where to search
      :return: Instance of UnitSymbolReachability.