Given the expression
x^2 + y^2 + z^2 = 1
You should immediately notice that this describes the unit sphere (dur), which isn't a function. One of the many methods I'm considering using to cripple this is to limit the input to functions, such that for any pair (x,y) there exists only one output z.
Thus, the above expression becomes
f1(x,y) = ( 1 - x^2 - y^2 ) ^ ( 1/2 )
f2(x,y) = - ( 1 - x^2 - y^2 ) ^ ( 1/2 )
The most obvious disadvantage to this is that our nice little expression for a sphere becomes this distorted crazah set of equations. So yeah. Deal with it for now I guess.
That said, the parser consists of three main "ideas"/components.
- Values - a construct which represents a value in an expression, whether its a variable or a constant, or whatever.
- Expressions - a pair of values and/or expressions combined with an operation.
- Statement - a list of expressions and/or statements which operate on one another.
Taking f1 from above, we can parse it like -
f1( x, y ) = // defines a statement f1.
That's nice and clean, but the rest of it gets ugly. Very ugly. Even by my standards -
( ( ( (1) - (x^2) ) - (y^2) ) ) ^ (1/2)
expression( expression( expression( value(1) minus expression( value(x) power value(2) ) minus expression( value(y) power value(2) ) ) power expression( value(1) divided by value(2) )
Which, although it does seem kind of easy to parse since I've passed it nicely organized input with all the order-of-operations laid out for it. It shouldn't be _that_ hard to parse it without - just search left-to-right looking for operators.
Which is exactly the part I'm not looking forward to - searching around a string looking for yummy details to parse. We'll see what happens...
[ ^_^ ]/[ O_o ]