void CParseTreeNode::MakeAction(int action_constant)
{
	assert(TokenIsOpenPPLAction(action_constant));
  CString action_name = TokenString(action_constant);
  assert(action_name != "");
  MakeIdentifier(action_name);
}
Beispiel #2
0
int ExpectingToken(             // ISSUE EXPECTING ERROR FOR A TOKEN
    TOKEN token )               // - required token
{
    TOKEN alt_token;

    /* also accept alternative tokens (digraphs) */
    switch( token ) {
    case T_LEFT_BRACKET:
        alt_token = T_ALT_LEFT_BRACKET;
        break;
    case T_RIGHT_BRACKET:
        alt_token = T_ALT_RIGHT_BRACKET;
        break;
    case T_LEFT_BRACE:
        alt_token = T_ALT_LEFT_BRACE;
        break;
    case T_RIGHT_BRACE:
        alt_token = T_ALT_RIGHT_BRACE;
        break;
    default:
        alt_token = token;
        break;
    }
    if( ( CurToken == token ) || ( CurToken == alt_token ) ) {
        return( 1 );
    }
    CErr( ERR_EXPECTING_BUT_FOUND, Tokens[token], TokenString() );
    return( 0 );
}
//?????!!!!!
double CParseTreeTerminalNodeFixedAction::Evaluate(bool log /* = false */){
  write_log(preferences.debug_formula(), 
    "[CParseTreeTerminalNode] Evaluating node type %i %s\n", 
		_node_type, TokenString(_node_type));
  p_autoplayer_trace->SetLastEvaluatedRelativeLineNumber(_relative_line_number);
	// Most common types first: numbers and identifiers
  if (_node_type == kTokenIdentifier) {
    assert(_first_sibbling  == NULL);
    assert(_second_sibbling == NULL);
    assert(_third_sibbling  == NULL);
		assert(_terminal_name != "");
		double value = EvaluateIdentifier(_terminal_name, log);
		write_log(preferences.debug_formula(), 
      "[CParseTreeTerminalNode] Identifier evaluates to %6.3f\n", value);
    // In case of f$-functions the line changed inbetween,
    // so we have to set it to the current location (again)
    // for the next log.
    p_autoplayer_trace->SetLastEvaluatedRelativeLineNumber(_relative_line_number);
		return value;
	} else if (TokenIsElementaryAction(_node_type)) { //?????
		return (0 - _node_type);
  }
	// This must not happen for a terminal node
	assert(false);
	return kUndefined;
}
Beispiel #4
0
/*!
	@brief try to find begin/end parameter
	@return parameter of \begin or \end
*/
TokenString	Parser::_get_begroup(void)
{
	_skip_whitechars();
	_readchar();
	if (_char != lbrace )
		return TokenString();
	_skip_whitechars();
	_readnexttoken();
	TokenString pom(_tokenstring);
	_skip_whitechars();
	_readnexttoken();
	if (_token != rbrace)
	{
		//std::cerr << "Chybny parametr u end/begin" << std::endl;
		return TokenString();
	}
	return pom;
}
Beispiel #5
0
double CParseTreeOperatorNode::Evaluate(bool log /* = false */) {
  write_log(preferences.debug_formula(), 
    "[CParseTreeOperatorNode] Evaluating node type %i %s\n", 
		_node_type, TokenString(_node_type));
  p_autoplayer_trace->SetLastEvaluatedRelativeLineNumber(_relative_line_number);
	// Actions first, which are "unary".
	// We have to encode all possible outcomes in a single floating-point,
	// therefore:
	// * positive values mean: raise size (by big-blinds, raise-to-semantics) 
	// * negative values mean: elementary actions
	if (_node_type == kTokenActionRaiseToBigBlinds)	{
    // RaiseTo N Force
		return EvaluateSibbling(_first_sibbling, log);
	}	else if (_node_type == kTokenActionRaiseByBigBlinds)	{
    // RaiseBy N Force
    double raise_by_amount_in_bblinds = EvaluateSibbling(_first_sibbling, log);
    double final_betsize_in_bblinds = p_symbol_engine_chip_amounts->ncallbets()
      + raise_by_amount_in_bblinds;
    write_log(preferences.debug_formula(), 
      "[CParseTreeOperatorNode] raiseby = %.2f ncallbets = %.2f final = %.2f\n",
      raise_by_amount_in_bblinds,
      p_symbol_engine_chip_amounts->ncallbets(),
      final_betsize_in_bblinds);
		return final_betsize_in_bblinds;
	}	else if (_node_type == kTokenActionRaiseByPercentagedPotsize)	{
    // RaiseBy X% Force
		double raise_by_percentage = EvaluateSibbling(_first_sibbling, log);
    assert(p_symbol_engine_tablelimits->bet() > 0);
		double pot_size_after_call_in_big_blinds = 
      (p_symbol_engine_chip_amounts->pot() / p_symbol_engine_tablelimits->bet()) 
      + p_symbol_engine_chip_amounts->nbetstocall();
    assert(pot_size_after_call_in_big_blinds >= 0);
		double raise_by_amount_in_bblinds = 0.01 * raise_by_percentage
			* pot_size_after_call_in_big_blinds;
    double final_betsize_in_bblinds = p_symbol_engine_chip_amounts->ncallbets()
      + raise_by_amount_in_bblinds;
    write_log(preferences.debug_formula(), 
      "[CParseTreeOperatorNode] raiseby percentage = %.2f pot after call = %.2f raiseby = %.2f final = %.2f\n",
      raise_by_percentage,
      pot_size_after_call_in_big_blinds,
      raise_by_amount_in_bblinds,
      final_betsize_in_bblinds);
    return final_betsize_in_bblinds;
  } else if (TokenIsElementaryAction(_node_type)) {
		return (0 - _node_type);
  }
	// Finally operators
	else if (TokenIsUnary(_node_type)) {
		return EvaluateUnaryExpression(log);
	}	else if (TokenIsBinary(_node_type))	{
		return EvaluateBinaryExpression(log);
	}	else if (TokenIsTernary(_node_type)) {
		return EvaluateTernaryExpression(log);
	}
	assert(false);
	return kUndefined;
}
CString CParseTreeNode::Serialize()
{
  if (_node_type == kTokenIdentifier) {
    return _terminal_name;
  } else if (_node_type == kTokenNumber) {
    return Number2CString(_constant_value);
  } else if (TokenIsBracketOpen(_node_type)) {
    return ("(" + _first_sibbling->Serialize() + ")");
  } else if (TokenIsUnary(_node_type)) {
    assert(_first_sibbling != NULL);
    return TokenString(_node_type) + "(" + _first_sibbling->Serialize() + ")";
  } else if (TokenIsBinary(_node_type)) {
    assert(_first_sibbling != NULL);
    assert(_second_sibbling != NULL);
    return "(" + _first_sibbling->Serialize() + " "
      + TokenString(_node_type) + " " + _second_sibbling->Serialize() + ")";
  } else if (_node_type == kTokenOperatorConditionalIf) {
    assert(_first_sibbling != NULL);
    assert(_second_sibbling != NULL);
    assert(_third_sibbling != NULL);  
    return "(" + _first_sibbling->Serialize() + " ? "
      + _second_sibbling->Serialize() + " : "
      + _third_sibbling->Serialize() + ")";
  } else if (IsOpenEndedWhenCondition()) {
    return "WHEN: " + _first_sibbling->Serialize() + "\n"
      + (_second_sibbling? _second_sibbling->Serialize(): "")
      // No third sibbling to serialize, because this is the next open-ender
      // and TWO pointers point to it (one from a normal "when")
      + "WEND";
  } else if (IsWhenConditionWithAction()) {
    return "    WHEN: " + _first_sibbling->Serialize() + "WRETURN: "
      + (_second_sibbling? _second_sibbling->Serialize(): "") + "\n"
      // Third sibbling: either next when-condition or next open-ended when-condition
      + (_third_sibbling? _third_sibbling->Serialize(): "");
  } else {
    // Unhandled note-type, probably new and therefore not yet handled
    write_log(k_always_log_errors, "[CParseTreeNode] ERROR: Unhandled node-tzpe %i in serialiyation of parse-tree\n",
      _node_type);
    return "";
  }
}
double CParseTreeTerminalNodeNumber::Evaluate(bool log /* = false */){
 write_log(Preferences()->debug_formula(), 
    "[CParseTreeTerminalNode] Evaluating node type %i %s\n", 
		_node_type, TokenString(_node_type));
  p_autoplayer_trace->SetLastEvaluatedRelativeLineNumber(_relative_line_number);
	if (_node_type == kTokenNumber)	{
		write_log(Preferences()->debug_formula(), 
      "[CParseTreeTerminalNode] Number evaluates to %6.3f\n",
			_constant_value);
		return _constant_value;
	}
	// This must not happen for a terminal node
	assert(false);
	return kUndefined;
}
double CParseTreeTerminalNodeNumber::Evaluate(bool log /* = false */){
  write_log(preferences.debug_formula(), 
    "[CParseTreeTerminalNode] Evaluating node type %i %s\n", 
		_node_type, TokenString(_node_type));
  p_autoplayer_trace->SetLastEvaluatedRelativeLineNumber(_relative_line_number);
	// Most common types first: numbers and identifiers
	if (_node_type == kTokenNumber)	{
		write_log(preferences.debug_formula(), 
      "[CParseTreeTerminalNode] Number evaluates to %6.3f\n",
			_constant_value);
		return _constant_value;
	}
	// Actions second, which are also "unary".
	// We have to encode all possible outcomes in a single floating-point,
	// therefore:
	// * positive values mean: raise size (by big-blinds, raise-to-semantics) 
	// * negative values mean: elementary actions
  else if (TokenIsElementaryAction(_node_type)) {
		return (0 - _node_type);
  }
	// This must not happen for a terminal node
	assert(false);
	return kUndefined;
}
Beispiel #9
0
void Expecting(                 // ISSUE EXPECTING ERROR FOR A TOKEN
    const char *a_token )       // - required token
{
    CErr( ERR_EXPECTING_BUT_FOUND, a_token, TokenString() );
}
bool CSrScriptFile::Tokenize (void)
{
	static const int CSP = 1;
	static const int CNM = 2;
	static const int CAL = 3;
	static const int COP = 4;
	static const int CDO = 5;
	static const int CCM = 6;
	static const int CST = 7;
	static const int CEN = 8;
	static const int CLN = 9;
	static const int CCN = 10;

	static const int s_CharTypes[256] = 
	{
	  CEN,  0,  0,  0,  0,  0,  0,  0,  0,CSP,CLN,  0,  0,CLN,  0,  0,
	    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  CSP,COP,CST,  0,  0,COP,COP,  0,COP,COP,COP,COP,COP,COP,COP,COP,		
 	  CNM,CNM,CNM,CNM,CNM,CNM,CNM,CNM,CNM,CNM,  0,CCM,COP,COP,COP,  0,
		0,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,
      CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,COP,CCN,COP,  0,CAL,
		0,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,
	  CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CAL,CDO,COP,  0,  0,  0,
	    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
		0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
		0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
		0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
		0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
		0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
		0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
	};

	const char* pParse;
	bool        Result;

	m_Tokens.Destroy();

	srtimer_t TokenTimer;
	SrStartTimer(TokenTimer);

	pParse = m_ScriptText.c_str();

	while (*pParse)
	{
		while (s_CharTypes[*pParse] == CSP) ++pParse;

		switch (s_CharTypes[*pParse])
		{
		case CCN:
			++pParse;
			while (s_CharTypes[*pParse] == CSP) ++pParse;
			while (s_CharTypes[*pParse] == CLN) ++pParse;
			while (s_CharTypes[*pParse] == CSP) ++pParse;
			break;
		case CLN:
			Result = TokenEOL(pParse);
			if (!Result) return false;
			break;
			break;
		case CNM:
			Result = TokenNumber(pParse);
			if (!Result) return false;
			break;
		case CAL:
			Result = TokenAlpha(pParse);
			if (!Result) return false;
			break;
		case CDO:
			Result = TokenDocument(pParse);
			if (!Result) return false;
			break;
		case CCM:
			Result = TokenComment(pParse);
			if (!Result) return false;
			break;
		case COP:
			Result = TokenOperator(pParse);
			if (!Result) return false;
			break;
		case CST:
			Result = TokenString(pParse);
			if (!Result) return false;
			break;
		default:
			AddSrGeneralError("Found unknown character '%c'(0x%02X) in script!", *pParse, *pParse);
			return false;
		}

	}

	srscripttoken_t* pToken = m_Tokens.AddNew();
	pToken->Type = SR_TOKEN_END;

	SrEndTimer(TokenTimer, "Script Tokenized in ");

	//DumpTokens();
	return true;
}
double CParseTreeNode::Evaluate(bool log /* = false */){
  write_log(preferences.debug_formula(), 
    "[CParseTreeNode] Evaluating node type %i %s\n", 
		_node_type, TokenString(_node_type));
  p_autoplayer_trace->SetLastEvaluatedRelativeLineNumber(_relative_line_number);
	// Most common types first: numbers and identifiers
	if (_node_type == kTokenNumber)	{
		write_log(preferences.debug_formula(), 
      "[CParseTreeNode] Number evaluates to %6.3f\n",
			_constant_value);
		return _constant_value;
	}	else if (_node_type == kTokenIdentifier) {
    assert(_first_sibbling  == NULL);
    assert(_second_sibbling == NULL);
    assert(_third_sibbling  == NULL);
		assert(_terminal_name != "");
		double value = EvaluateIdentifier(_terminal_name, log);
		write_log(preferences.debug_formula(), 
      "[CParseTreeNode] Identifier evaluates to %6.3f\n", value);
    // In case of f$-functions the line changed inbetween,
    // so we have to set it to the current location (again)
    // for the next log.
    p_autoplayer_trace->SetLastEvaluatedRelativeLineNumber(_relative_line_number);
		return value;
	}
	// Actions second, which are also "unary".
	// We have to encode all possible outcomes in a single floating-point,
	// therefore:
	// * positive values mean: raise size (by big-blinds, raise-to-semantics) 
	// * negative values mean: elementary actions
	else if (_node_type == kTokenActionRaiseToBigBlinds)	{
    // RaiseTo N Force
		return EvaluateSibbling(_first_sibbling, log);
	}	else if (_node_type == kTokenActionRaiseByBigBlinds)	{
    // RaiseBy N Force
    double raise_by_amount_in_bblinds = EvaluateSibbling(_first_sibbling, log);
    double final_betsize_in_bblinds = p_symbol_engine_chip_amounts->ncallbets()
      + raise_by_amount_in_bblinds;
    write_log(preferences.debug_formula(), 
      "[CParseTreeNode] raiseby = %.2f ncallbets = %.2f final = %.2f\n",
      raise_by_amount_in_bblinds,
      p_symbol_engine_chip_amounts->ncallbets(),
      final_betsize_in_bblinds);
		return final_betsize_in_bblinds;
	}	else if (_node_type == kTokenActionRaiseByPercentagedPotsize)	{
    // RaiseBy X% Force
		double raise_by_percentage = EvaluateSibbling(_first_sibbling, log);
    assert(p_symbol_engine_tablelimits->bet() > 0);
		double pot_size_after_call_in_big_blinds = 
      (p_symbol_engine_chip_amounts->pot() / p_symbol_engine_tablelimits->bet()) 
      + p_symbol_engine_chip_amounts->nbetstocall();
    assert(pot_size_after_call_in_big_blinds >= 0);
		double raise_by_amount_in_bblinds = 0.01 * raise_by_percentage
			* pot_size_after_call_in_big_blinds;
    double final_betsize_in_bblinds = p_symbol_engine_chip_amounts->ncallbets()
      + raise_by_amount_in_bblinds;
    write_log(preferences.debug_formula(), 
      "[CParseTreeNode] raiseby percentage = %.2f pot after call = %.2f raiseby = %.2f final = %.2f\n",
      raise_by_percentage,
      pot_size_after_call_in_big_blinds,
      raise_by_amount_in_bblinds,
      final_betsize_in_bblinds);
    return final_betsize_in_bblinds;
  }	else if (_node_type == kTokenActionUserVariableToBeSet) {
    // User-variables are a special case of elementary actions
    // Therefore need to be handled first.
    SetUserVariable(_terminal_name);
		return kUndefinedZero;
  } else if (TokenIsElementaryAction(_node_type)) {
		return (0 - _node_type);
  }
	// Finally operators
	else if (TokenIsUnary(_node_type)) {
		return EvaluateUnaryExpression(log);
	}	else if (TokenIsBinary(_node_type))	{
		return EvaluateBinaryExpression(log);
	}	else if (TokenIsTernary(_node_type)) {
		return EvaluateTernaryExpression(log);
	}
	assert(false);
	return kUndefined;
}