How create a operator tree?

Namespace rswhite4 at googlemail.com
Fri Aug 17 08:59:15 PDT 2012


On Friday, 17 August 2012 at 12:55:24 UTC, Timon Gehr wrote:
> On 08/17/2012 10:38 AM, Namespace wrote:
>> o_O
>> I was hoping that there is a shorter way than this.
>
> I hacked together the following little parser (not extensively 
> tested).
>
> http://dpaste.dzfl.pl/e616692e
>
> It transforms the input expression into polish notation, 
> ignoring space
> characters.
> Note that it is significantly shorter than the regex attempt.
>
> It handles numbers, unary +, -, binary +, -, *, /, ^, where ^
> associates to the right, as well as nested parentheses. It 
> should be
> trivial to extend. (in this case you might want to generate the 
> switch
> cases automatically from the operator precedence table.)

Genial. Exactly what I'm looking for. Thanks!


More information about the Digitalmars-d-learn mailing list