code: def parse(str, flags=0, state=None):
      # parse 're' pattern into list of (opcode, argument) tuples
  
      source = Tokenizer(str)
  
      if state is None:
          state = State()
      state.flags = flags
      state.str = str
  
      p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
      p.state.flags = fix_flags(str, p.state.flags)
  
      if source.next is not None:
          assert source.next == ")"
          raise source.error("unbalanced parenthesis")
  
      for g in p.state.grouprefpos:
          if g >= p.state.groups:
              msg = "invalid group reference %d" % g
              raise error(msg, str, p.state.grouprefpos[g])
  
      if flags & SRE_FLAG_DEBUG:
          p.dump()
  
      return p
  
imports: from ._constants import *
label_desc: Use image node_id 8 for calling a global function with example usage: parse(str, flags, state) and returns: p