class_docstr: A simple bottom-up CFG parser that uses two operations, "shift"
  and "reduce", to find a single parse for a text.
  
  ``ShiftReduceParser`` maintains a stack, which records the
  structure of a portion of the text.  This stack is a list of
  strings and Trees that collectively cover a portion of
  the text.  For example, while parsing the sentence "the dog saw
  the man" with a typical grammar, ``ShiftReduceParser`` will produce
  the following stack, which covers "the dog saw"::
  
     [(NP: (Det: 'the') (N: 'dog')), (V: 'saw')]
  
  ``ShiftReduceParser`` attempts to extend the stack to cover the
  entire text, and to combine the stack elements into a single tree,
  producing a complete parse for the sentence.
  
  Initially, the stack is empty.  It is extended to cover the text,
  from left to right, by repeatedly applying two operations:
  
    - "shift" moves a token from the beginning of the text to the
      end of the stack.
    - "reduce" uses a CFG production to combine the rightmost stack
      elements into a single Tree.
  
  Often, more than one operation can be performed on a given stack.
  In this case, ``ShiftReduceParser`` uses the following heuristics
  to decide which operation to perform:
  
    - Only shift if no reductions are available.
    - If multiple reductions are available, then apply the reduction
      whose CFG production is listed earliest in the grammar.
  
  Note that these heuristics are not guaranteed to choose an
  operation that leads to a parse of the text.  Also, if multiple
  parses exists, ``ShiftReduceParser`` will return at most one of
  them.
  
  :see: ``nltk.grammar``
class_docstr_tok: ["A","simple","bottom-up","CFG","parser","that","uses","two","operations",",","``","shift","''","and","``","reduce","''",",","to","find","a","single","parse","for","a","text",".","``","ShiftReduceParser","``","maintains","a","stack",",","which","records","the","structure","of","a","portion","of","the","text",".","This","stack","is","a","list","of","strings","and","Trees","that","collectively","cover","a","portion","of","the","text",".","For","example",",","while","parsing","the","sentence","``","the","dog","saw","the","man","''","with","a","typical","grammar",",","``","ShiftReduceParser","``","will","produce","the","following","stack",",","which","covers","``","the","dog","saw","''",":",":","[","(","NP",":","(","Det",":","'the","'",")","(","N",":","'dog","'",")",")",",","(","V",":","'saw","'",")","]","``","ShiftReduceParser","``","attempts","to","extend","the","stack","to","cover","the","entire","text",",","and","to","combine","the","stack","elements","into","a","single","tree",",","producing","a","complete","parse","for","the","sentence",".","Initially",",","the","stack","is","empty",".","It","is","extended","to","cover","the","text",",","from","left","to","right",",","by","repeatedly","applying","two","operations",":","-","``","shift","''","moves","a","token","from","the","beginning","of","the","text","to","the","end","of","the","stack",".","-","``","reduce","''","uses","a","CFG","production","to","combine","the","rightmost","stack","elements","into","a","single","Tree",".","Often",",","more","than","one","operation","can","be","performed","on","a","given","stack",".","In","this","case",",","``","ShiftReduceParser","``","uses","the","following","heuristics","to","decide","which","operation","to","perform",":","-","Only","shift","if","no","reductions","are","available",".","-","If","multiple","reductions","are","available",",","then","apply","the","reduction","whose","CFG","production","is","listed","earliest","in","the","grammar",".","Note","that","these","heuristics","are","not","guaranteed","to","choose","an","operation","that","leads","to","a","parse","of","the","text",".","Also",",","if","multiple","parses","exists",",","``","ShiftReduceParser","``","will","return","at","most","one","of","them",".",":","see",":","``","nltk.grammar","``"]
docstr: :rtype: bool
  :return: true if the right hand side of a CFG production
      matches the rightmost elements of the stack.  ``rhs``
      matches ``rightmost_stack`` if they are the same length,
      and each element of ``rhs`` matches the corresponding
      element of ``rightmost_stack``.  A nonterminal element of
      ``rhs`` matches any Tree whose node value is equal
      to the nonterminal's symbol.  A terminal element of ``rhs``
      matches any string whose type is equal to the terminal.
  :type rhs: list(terminal and Nonterminal)
  :param rhs: The right hand side of a CFG production.
  :type rightmost_stack: list(string and Tree)
  :param rightmost_stack: The rightmost elements of the parser's
      stack.
docstr_tok: [":","rtype",":","bool",":","return",":","true","if","the","right","hand","side","of","a","CFG","production","matches","the","rightmost","elements","of","the","stack",".","``","rhs","``","matches","``","rightmost_stack","``","if","they","are","the","same","length",",","and","each","element","of","``","rhs","``","matches","the","corresponding","element","of","``","rightmost_stack","``",".","A","nonterminal","element","of","``","rhs","``","matches","any","Tree","whose","node","value","is","equal","to","the","nonterminal","'s","symbol",".","A","terminal","element","of","``","rhs","``","matches","any","string","whose","type","is","equal","to","the","terminal",".",":","type","rhs",":","list","(","terminal","and","Nonterminal",")",":","param","rhs",":","The","right","hand","side","of","a","CFG","production",".",":","type","rightmost_stack",":","list","(","string","and","Tree",")",":","param","rightmost_stack",":","The","rightmost","elements","of","the","parser's","stack","."]
code: def _match_rhs(self, rhs, rightmost_stack):
      """
      :rtype: bool
      :return: true if the right hand side of a CFG production
          matches the rightmost elements of the stack.  ``rhs``
          matches ``rightmost_stack`` if they are the same length,
          and each element of ``rhs`` matches the corresponding
          element of ``rightmost_stack``.  A nonterminal element of
          ``rhs`` matches any Tree whose node value is equal
          to the nonterminal's symbol.  A terminal element of ``rhs``
          matches any string whose type is equal to the terminal.
      :type rhs: list(terminal and Nonterminal)
      :param rhs: The right hand side of a CFG production.
      :type rightmost_stack: list(string and Tree)
      :param rightmost_stack: The rightmost elements of the parser's
          stack.
      """
  
      if len(rightmost_stack) != len(rhs):
          return False
      for i in range(len(rightmost_stack)):
          if isinstance(rightmost_stack[i], Tree):
              if not isinstance(rhs[i], Nonterminal):
                  return False
              if rightmost_stack[i].label() != rhs[i].symbol():
                  return False
          else:
              if isinstance(rhs[i], Nonterminal):
                  return False
              if rightmost_stack[i] != rhs[i]:
                  return False
      return True
  
imports: from nltk.grammar import Nonterminal
  from nltk.parse.api import ParserI
  from nltk.tree import Tree
label_desc: Use image node_id 5 for calling the ShiftReduceParser obj's underlying member method code with example usage: obj._match_rhs(rhs, rightmost_stack) and returns: True, False, False, False, False, False