code: def auto_symbol(
      tokens: List[TOKEN], local_dict: DICT, global_dict: DICT
  ):
      """Inserts calls to ``Symbol``/``Function`` for undefined variables."""
      result: List[TOKEN] = []
      prevTok = (-1, "")
  
      tokens.append((-1, ""))  # so zip traverses all tokens
      for tok, nextTok in zip(tokens, tokens[1:]):
          tokNum, tokVal = tok
          nextTokNum, nextTokVal = nextTok
          if tokNum == NAME:
              name = tokVal
  
              if (
                  name in ["True", "False", "None"]
                  or iskeyword(name)
                  # Don't convert attribute access
                  or (prevTok[0] == OP and prevTok[1] == ".")
                  # Don't convert keyword arguments
                  or (
                      prevTok[0] == OP
                      and prevTok[1] in ("(", ",")
                      and nextTokNum == OP
                      and nextTokVal == "="
                  )
                  # the name has already been defined
                  or name in local_dict
                  and local_dict[name] is not null
              ):
                  result.append((NAME, name))
                  continue
              elif name in local_dict:
                  local_dict.setdefault(null, set()).add(name)
                  if nextTokVal == "(":
                      local_dict[name] = Function(name)
                  else:
                      local_dict[name] = Symbol(name)
                  result.append((NAME, name))
                  continue
              elif name in global_dict:
                  obj = global_dict[name]
                  if isinstance(
                      obj, (AssumptionKeys, Basic, type)
                  ) or callable(obj):
                      result.append((NAME, name))
                      continue
  
              result.extend(
                  [
                      (
                          NAME,
                          "Symbol" if nextTokVal != "(" else "Function",
                      ),
                      (OP, "("),
                      (NAME, repr(str(name))),
                      (OP, ")"),
                  ]
              )
          else:
              result.append((tokNum, tokVal))
  
          prevTok = (tokNum, tokVal)
  
      return result
  
imports: from tokenize import generate_tokens, untokenize, TokenError, NUMBER, STRING, NAME, OP, ENDMARKER, ERRORTOKEN, NEWLINE
  from keyword import iskeyword
  import ast
  import unicodedata
  from io import StringIO
  import builtins
  import types
  from typing import Tuple, Dict, Any, Callable, List, Optional, Union
  from sympy.assumptions.ask import AssumptionKeys
  from sympy.core.basic import Basic
  from sympy.core import Symbol
  from sympy.core.function import Function
  from sympy.utilities.misc import func_name
  from sympy.functions.elementary.miscellaneous import Max, Min
label_desc: Use image node_id 14 for calling a global function with example usage: auto_symbol(tokens, local_dict, global_dict) and returns: result