math expression validator, not evaluator?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Thanks Dave,
To repeat the question:
I am developing a WinForms application and I need a Math Expression
validator, not an expression evaluator. So I want to be able to say...

if ((sales - tax) > 20)
THEN (x * y * 0.55)

without knowing at runtime what the values of sales, tax, x and y are. Is
there any software out there that will do this validation for me?

//NEEDS
I do not know and do not care about these values at runtime. These are rules
that will be stored in a database, and weeks later someone may pull this out
and provide values for the variables and then evaluate it.

Thanks in advance
 
I am not sure I understand your question, but I think you need a parser:
something that would take a string and say if it were a valid expression,
according to some set of rules.

The easiest kind of parser to write is a "recursive descent parser". You can
find the technique on the web. I have written some code that might help you
get a start: http://www.frontiernet.net/~fredm/dps/Contents.htm , Chapter 3.

To use the code, you will need to write a "lexigraphical analyzer" to turn
the input string into some token objects. To do that, you can use the RegEx
class in C#.
 
Faraz said:
I am developing a WinForms application and I need a Math Expression
validator, not an expression evaluator. So I want to be able to say...

if ((sales - tax) > 20)
THEN (x * y * 0.55)

without knowing at runtime what the values of sales, tax, x and y are. Is
there any software out there that will do this validation for me?

//NEEDS
I do not know and do not care about these values at runtime. These are
rules
that will be stored in a database, and weeks later someone may pull this
out
and provide values for the variables and then evaluate it.

If you are willing to use syntax that matches one of the .NET lanuages, you
can use the framework's CodeDOM classes to compile. The .NET language
compilers come with all installations of the .NET Framework. CodeDOM will
tell you if compiling fails.

-- Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top