TPParseTreeNode CFormulaParser::ParseOpenPPLRaiseByExpression() { // There are 3 possibilities // RAISE <Amount> FORCE // RAISE <PercentagedPot>% FORCE // // Keyword RAISE got already consumed TPParseTreeNode action = new CParseTreeNode(_tokenizer.LineRelative()); TPParseTreeNode expression; int _token_ID = _tokenizer.LookAhead(); if ((_token_ID == kTokenNumber) || (_token_ID == kTokenIdentifier) || TokenIsBracketOpen(_token_ID)){ expression = ParseExpression(); } else { CParseErrors::Error("Missing expression after keyword RaiseBy.\n" "Expecting the betsize in big blinds or a potsize-expression.\n" "Example: WHEN ... RAISEBY 60% FORCE\n"); return NULL; } _token_ID = _tokenizer.LookAhead(); if (_token_ID == kTokenOperatorPercentage) { // Percentaged Potsize _tokenizer.GetToken(); action->MakeRaiseByPercentagedPotsizeAction(expression); return action; } else { // Raise by N big blinds action->MakeRaiseByAction(expression); return action; } }
TPParseTreeNode CFormulaParser::ParseOpenPPLAction(){ int token_ID = _tokenizer.GetToken(); assert(TokenIsOpenPPLAction(token_ID)); TPParseTreeNode action; if (token_ID == kTokenActionReturn) { // RETURN <Expression> FORCE action = ParseExpression(); ExpectKeywordForce(token_ID); } else if (token_ID == kTokenActionRaiseTo) { // NL-betsizing // RaiseTo N Force action = ParseOpenPPLRaiseToExpression(); ExpectKeywordForce(token_ID); } else if (token_ID == kTokenActionRaiseBy) { // NL-betsizing // There are 2 possibilities // RaiseBy N Force // RaiseBy X% Force action = ParseOpenPPLRaiseByExpression(); ExpectKeywordForce(token_ID); } else if (token_ID == kTokenActionUserVariableToBeSet) { action = ParseOpenPPLUserVar(); // Not expecting keyword Force here } else { // Predefined action, like Check or Fold action = new CParseTreeNode(_tokenizer.LineRelative()); action->MakeAction(token_ID); ExpectKeywordForce(token_ID); } return action; }
TPParseTreeNode CFormulaParser::ParseOpenPPLRaiseToExpression() { // RaiseTo N Force // Keyword RaiseTo got already consumed TPParseTreeNode action = new CParseTreeNode(_tokenizer.LineRelative()); TPParseTreeNode expression; int _token_ID = _tokenizer.LookAhead(); if ((_token_ID == kTokenNumber) || (_token_ID == kTokenIdentifier) || TokenIsBracketOpen(_token_ID)) { expression = ParseExpression(); } else { CParseErrors::Error("Missing expression after keyword RaiseTo.\n" "Expecting the betsize in big blinds.\n"); return NULL; } action->MakeRaiseToAction(expression); return action; }
double CParseTreeNode::EvaluateSibbling( TPParseTreeNode first_second_or_third_sibbling, bool log) { // We allow NULL-nodes here, because that can happen // after the end of a sequence of when-conditions if (first_second_or_third_sibbling == NULL) { return kUndefinedZero; } double result = first_second_or_third_sibbling->Evaluate(log); return result; }
TPParseTreeNode CFormulaParser::ParseOpenPPLUserVar() { // User-variable to be set int token_ID = _tokenizer.GetToken(); if (token_ID != kTokenIdentifier) { CParseErrors::Error("Unexpected token.\n" "User-variable or memory-store-command expected.\n"); return NULL; } CString identifier = _tokenizer.GetTokenString(); if ((identifier.Left(4).MakeLower() != "user") && (identifier.Left(3) != "me_")) { CParseErrors::Error("Unexpected identifier.\n" "Valid options:\n" " * user-variable (user_utg_limp_raised)\n" " * memory-store-command (me_st_pi_3_141592653)\n" " * memory-increment-command (me_inc_flopsseen)\n"); return NULL; } TPParseTreeNode action = new CParseTreeNode(_tokenizer.LineRelative()); action->MakeUserVariableDefinition(identifier); // Not expecting any Force here return action; }
double CParseTreeOperatorNode::EvaluateSibbling( TPParseTreeNode first_second_or_third_sibbling, bool log) { // We allow NULL-nodes here, because that can happen // after the end of a sequence of when-conditions if (first_second_or_third_sibbling == NULL) { // When evaluating an empty tree we evaluate a special symbol // kEmptyxpression_False_Zero_WhenOthersFoldForce // for better readability of the log-file. double null_value = CParseTreeTerminalNodeIdentifier::EvaluateIdentifier( kEmptyExpression_False_Zero_WhenOthersFoldForce, log); write_log(preferences.debug_formula(), "[CParseTreeOperatorNode] Evaluating empty tree: false / zero / fold\n"); assert(null_value == kUndefinedZero); return null_value; } double result = first_second_or_third_sibbling->Evaluate(log); return result; }