class_docstr: A simple top-down CFG parser that parses texts by recursively
  expanding the fringe of a Tree, and matching it against a
  text.
  
  ``RecursiveDescentParser`` uses a list of tree locations called a
  "frontier" to remember which subtrees have not yet been expanded
  and which leaves have not yet been matched against the text.  Each
  tree location consists of a list of child indices specifying the
  path from the root of the tree to a subtree or a leaf; see the
  reference documentation for Tree for more information
  about tree locations.
  
  When the parser begins parsing a text, it constructs a tree
  containing only the start symbol, and a frontier containing the
  location of the tree's root node.  It then extends the tree to
  cover the text, using the following recursive procedure:
  
    - If the frontier is empty, and the text is covered by the tree,
      then return the tree as a possible parse.
    - If the frontier is empty, and the text is not covered by the
      tree, then return no parses.
    - If the first element of the frontier is a subtree, then
      use CFG productions to "expand" it.  For each applicable
      production, add the expanded subtree's children to the
      frontier, and recursively find all parses that can be
      generated by the new tree and frontier.
    - If the first element of the frontier is a token, then "match"
      it against the next token from the text.  Remove the token
      from the frontier, and recursively find all parses that can be
      generated by the new tree and frontier.
  
  :see: ``nltk.grammar``
docstr: :rtype: iter(Tree)
  :return: An iterator of all parses that can be generated by
      expanding the first element of ``frontier`` with
      ``production``.  In particular, if the first element of
      ``frontier`` is a subtree whose node type is equal to
      ``production``'s left hand side, then add a child to that
      subtree for each element of ``production``'s right hand
      side; and return all parses that can be generated by
      matching and expanding the remaining elements of
      ``frontier``.  If the first element of ``frontier`` is not a
      subtree whose node type is equal to ``production``'s left
      hand side, then return an empty list.  If ``production`` is
      not specified, then return a list of all parses that can
      be generated by expanding the first element of ``frontier``
      with *any* CFG production.
  
  :type tree: Tree
  :param tree: A partial structure for the text that is
      currently being parsed.  The elements of ``tree``
      that are specified by ``frontier`` have not yet been
      expanded or matched.
  :type remaining_text: list(str)
  :param remaining_text: The portion of the text that is not yet
      covered by ``tree``.
  :type frontier: list(tuple(int))
  :param frontier: A list of the locations within ``tree`` of
      all subtrees that have not yet been expanded, and all
      leaves that have not yet been matched.
docstr_tok: [":","rtype",":","iter","(","Tree",")",":","return",":","An","iterator","of","all","parses","that","can","be","generated","by","expanding","the","first","element","of","``","frontier","``","with","``","production","``",".","In","particular",",","if","the","first","element","of","``","frontier","``","is","a","subtree","whose","node","type","is","equal","to","``","production","``","'s","left","hand","side",",","then","add","a","child","to","that","subtree","for","each","element","of","``","production","``","'s","right","hand","side",";","and","return","all","parses","that","can","be","generated","by","matching","and","expanding","the","remaining","elements","of","``","frontier","``",".","If","the","first","element","of","``","frontier","``","is","not","a","subtree","whose","node","type","is","equal","to","``","production","``","'s","left","hand","side",",","then","return","an","empty","list",".","If","``","production","``","is","not","specified",",","then","return","a","list","of","all","parses","that","can","be","generated","by","expanding","the","first","element","of","``","frontier","``","with","*","any","*","CFG","production",".",":","type","tree",":","Tree",":","param","tree",":","A","partial","structure","for","the","text","that","is","currently","being","parsed",".","The","elements","of","``","tree","``","that","are","specified","by","``","frontier","``","have","not","yet","been","expanded","or","matched",".",":","type","remaining_text",":","list","(","str",")",":","param","remaining_text",":","The","portion","of","the","text","that","is","not","yet","covered","by","``","tree","``",".",":","type","frontier",":","list","(","tuple","(","int",")",")",":","param","frontier",":","A","list","of","the","locations","within","``","tree","``","of","all","subtrees","that","have","not","yet","been","expanded",",","and","all","leaves","that","have","not","yet","been","matched","."]
code: def _expand(self, remaining_text, tree, frontier, production=None):
      """
      :rtype: iter(Tree)
      :return: An iterator of all parses that can be generated by
          expanding the first element of ``frontier`` with
          ``production``.  In particular, if the first element of
          ``frontier`` is a subtree whose node type is equal to
          ``production``'s left hand side, then add a child to that
          subtree for each element of ``production``'s right hand
          side; and return all parses that can be generated by
          matching and expanding the remaining elements of
          ``frontier``.  If the first element of ``frontier`` is not a
          subtree whose node type is equal to ``production``'s left
          hand side, then return an empty list.  If ``production`` is
          not specified, then return a list of all parses that can
          be generated by expanding the first element of ``frontier``
          with *any* CFG production.
  
      :type tree: Tree
      :param tree: A partial structure for the text that is
          currently being parsed.  The elements of ``tree``
          that are specified by ``frontier`` have not yet been
          expanded or matched.
      :type remaining_text: list(str)
      :param remaining_text: The portion of the text that is not yet
          covered by ``tree``.
      :type frontier: list(tuple(int))
      :param frontier: A list of the locations within ``tree`` of
          all subtrees that have not yet been expanded, and all
          leaves that have not yet been matched.
      """
  
      if production is None:
          productions = self._grammar.productions()
      else:
          productions = [production]
  
      for production in productions:
          lhs = production.lhs().symbol()
          if lhs == tree[frontier[0]].label():
              subtree = self._production_to_tree(production)
              if frontier[0] == ():
                  newtree = subtree
              else:
                  newtree = tree.copy(deep=True)
                  newtree[frontier[0]] = subtree
              new_frontier = [
                  frontier[0] + (i,)
                  for i in range(len(production.rhs()))
              ]
              if self._trace:
                  self._trace_expand(newtree, new_frontier, production)
              yield from self._parse(
                  remaining_text, newtree, new_frontier + frontier[1:]
              )
  
imports: from nltk.grammar import Nonterminal
  from nltk.parse.api import ParserI
  from nltk.tree import ImmutableTree, Tree
label_desc: Use image node_id 6 for calling the RecursiveDescentParser obj's underlying member method code with example usage: obj._expand(remaining_text, tree, frontier, production) without return types