C# Evaluate BEDMAS Strings
Posted: 11 Oct 2009, 04:09
So... I have need of a function that can take four parameters as,
public float (string func, float x, float y, float z) and return the result of the function with those parameters filled in... for example pass:
"1-z*(x+y-(2*x*y))", 0.5, 0.9, 0.2
and return the result of 0.9
I'm pretty sure I can manage it with a nice recursive function to break it down... but it seems like kinda a trivial thing to do... I was wondering if anyone has already done this or has run across it in programming and can give me a few hints... Google has been no help as putting "function" and "string" into a query doesn't yield the desired results... it sounds like a kind-of text-book-case that I should be able to easily find a code example for to snag.
In the end, there are only 255 valid functions so I'll probably end up just putting a case selection in the code instead... but I'd prefer a nice simple code block to use.
public float (string func, float x, float y, float z) and return the result of the function with those parameters filled in... for example pass:
"1-z*(x+y-(2*x*y))", 0.5, 0.9, 0.2
and return the result of 0.9
I'm pretty sure I can manage it with a nice recursive function to break it down... but it seems like kinda a trivial thing to do... I was wondering if anyone has already done this or has run across it in programming and can give me a few hints... Google has been no help as putting "function" and "string" into a query doesn't yield the desired results... it sounds like a kind-of text-book-case that I should be able to easily find a code example for to snag.
In the end, there are only 255 valid functions so I'll probably end up just putting a case selection in the code instead... but I'd prefer a nice simple code block to use.