
from grammpy import Grammar


def find_terminals_rewritable_to_epsilon(grammar: Grammar) -> list:
    raise NotImplementedError()


from grammpy import Grammar, EPSILON


def find_terminals_rewritable_to_epsilon(grammar: Grammar) -> list:
    rewritable = {EPSILON}
    while True:
        working = rewritable.copy()
        for rule in grammar.rules():
            allRewritable = True
            for symbol in rule.right:
                if symbol not in rewritable: allRewritable = False
            if allRewritable: working.add(rule.fromSymbol)
        if working == rewritable: break
        rewritable = working
    rewritable.remove(EPSILON)
    return [i for i in rewritable]

Implement finding of nonterminals rewritable to epsilon
Implement finding of nonterminals rewritable to epsilon

  
- from grammpy import Grammar
+ from grammpy import Grammar, EPSILON
  
  
  def find_terminals_rewritable_to_epsilon(grammar: Grammar) -> list:
-     raise NotImplementedError()
+     rewritable = {EPSILON}
+     while True:
+         working = rewritable.copy()
+         for rule in grammar.rules():
+             allRewritable = True
+             for symbol in rule.right:
+                 if symbol not in rewritable: allRewritable = False
+             if allRewritable: working.add(rule.fromSymbol)
+         if working == rewritable: break
+         rewritable = working
+     rewritable.remove(EPSILON)
+     return [i for i in rewritable]
  
Implement finding of nonterminals rewritable to epsilon
## Code Before:

from grammpy import Grammar


def find_terminals_rewritable_to_epsilon(grammar: Grammar) -> list:
    raise NotImplementedError()

## Instruction:
Implement finding of nonterminals rewritable to epsilon
## Code After:

from grammpy import Grammar, EPSILON


def find_terminals_rewritable_to_epsilon(grammar: Grammar) -> list:
    rewritable = {EPSILON}
    while True:
        working = rewritable.copy()
        for rule in grammar.rules():
            allRewritable = True
            for symbol in rule.right:
                if symbol not in rewritable: allRewritable = False
            if allRewritable: working.add(rule.fromSymbol)
        if working == rewritable: break
        rewritable = working
    rewritable.remove(EPSILON)
    return [i for i in rewritable]
