Remove epsilon rules.
    :param grammar: Grammar where rules remove
    :param inplace: True if transformation should be performed in place, false otherwise.
    False by default.
    :return: Grammar without epsilon rules.

def remove_rules_with_epsilon(grammar, inplace=False):
    # type: (Grammar, bool) -> Grammar
    """
    Remove epsilon rules.
    :param grammar: Grammar where rules remove
    :param inplace: True if transformation should be performed in place, false otherwise.
    False by default.
    :return: Grammar without epsilon rules.
    """
    # copy if required
    if inplace is False:
        grammar = copy(grammar)
    # find nonterminals rewritable to epsilon
    rewritable = find_nonterminals_rewritable_to_epsilon(grammar)  # type: Dict[Type[Nonterminal], Type[Rule]]
    # create queue from rules to iterate over
    rules = Queue()
    for r in grammar.rules:
        rules.put(r)
    # iterate thought rules
    while not rules.empty():
        rule = rules.get()
        right = rule.right
        # if the rule rewrite to epsilon we can safely delete it
        if right == [EPSILON]:
            # unless it rewrites from the start symbol
            if rule.fromSymbol != grammar.start:
                grammar.rules.discard(rule)
            # continue IS executed, but due optimization line is marked as missed.
            continue  # pragma: no cover
        # iterate over the right side
        for rule_index in range(len(right)):
            symbol = right[rule_index]
            # if symbol is rewritable, generate new rule without that symbol
            if symbol in rewritable:
                new_rule = _create_rule(rule, rule_index, rewritable)
                grammar.rules.add(new_rule)
                rules.put(new_rule)  # in case there are more rewritable symbols
    return grammar