parameters: (nonterminal_to_dfas, first_plans, nonterminal)
return_statement: return new_first_plans
docstring: Calculates the first plan in the first_plans dictionary for every given
      nonterminal. This is going to be used to know when to create stack nodes.
docstring_summary: Calculates the first plan in the first_plans dictionary for every given
      nonterminal. This is going to be used to know when to create stack nodes.
docstring_tokens: Calculates the first plan in the first_plans dictionary for every given nonterminal . This is going to be used to know when to create stack nodes .
function: def _calculate_first_plans(nonterminal_to_dfas, first_plans, nonterminal):
      """
      Calculates the first plan in the first_plans dictionary for every given
      nonterminal. This is going to be used to know when to create stack nodes.
      """
      dfas = nonterminal_to_dfas[nonterminal]
      new_first_plans = {}
      first_plans[nonterminal] = None  # dummy to detect left recursion
      # We only need to check the first dfa. All the following ones are not
      # interesting to find first terminals.
      state = dfas[0]
      for transition, next_ in state.transitions.items():
          # It's a string. We have finally found a possible first token.
          new_first_plans[transition] = [next_.next_dfa]
  
      for nonterminal2, next_ in state.nonterminal_arcs.items():
          # It's a nonterminal and we have either a left recursion issue
          # in the grammar or we have to recurse.
          try:
              first_plans2 = first_plans[nonterminal2]
          except KeyError:
              first_plans2 = _calculate_first_plans(nonterminal_to_dfas, first_plans, nonterminal2)
          else:
              if first_plans2 is None:
                  raise ValueError("left recursion for rule %r" % nonterminal)
  
          for t, pushes in first_plans2.items():
              new_first_plans[t] = [next_] + pushes
  
      first_plans[nonterminal] = new_first_plans
      return new_first_plans
function_tokens: def _calculate_first_plans ( nonterminal_to_dfas , first_plans , nonterminal ) : dfas = nonterminal_to_dfas [ nonterminal ] new_first_plans = { } first_plans [ nonterminal ] = None # dummy to detect left recursion # We only need to check the first dfa. All the following ones are not # interesting to find first terminals. state = dfas [ 0 ] for transition , next_ in state . transitions . items ( ) : # It's a string. We have finally found a possible first token. new_first_plans [ transition ] = [ next_ . next_dfa ] for nonterminal2 , next_ in state . nonterminal_arcs . items ( ) : # It's a nonterminal and we have either a left recursion issue # in the grammar or we have to recurse. try : first_plans2 = first_plans [ nonterminal2 ] except KeyError : first_plans2 = _calculate_first_plans ( nonterminal_to_dfas , first_plans , nonterminal2 ) else : if first_plans2 is None : raise ValueError ( "left recursion for rule %r" % nonterminal ) for t , pushes in first_plans2 . items ( ) : new_first_plans [ t ] = [ next_ ] + pushes first_plans [ nonterminal ] = new_first_plans return new_first_plans