public float EvaluateFiringStrength( )
{
// Stack to store the operand values
Stack<float> s = new Stack<float>( );
// Logic to calculate the firing strength
foreach ( object o in rpnTokenList )
{
// if its a clause, then its value must be calculated and pushed
if ( o.GetType( ) == typeof( Clause ) )
{
Clause c = o as Clause;
s.Push( c.Evaluate( ) );
}
// if its an operator (AND / OR) the operation is performed and the result
// returns to the stack
else
{
float y = s.Pop( );
float x = 0;
// unary pops only one value
if ( unaryOperators.IndexOf( o.ToString( ) ) < 0 )
x = s.Pop( );
// operation
switch ( o.ToString( ) )
{
case "AND":
s.Push( normOperator.Evaluate( x, y ) );
break;
case "OR":
s.Push( conormOperator.Evaluate( x, y ) );
break;
case "NOT":
s.Push( notOperator.Evaluate( y ) );
break;
}
}
}
// result on the top of stack
return s.Pop( );
}
}