Hi,

On 24 November 2011 18:18, Aaron Meurer <[email protected]> wrote:

> I think the problem is that you can't parse this with regular
> expressions.  You need a more advanced parser.  This is because
> regular expressions cannot solve the matching parentheses problem
> (given a string of left and right parentheses, determine if the
> parentheses match).  In this case, the regular expression replaces one
> implied multiplication (the first one it sees), and so it fails when
> there is another one.  You could modify it to replace n implied
> multiplications, but it would break for n + 1.
>

pyparsing should be enough to implement this. More sophisticated regular
expressions could fake desired parsing functionality, but for a recursive
language they are simply ill suited.


>
> The solution is to write an actual parser.  I don't know the best way
> to do this.  Perhaps the one that we use for sympify can be adapted.
> This is actually the same problem as with the LaTeX parser.  What's
> the best way to write an extensible parser? Can the AST module perhaps
> be used (or does that only work for Python syntax)?


ASTs allow to modify semantics of Python language. It could help if you
wanted to add a preparser for things like 2 x (in Python).


>
> Aaron Meurer
>
> On Wed, Nov 23, 2011 at 10:20 AM, gsagrawal <[email protected]> wrote:
> > There are some issues in regex expressions of mathematica.
> > See below cases
> >
> > k="(h+g)(l+m)r"
> > print mathematica(k)
> > output -> (g + h)*(l + m)
> > k="r(h+g)(l+m)"
> > print mathematica(k)
> > output ->Exception
> >
> > i am new to regex so can anyone provide the correct regex expressions  ?
> >
> > --
> > 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.
>
>
Mateusz

-- 
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