protected bool ValidateToken( int rulePathIdx, Symbol activeRuleID )
{
int tokenlength = 0;
// assume the test is going to fail
bool passed = false;
Symbol tokenID = rootRulePath[ rulePathIdx ].tokenID;
// only validate token if context is correct
if ( ( symbolTypeLib[ (int)tokenID ].contextKey & activeContexts ) > 0 )
{
int ruleID = symbolTypeLib[ (int)tokenID ].ruleID;
// if terminal token then compare text of symbol with what is in source
if ( ruleID == 0 )
{
if ( PositionToNextSymbol() )
{
// if Token is supposed to be a number then check if its a numerical constant
if ( tokenID == valueID )
{
float constantvalue;
if ( passed = IsFloatValue( out constantvalue, out tokenlength ) )
{
constants.Add( constantvalue );
}
}
// compare token symbol text with source text
else
{
passed = IsSymbol( rootRulePath[ rulePathIdx ].symbol, out tokenlength );
}
if ( passed )
{
TokenInstruction newtoken;
// push token onto end of container
newtoken.ID = tokenID;
newtoken.NTTRuleID = activeRuleID;
newtoken.line = currentLine;
newtoken.pos = charPos;
tokenInstructions.Add( newtoken );
// update source position
charPos += tokenlength;
// allow token instruction to change the ActiveContexts
// use token contexts pattern to clear ActiveContexts pattern bits
activeContexts &= ~symbolTypeLib[ (int)tokenID ].contextPatternClear;
// use token contexts pattern to set ActiveContexts pattern bits
activeContexts |= symbolTypeLib[ (int)tokenID ].contextPatternSet;
}
}
}
// else a non terminal token was found
else
{
// execute rule for non-terminal
// get rule_ID for index into rulepath to be called
passed = ProcessRulePath( symbolTypeLib[ (int)tokenID ].ruleID );
}
}
return passed;
}