def _apply_functions(tokens, local_dict, global_dict):
 result = []
 symbol = None
 for tok in tokens:
  if (tok[0] == NAME):
   symbol = tok
   result.append(tok)
  elif isinstance(tok, ParenthesisGroup):
   if (symbol and _token_callable(symbol, local_dict, global_dict)):
    result[(-1)] = AppliedFunction(symbol, tok)
    symbol = None
   else:
    result.extend(tok)
  else:
   symbol = None
   result.append(tok)
 return result

def _apply_functions ( tokens , local_dict , global_dict ) : result = [ ] symbol = None for tok in tokens : if ( tok [ 0 ] == NAME ) : symbol = tok result . append ( tok ) elif isinstance ( tok , ParenthesisGroup ) : if ( symbol and _token_callable ( symbol , local_dict , global_dict ) ) : result [ ( - 1 ) ] = AppliedFunction ( symbol , tok ) symbol = None else : result . extend ( tok ) else : symbol = None result . append ( tok ) return result
convert a name token + parenthesisgroup into an appliedfunction .