Untitled
Please kill me. Please… 
I think I’m done with this parser nonsense. Variables were pie to fix. Then I started adding in the stuff for unary operaters (basically, trig functions, inverse trig functions and log).
So I do a test.
INPUT: cos0
OUTPUT: 1
And I suddenly feel really really happy because omg it was working!
And how wrong I was. If we illustrate this with a picture of a tree…

This isn’t what we want – the value of cos is being calculated based on the default value (0), not on the actual input. ARRGH! This took me some brain bashing to fix. For reference, we want it too look like this -

The actual solution doesn’t look like that though, but it almost does. Almost. Its a little messier 

Well, I guess it doesn’t make that much of a difference. It looks pretty messy in code though:
void apply( unsigned int op, IEvalable< T, V >* expr ) {
if ( op == OP_SIN ||
op == OP_COS ||
op == OP_TAN ||
op == OP_LOG ||
op == OP_ASIN ||
op == OP_ACOS ||
op == OP_ATAN ) {
splice< OP_ADD >( expr );
append( op );
}
else {
splice( op, expr );
}
}
But yeah. Hopefully there are no big oversights. There are still some bugs, like OP_LOG doesn’t work for shit. But I don’t care at this point.
Tommorrow I’m going to write some rendering functions and we can start rendering single-variable graphs. Then after that I’ll implement an OGL renderer and we can play with MULTIVARIABLE GRAPHS :D :D
And then I’m throwing this project into the fucking portfolio. Because that’s the only reason I chose to do it… grr. Bad idea.
2 commentsUntitled
Unforseen troubles.
So, I wrote that piece of #(%*)# #)(%*)( #*&% )#&%)# %)*#. It took all day, pain in the #)%**) but it appears to work. That is, it parses something like
(2+((3^2)*3))
Into a nice little tree which can be evaluated. But get this -
INPUT: 10^2-100+200/10^2
OUTPUT: = -2
See what’s going on here? The actual output should be positive 2, not negative. For those of you who don’t see it yet – lets examine the expanded output (first parse step) -
INPUT: 10^2-100+200/10^2
OUTPUT: ((10^2)-(100+(200/(10^2))))
See the bugger? the + operation is taking precidence over the - operation instead of being evaluated right-to-left with equal precidence. The culpret?
string pawn::equ::expand( string equ ) {
// ...
equ = expand( equ, "+" );
equ = expand( equ, "-" );
// ...
return equ;
}
Yeah. Shit.
I never ever thought that I should be evaluating multiple symbols at the same time. Which is bad. Very very bad. Because, well, it doesn’t work.
But the good news is that the expander works by searching to searching for the token string in something something, yadda yadda its one giant hack.
Oddly enough, two wrongs may not make a right, but too hacks certainly do make a solution:
string pawn::equ::expand( string equ ) {
// ...
equ = expand( equ, "+|-" );
// ...
return equ;
}
Do I know why it works? No. In fact it shouldn’t work at all. But it does so I’m not going to bother with it.
INFINITE IMPROBABILITY GOOO!!!!
2 comments
