On Fri, Nov 25, 2011 at 5:40 AM, Joachim Durchholz <[email protected]> wrote:
> Am 25.11.2011 03:18, schrieb Aaron Meurer:
>>
>> I think the problem is that you can't parse this with regular
>> expressions.  You need a more advanced parser.
>
> Actually, there are two ways to use regular expressions to parse
> parenthesized expressions.
>
> Way 1: Do a search-and-replace, replacing parenthese pairs that don't
> contain parentheses with a marker text (that cannot otherwise occur inside
> the string). Keep a dictionary or markers to strings.
> The dictionary ends up being a kind of parse tree.
> This is actually quite fast assuming that the RE engine and
> search-and-replace operations are faster than a handcoded parser, something
> that tends to be true for scripting languages.

I don't know how good the performance of the regular expression module
in Python is. I guess you'd have to benchmark it.  Anyway, I don't
think for a Mathematica parser this is such a big deal (but I suppose
it could be, depending on where we use it). Making sympify() fast
would be important (for that, we use a hand-coded parser, but it
doesn't seem to be too slow).

The main issue here, as I see it, is not so much the speed, as the
extensibility.  We want to be able to add in bunches of new syntaxes
without the parser becoming too unwieldy.  If you just have a list of
regular expression search and replaces, this could easily happen.

Actually, this is probably an independent consideration.  A nice,
object oriented approach that does a good job of abstraction could use
regular expressions, or a hand coded parser, or whatever internally.

>
> Way 2: Use a Perl-compatible regular expression engine. PCRE engines do have
> support for parsing nested parentheses, see http://www.pcre.org/pcre.txt and
> search for "recursive back references".
> That support is limited both in what can be parsed and what you can do with
> the parse, so it may or may not help in this particular case.

Is there a way to do PCRE in Python?

>
> Regards,
> Jo

Aaron Meurer

>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to