How to check the final result type of an expression...

Feb 26, 2010 at 3:00 PM

Hi,

 

I was wondering if there is any easy way to find out if a given expression will result in a boolean value or a numeric value.

For example, if I have an expression (A + B * C)/D, I know this will result in a numeric value, whereas an expression like ((A & B) = B) would result in a boolean value. Is there a way I can check this using NCalc?

In my specific requirement, user indicates that he wants to build a boolean/numeric expression, I need to ensure that the expression that he has supplied indeed results in a boolean/numeric value. Initially I though, just looking for boolean operators in the expression should tell me that, but expressions like (A & B)  (bitwise AND) actually results in a numeric value.

Any ideas?

Thanks,

Regards,

- Vikram

 

 

Coordinator
Feb 27, 2010 at 7:49 AM

Well, everything with '&&' or 'and' results in boolean, whereas '&' only results in numeric value. In a more scientific way, you can create a specific Visitor implementation for evaluating each node and returning the intended type. Just like the ExpressionVisitor class.

Mar 3, 2010 at 3:43 AM

Thanks Sebastien,

I will try that out.

Regards,

- Vikram

Feb 1, 2013 at 8:19 AM
Hi Sebastien,

I'm new to NCal so I would appreciate it if you could give me an example or more info on the visitor implementation.

Many thanks,

Nero
Feb 4, 2013 at 8:03 AM
Hi Nero,

We did try to implement the visitor as suggested by Sebastien, but eventually we switched to using flee.codeplex.com, which was more suitable for our requirements.

Sorry - couldn't be much help.

Regards,
Vikram