Hi "Z",

On Sunday 24 Apr 2011 15:08:18 z sway wrote:
> the expression only contains number and"+*()"
> the form of list is like[op,node1,node2...],op is "+"or"*",node can be a
> number or a child list.
> e.g :1*2+3*4*(5+6)
>       [ '+', ['*', '1', '2'], ['*', '3', '4', ['+','5', '6'] ] ]
> Thanks!

Well, I think I understand your question. If you:

1. Want to parse the statements look at the various parser generators on CPAN:

http://perl-begin.org/uses/text-parsing/#parser-generators

This seems what you want. Using them requires some knowledge in the underlying 
theory of the so-called "formal languages" and "context-free grammars" (whose 
study has a lot of discrete mathematics formalism, but is conceptually very 
simple), and parsers generators tend to be very "subtle and quick to become 
angry" beasts - i.e: they are hard to get right and often expose 
implementation details.

2. If you want to generate a serial expression from a tree, then this can be 
easily done sub-optimally using recursion, but will require more logic to do 
properly (i,e: while omitting unnecessary parentheses).. See:

http://en.wikipedia.org/wiki/Computer_algebra_system

Implementing a full user-friendly system like that is probably out-of-scope 
for what you want, and serious, proprietary, mathematical software (e.g: 
Mathematica, Matlab, Maple, etc.) can cost you a lot of money (unless you are 
a student).

--------------

Hope that helps, because your message was a bit vague. My mind reading device 
is on repair, not to mention that it is limited to a 10 kilometer radius 
beyond which I am unable to read people's mind clearly enough, due to natural 
technological limitations. ;-) (Old joke - ignore.).

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

I hope that you agree with me that 99.9218485921% of the users wouldn't bother
themselves with recompilation (or any other manual step for that matter) to
make their games run 1.27127529900685765% faster ;-) -- Nadav Har'El

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to