<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def parse( svalue, conf=None, configurable=None, ptype=None, scope=DEFAULT_SCOPE, safe=DEFAULT_SAFE, besteffort=DEFAULT_BESTEFFORT ):
 """Parser which delegates parsing to expression or format parser."""


    result = None

    if ptype is None:
        ptype = object

    compilation = REGEX_EXPR.match(svalue)

    _scope = {} if scope is None else scope.copy()

    if compilation:

        lang, expr = compilation.group('lang', 'expr')

        result = _exprparser(
            expr=expr, lang=lang, conf=conf, configurable=configurable,
            scope=_scope, safe=safe, besteffort=besteffort
        )

    else:
        result = _strparser(
            svalue=svalue, conf=conf, configurable=configurable,
            scope=_scope, safe=safe, besteffort=besteffort
        )

    # try to cast value in ptype
    if not isinstance(result, ptype):
        try:
            result = ptype(result)

        except TypeError:
            result = result

    return result