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; }
void CParseTreeNode::MakeAction(int action_constant) { assert(TokenIsOpenPPLAction(action_constant)); CString action_name = TokenString(action_constant); assert(action_name != ""); MakeIdentifier(action_name); }
TPParseTreeNode CFormulaParser::ParseOpenEndedWhenConditionSequence() { TPParseTreeNode last_when_condition = NULL; bool last_when_condition_was_open_ended = false; TPParseTreeNode first_when_condition_of_sequence = NULL; int token_ID = _tokenizer.LookAhead(); while (token_ID == kTokenOperatorConditionalWhen) { token_ID = _tokenizer.GetToken(); TPParseTreeNode condition = ParseExpression(); TPParseTreeNode when_condition = new CParseTreeNode(_tokenizer.LineRelative()); when_condition->MakeWhenCondition(condition); // Remember first when-condition if (first_when_condition_of_sequence == NULL) { first_when_condition_of_sequence = when_condition; } // Concatenate conditions in sequence if (last_when_condition != NULL) { if (last_when_condition_was_open_ended) { // Open ended when-conditions: // Second sibbling points to next when-condition // Third siblling points to next open-ender last_when_condition->_second_sibbling = when_condition; } else { // When condition with action (2nd sibbling) // Third sibbling oints to next when-conditon last_when_condition->_third_sibbling = when_condition; } } // For future back-patching last_when_condition = when_condition; // Next either: // * action // * another when-condition // * user-variable to be set token_ID = _tokenizer.LookAhead(true); if (TokenIsOpenPPLAction(token_ID)) { TPParseTreeNode action = ParseOpenPPLAction(); when_condition->_second_sibbling = action; // For future backpatching last_when_condition_was_open_ended = false; token_ID = _tokenizer.LookAhead(); } else if (token_ID == kTokenOperatorConditionalWhen) { // All work to do: in the next loop last_when_condition_was_open_ended = true; // LookAhead() already executed continue; } else if ((token_ID == kTokenEndOfFile) || (token_ID == kTokenEndOfFunction)) { // Parsing successfully finished break; } else { ErrorMissingAction(token_ID); break; } } return first_when_condition_of_sequence; }