本文整理汇总了C++中ExpressionNode类的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionNode类的具体用法?C++ ExpressionNode怎么用?C++ ExpressionNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExpressionNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
PassRefPtr<FunctionExecutable> FunctionExecutable::fromGlobalCode(const Identifier& functionName, ExecState* exec, Debugger* debugger, const SourceCode& source, int* errLine, UString* errMsg)
{
RefPtr<ProgramNode> program = exec->globalData().parser->parse<ProgramNode>(&exec->globalData(), debugger, exec, source, errLine, errMsg);
if (!program)
return 0;
StatementNode* exprStatement = program->singleStatement();
ASSERT(exprStatement);
ASSERT(exprStatement->isExprStatement());
if (!exprStatement || !exprStatement->isExprStatement())
return 0;
ExpressionNode* funcExpr = static_cast<ExprStatementNode*>(exprStatement)->expr();
ASSERT(funcExpr);
ASSERT(funcExpr->isFuncExprNode());
if (!funcExpr || !funcExpr->isFuncExprNode())
return 0;
FunctionBodyNode* body = static_cast<FuncExprNode*>(funcExpr)->body();
ASSERT(body);
return FunctionExecutable::create(&exec->globalData(), functionName, body->source(), body->usesArguments(), body->parameters(), body->lineNo(), body->lastLine());
}
示例2: ILOC
void IdentifierNode::generateILOCCode(Node* context) {
if (this->children->size() == 0) { // Variable
Symbol* symbol = Scope::getSymbol(this->symbol->getText());
Node* symbolScope = Scope::getScope(this->symbol->getText());
std::string* varAddressRegisterName = ILOC::getRegister(symbol->getText());
std::string registerBaseAddress = (symbolScope->getNodeType() == Common::NT_PROGRAM) ? "bss" : "fp";
std::stringstream symbolOffsetStr;
symbolOffsetStr << symbol->getOffset();
ILOC* instruction = new ILOC(Common::ILOC_LOADAI, registerBaseAddress, symbolOffsetStr.str(), *varAddressRegisterName, "");
this->addInstruction(instruction);
this->setLastRegister(*varAddressRegisterName);
} else { // vector
Symbol* symbol = Scope::getSymbol(this->symbol->getText());
Node* symbolScope = Scope::getScope(this->symbol->getText());
std::string* vectorAddressRegisterName = ILOC::getRegister(symbol->getText());
std::string registerBaseAddress = (symbolScope->getNodeType() == Common::NT_PROGRAM) ? "bss" : "fp";
std::stringstream symbolOffsetStr;
symbolOffsetStr << symbol->getOffset();
ILOC* instruction = new ILOC(Common::ILOC_ADDI, registerBaseAddress, symbolOffsetStr.str(), *vectorAddressRegisterName, "");
this->addInstruction(instruction);
std::string lastBaseRegister = *vectorAddressRegisterName;
std::string* indexRegisterName;
for (unsigned int i = 0; i < this->children->size(); i++) {
ExpressionNode* expression = dynamic_cast<ExpressionNode*>(this->children->at(i));
expression->generateILOCCode(this);
std::stringstream indexStream;
indexStream << i;
std::string* multResultRegisterName = ILOC::getRegister("INST_MULT_VEC_RESULT_" + indexStream.str());
indexRegisterName = ILOC::getRegister("INDEX_REGISTER_NAME_" + indexStream.str());
ILOC* instructionMult = new ILOC(Common::ILOC_MULTI, expression->getLastRegister(), "4", *multResultRegisterName, "");
ILOC* instructionLoadAO = new ILOC(Common::ILOC_LOADA0, lastBaseRegister, *multResultRegisterName, *indexRegisterName, "");
lastBaseRegister = *indexRegisterName;
this->addInstruction(instructionMult);
this->addInstruction(instructionLoadAO);
}
this->setLastRegister(*indexRegisterName);
}
}
示例3: simplify
ExpressionNode BinaryOperation::simplify(const ExpressionNode& root) const
{
ExpressionNode* left = root.getFirstChild();
if (left != 0)
{
if (left->getRight() != 0)
{
if ((left->getRight())->getRight() != 0)
{
throw ExpressionNode::WrongArityError("> 2 arguments for BinaryOperation");
}
return simplify( *left, *(left->getRight()) );
}
else
{
cerr << left << endl;
throw ExpressionNode::WrongArityError("only 1 argument for BinaryOperation");
}
}
else
{
throw ExpressionNode::WrongArityError("No arguments for BinaryOperation");
}
}
示例4:
bool ExpressionNode::operator== (const ExpressionNode& other) const
{
ExpressionNode *selfptr;
ExpressionNode *otherptr;
if (getType() == other.getType() &&
getOperation() == other.getOperation() &&
getVariable() == other.getVariable() &&
getValue() == other.getValue() )
{
selfptr = firstChild;
otherptr = other.getFirstChild();
while (selfptr != 0 && otherptr != 0)
{
if (*selfptr == *otherptr)
{
selfptr = selfptr->getRight();
otherptr = otherptr->getRight();
}
else
{
return false;
}
}
if (selfptr == 0 && otherptr == 0)
{
return true;
}
else
{
assert(selfptr != otherptr);
return false;
}
}
else
{
return false;
}
}
示例5: isAddable
bool Addition::isCompatible(const ExpressionNode& term1, const ExpressionNode& term2) const
{
clog << "checkpoint isAddable(" << term1 << ", " << term2 << ")" << endl;
const ExpressionNode * varpart1(0);
const ExpressionNode * varpart2(0);
const ExpressionNode * left;
const ExpressionNode * right;
if (term1.getType() == NUMBER)
{
varpart1 = 0;
}
else if (term1.getType() == OPERATION)
{
if (term1.getOperation() == &MULTIPLICATION)
{
left = term1.getFirstChild();
right = left->getRight();
if (left->getType() == NUMBER)
{
varpart1 = right;
}
else if (right->getType() == NUMBER)
{
varpart1 = left;
}
else
{
varpart1 = &term1;
}
}
else
{
varpart1 = &term1;
}
}
else // VARIABLE
{
assert(term1.getType() == VARIABLE);
varpart1 = &term1;
}
if (term2.getType() == NUMBER)
{
varpart2 = 0;
}
else if (term2.getType() == OPERATION)
{
if (term2.getOperation() == &MULTIPLICATION)
{
left = term2.getFirstChild();
right = left->getRight();
if (left->getType() == NUMBER)
{
varpart2 = right;
}
else if (right->getType() == NUMBER)
{
varpart2 = left;
}
else
{
varpart2 = &term2;
}
}
else
{
varpart2 = &term2;
}
}
else // VARIABLE
{
assert(term2.getType() == VARIABLE);
varpart2 = &term2;
}
if (varpart1 != 0 && varpart2 != 0)
{
if (*varpart1 == *varpart2)
{
return true;
}
else
{
return false;
}
}
else
{
if (varpart1 == 0 && varpart2 == 0)
{
// both numbers
return true;
}
else
{
return false;
}
}
//.........这里部分代码省略.........
示例6: switch
void ExpressionNode::ScopeAndType(ostream &out, int &numErrors) {
DeclarationNode *dPtr, *paramPtr, *tempdPtr;
ExpressionNode *argPtr;
int argCounter;
Types lhs_type, rhs_type, lhs_decl, rhs_decl, returnType;
bool isUnary, lhs_isArray, rhs_isArray, foundError;
lhs_type = rhs_type = lhs_decl = rhs_decl = returnType = Undefined; // initialize types to undefined
lhs_isArray = rhs_isArray = foundError = false; // initialize booleans to false
isUnary = true;
string nameToLookup;
switch (subKind) {
case AssignK:
op = "="; // populate the op for assignments with "=" to make Op logic work properly
// intentionally drop through to OpK case...
case OpK:
if (child[0] != NULL) {
child[0]->ScopeAndType(out, numErrors);
lhs_type = ((ExpressionNode *)child[0])->type; // grab lhs type
lhs_isArray = child[0]->getIsArray();
}
if (child[1] != NULL) {
isUnary = false;
child[1]->ScopeAndType(out, numErrors);
rhs_type = ((ExpressionNode *)child[1])->type; // grab lhs type
rhs_isArray = child[1]->getIsArray();
}
lookupTypes(op, lhs_decl, rhs_decl, returnType); // populate the last three variable from the function
//DEBUG
/*if (lineNumber == 26) {
cerr << "op: " << op << "\nlhs_decl: " << PrintType(lhs_decl) << " lhs_type: "
<< PrintType(lhs_type) << "\nrhs_decl: " << PrintType(rhs_decl)
<< " rhs_type: " << PrintType(rhs_type) << "\nlhs_isArray: "
<< boolalpha << lhs_isArray << "\nrhs_isArray: " << rhs_isArray
<< noboolalpha << endl;
}*/
//DEBUG
// unary ops
if (isUnary && lhs_type != Error) {
//check for arrays
if (lhs_isArray) {
++numErrors;
foundError = true;
// Unary operator array check error
PrintError(out, 16, lineNumber, op, "", "", 0, 0);
}
else if (lhs_type != lhs_decl) { // do type check on unary op
++numErrors;
foundError = true;
// Unary operator type check error
PrintError(out, 17, lineNumber, op, PrintType(lhs_decl), PrintType(lhs_type), 0, 0);
}
}
// binary ops
else if (!isUnary) {
// check for arrays
if (lhs_type != Error && rhs_type != Error && (lhs_isArray || rhs_isArray)) {
++numErrors;
foundError = true;
// binary operator array check error
PrintError(out, 16, lineNumber, op, "", "", 0, 0);
}
// check for binary ops that can process different types as long as they are the same
else if (lhs_type != Error && rhs_type != Error && lhs_decl == Undefined && rhs_decl == Undefined && lhs_type != rhs_type) {
++numErrors;
foundError = true;
// same type required check error
PrintError(out, 1, lineNumber, op, PrintType(lhs_type), PrintType(rhs_type), 0, 0);
}
// do type check for strict binary operators
/*else {
if (lhs_type != Error && lhs_decl != Undefined && lhs_decl != lhs_type) {
++numErrors;
foundError = true;
// binary lhs type check error
PrintError(out, 2, lineNumber, op, PrintType(lhs_decl), PrintType(lhs_type), 0, 0);
}
if (rhs_type != Error && rhs_decl != Undefined && rhs_decl != rhs_type) {
++numErrors;
foundError = true;
// binary rhs type check error
PrintError(out, 3, lineNumber, op, PrintType(rhs_decl), PrintType(rhs_type), 0, 0);
}
}*/
else if (lhs_type != Error && rhs_type != Error) {
if (lhs_decl != Undefined && lhs_decl != lhs_type) {
++numErrors;
foundError = true;
// binary lhs type check error
PrintError(out, 2, lineNumber, op, PrintType(lhs_decl), PrintType(lhs_type), 0, 0);
}
if (rhs_decl != Undefined && rhs_decl != rhs_type) {
++numErrors;
foundError = true;
// binary rhs type check error
//.........这里部分代码省略.........
示例7: switch
bool Parser::parse_statement(StatementList *list)
{
lexer.identify_keywords();
switch(lexeme())
{
case Lexeme::KW_IF:
parse_if(list);
break;
case Lexeme::KW_WHILE:
parse_while(list);
break;
case Lexeme::KW_DO:
parse_do(list);
parse_terminator();
break;
case Lexeme::KW_RETURN:
parse_return(list);
parse_terminator();
break;
case Lexeme::KW_BREAK:
parse_break(list);
parse_terminator();
break;
case Lexeme::KW_CONTINUE:
parse_continue(list);
parse_terminator();
break;
case Lexeme::KW_CONST:
step();
parse_local(true, parse_expression(), list);
parse_terminator();
break;
case Lexeme::BRACET_OPEN:
list->append(parse_block<true, false>(Scope::EMPTY));
break;
case Lexeme::SEMICOLON:
step();
break;
case Lexeme::END:
case Lexeme::BRACET_CLOSE:
return false;
default:
if(is_expression(lexeme()))
{
ExpressionNode *node = parse_expression();
if(lexeme() == Lexeme::IDENT && node->is_type_name(document, false))
parse_local(false, node, list);
else
list->append(node);
parse_terminator();
}
else
return false;
}
return true;
}
示例8: AssignVar
bool AssignVar(CompileInstance &inst, const mtlChars &name, const mtlChars &expr)
{
mtlChars base_name = GetBaseName(name);
Definition *type = GetType(inst, base_name);
if (type == NULL) {
AddError(inst, "Undeclared variable", name);
return false;
}
if (type->mut != Mutable) {
AddError(inst, "Modifying a constant", name);
return false;
}
ExpressionNode *tree = GenerateTree(expr);
if (tree == NULL) {
AddError(inst, "Malformed expression", expr);
return false;
}
mtlChars base_mem = GetBaseMembers(name);
bool result = true;
Parser parser;
mtlList<mtlChars> ops;
mtlList<mtlChars> m;
mtlString order_str;
const int num_lanes = (base_mem.GetSize() > 0) ? base_mem.GetSize() : type->type.size;
for (int lane = 0; lane < num_lanes; ++lane) {
order_str.Free();
const int stack_size = tree->Evaluate(name, order_str, lane, 0);
PushStack(inst, stack_size);
order_str.SplitByChar(ops, ';');
mtlItem<mtlChars> *op = ops.GetFirst();
while (op != NULL && op->GetItem().GetSize() > 0) {
parser.SetBuffer(op->GetItem());
switch (parser.MatchPart("%s+=%s%|%s-=%s%|%s*=%s%|%s/=%s%|%s=%s", m, NULL)) {
case 0:
EmitInstruction(inst, swsl::FLT_ADD_MM);
break;
case 1:
EmitInstruction(inst, swsl::FLT_SUB_MM);
break;
case 2:
EmitInstruction(inst, swsl::FLT_MUL_MM);
break;
case 3:
EmitInstruction(inst, swsl::FLT_DIV_MM);
break;
case 4:
EmitInstruction(inst, swsl::FLT_SET_MM);
break;
default:
AddError(inst, "Invalid syntax", op->GetItem());
return false;
break;
}
mtlItem<swsl::Instruction> *instr_item = inst.program.GetLast();
const mtlChars dst = m.GetFirst()->GetItem();
const mtlChars src = m.GetFirst()->GetNext()->GetItem();
EmitOperand(inst, dst);
if (src.IsFloat()) {
*((int*)(&instr_item->GetItem().instr)) += 1;
}
EmitOperand(inst, src);
op = op->GetNext();
}
PopStack(inst, stack_size);
}
delete tree;
return result;
}
示例9: INIT_API_EE
// Evaluates and prints a tree version of the active watch list
// The tree will be expanded along the nodes in expansionPath
// Optionally the list is filtered to only show differences from pFilterName (the name of a persisted watch list)
HRESULT WatchCmd::Print(int expansionIndex, __in_z WCHAR* expansionPath, __in_z WCHAR* pFilterName)
{
HRESULT Status = S_OK;
INIT_API_EE();
INIT_API_DAC();
EnableDMLHolder dmlHolder(TRUE);
IfFailRet(InitCorDebugInterface());
PersistList* pFilterList = NULL;
if(pFilterName != NULL)
{
pFilterList = pPersistListHead;
while(pFilterList != NULL)
{
if(_wcscmp(pFilterList->pName, pFilterName)==0)
break;
pFilterList = pFilterList->pNext;
}
}
PersistWatchExpression* pHeadFilterExpr = (pFilterList != NULL) ? pFilterList->pHeadExpr : NULL;
WatchExpression* pExpression = pExpressionListHead;
int index = 1;
while(pExpression != NULL)
{
ExpressionNode* pResult = NULL;
if(FAILED(Status = ExpressionNode::CreateExpressionNode(pExpression->pExpression, &pResult)))
{
ExtOut(" %d) Error: HRESULT 0x%x while evaluating expression \'%S\'", index, Status, pExpression->pExpression);
}
else
{
//check for matching absolute expression
PersistWatchExpression* pCurFilterExpr = pHeadFilterExpr;
while(pCurFilterExpr != NULL)
{
if(_wcscmp(pCurFilterExpr->pExpression, pResult->GetAbsoluteExpression())==0)
break;
pCurFilterExpr = pCurFilterExpr->pNext;
}
// check for matching persist evaluation on the matching expression
BOOL print = TRUE;
if(pCurFilterExpr != NULL)
{
WCHAR pCurPersistResult[MAX_EXPRESSION];
FormatPersistResult(pCurPersistResult, MAX_EXPRESSION, pResult);
if(_wcscmp(pCurPersistResult, pCurFilterExpr->pPersistResult)==0)
{
print = FALSE;
}
}
//expand and print
if(print)
{
if(index == expansionIndex)
pResult->Expand(expansionPath);
PrintCallbackData data;
data.index = index;
WCHAR pCommand[MAX_EXPRESSION];
swprintf_s(pCommand, MAX_EXPRESSION, L"!watch -expand %d", index);
data.pCommand = pCommand;
pResult->DFSVisit(EvalPrintCallback, (VOID*)&data);
}
delete pResult;
}
pExpression = pExpression->pNext;
index++;
}
return Status;
}
示例10: isCompatible
bool Multiplication::isCompatible(const ExpressionNode& left, const ExpressionNode& right)
{
if (left.getType() == NUMBER && right.getType() == NUMBER)
{
return true;
}
else if (left.getType() == VARIABLE && right.getType() == VARIABLE)
{
if (left.getVariable() == right.getVariable())
{
return true;
}
}
else if (left.getType() == OPERATION)
{
if (left.getOperation() == &ADDITION || left.getOperation() == &SUM)
{
return true;
}
else if (left.getOperation() == &MULTIPLICATION || left.getOperation() == &PRODUCT)
{
return true;
}
}
else if (right.getType() == OPERATION)
{
if (right.getOperation() == &ADDITION || right.getOperation() == &SUM)
{
return true;
}
else if (right.getOperation() == &MULTIPLICATION || right.getOperation() == &PRODUCT)
{
return true;
}
}
return false;
}
示例11: newNode
ExpressionNode ChainOperation::simplify(const ExpressionNode& root) const
{
ExpressionNode* left = root.getFirstChild();
ExpressionNode* lPtr;
ExpressionNode* rPtr;
vector<ExpressionNode *> used;
ExpressionNode newNode(this);
bool ending = false;
cout << "ChainOp simplify " << *left << " " <<*left->getRight() << endl;
if (left == 0)
{
return ExpressionNode(root.getOperation()->getIdentity());
}
else if (left->getRight() == 0)
{
return *left;
}
else
{
for (lPtr=left; lPtr->getRight()!=0; lPtr=lPtr->getRight())
{
if (find(used.begin(), used.end(), lPtr) == used.end() ) //if lPtr not in used
{
if (lPtr->getOperation() == this || lPtr->getOperation() == pairwiseOp) // if lPtr is itself the same Chain Operation
{
for (ExpressionNode* i = lPtr->getFirstChild(); i!=0; i=i->getRight())
{
newNode.appendChild(*i);
}
used.push_back(lPtr);
}
else
{
for (rPtr = lPtr->getRight(); rPtr!=0; rPtr=rPtr->getRight())
{
if (find(used.begin(),used.end(),rPtr)==used.end() && pairwiseOp->isCompatible(*lPtr, *rPtr))
{
newNode.appendChild(pairwiseOp->simplify(*lPtr,*rPtr));
used.push_back(lPtr);
used.push_back(rPtr);
break;
}
}
}
}
}
if (find(used.begin(), used.end(), lPtr) == used.end() ) // check last child for expansion
{
if (lPtr->getOperation() == this || lPtr->getOperation() == pairwiseOp)
{
for (ExpressionNode* i = lPtr->getFirstChild(); i!=0; i=i->getRight())
{
newNode.appendChild(*i);
}
used.push_back(lPtr);
}
}
}
if (newNode.getFirstChild() == 0)
{
ending = true;
}
for (lPtr=left; lPtr!=0; lPtr=lPtr->getRight())
{
if (find(used.begin(),used.end(),lPtr) == used.end())
{
newNode.appendChild(*lPtr);
}
}
if (ending)
{
clog << "ending ChainSimplify, root/newNode: " << root << newNode << endl;
return newNode;
}
else
{
return simplify(newNode);
}
}
示例12: if
ExpressionNode Addition::simplify(ExpressionNode& left, ExpressionNode& right) const
{
clog << "checkpoint addsimplify" << endl;
//simplest case: at least one side is just 0
if (left.getType() == NUMBER && left.getValue().getInt() == 0)
{
return right;
}
else if (right.getType() == NUMBER && right.getValue().getInt() == 0)
{
return left;
}
// for each left term: for each right term: try adding
stack <ExpressionNode*> leftNodeStack;
ExpressionNode * currentLeftNode = &left;
bool leftFinished = false;
stack <ExpressionNode*> rightNodeStack;
vector <ExpressionNode*> rightDeleteList;
ExpressionNode * currentRightNode = &right;
bool rightFinished = false;
ExpressionNode newNode(&ADDITION);
while (leftFinished == false)
{
clog << "looping left" << endl;
if (currentLeftNode->getType() == OPERATION && currentLeftNode->getOperation() == &ADDITION)
{
if (currentLeftNode->getFirstChild() == 0)
{
throw ExpressionNode::WrongArityError();
}
currentLeftNode = currentLeftNode->getFirstChild();
leftNodeStack.push(currentLeftNode);
continue;
}
// leaf term on left tree: traverse right tree
rightFinished = false;
currentRightNode = &right;
while (rightFinished == false)
{
clog << "looping right" << endl;
if (currentRightNode->getType() == OPERATION && currentRightNode->getOperation() == &ADDITION)
{
if (currentRightNode->getFirstChild() == 0)
{
throw ExpressionNode::WrongArityError();
}
currentRightNode = currentRightNode->getFirstChild();
rightNodeStack.push(currentRightNode);
continue;
}
assert(currentLeftNode != 0);
assert(currentRightNode !=0);
clog << "checkpoint addsimplify: before isAddable(" << *currentLeftNode << ", " << *currentRightNode << ")"<< endl;
// leaf terms on both sides: attempt adding
if (isCompatible(*currentLeftNode, *currentRightNode))
{
clog << "checkpoint addsimplify: after isAddable; " << endl;
clog << *currentLeftNode << " " << *currentRightNode << endl;
(*currentLeftNode) = addTerms(*currentLeftNode, *currentRightNode);
clog << "checkpoint addsimplify: after addTerms; " << endl;
clog << "currentLeftNode: " << *currentLeftNode << " RightNode:" << *currentRightNode << endl;
clog << "left " << left << "right " << right << endl;
if (currentRightNode == &right)
{
//entire right tree has been assimilated
return left;
}
// try marking for deletion after right loop instead of removing
rightDeleteList.push_back(currentRightNode);
}
while (true)
{
clog << "rightNodeStack: " << rightNodeStack.size() << endl;
if (rightNodeStack.size() != 0) clog << "rightNodeStack.top(): " << *(rightNodeStack.top()) << endl;
if (rightNodeStack.size() == 0)
{
rightFinished = true;
break;
}
currentRightNode = rightNodeStack.top();
rightNodeStack.pop();
if (currentRightNode->getRight() != 0)
{
currentRightNode = currentRightNode->getRight();
rightNodeStack.push(currentRightNode);
break;
}
}
}
// deleting marked rights
for (vector<ExpressionNode*>::iterator it = rightDeleteList.begin(); it != rightDeleteList.end(); it++)
{
//.........这里部分代码省略.........
示例13: while
std::ostream& operator<<(std::ostream& out, const ExpressionNode& node)
{
ExpressionNode * ptr = 0;
if (node.getType() == OPERATION)
{
if (node.getOperation() == 0)
{
if (node.getFirstChild() != 0)
{
throw ExpressionNode::GenericError("ERROR: inserting OPERATION parent node w/o operation into ostream");
}
else
{
out << "()";
return out;
}
}
if (node.getOperation()->isFuncFormat() == true)
{
out << *(node.getOperation()) << "(";
ptr = node.getFirstChild();
if (ptr != 0)
{
out << *ptr;
ptr = ptr->getRight();
while (ptr != 0)
{
out << ", " << *ptr;
ptr = ptr->getRight();
}
}
out << ")";
}
else
{
out << "(";
ptr = node.getFirstChild();
if (ptr != 0)
{
out << *ptr;
ptr = ptr->getRight();
while (ptr != 0)
{
out << *(node.getOperation()) << *ptr;
ptr = ptr->getRight();
}
}
out << ")";
}
}
else if (node.getType() == VARIABLE)
{
if (node.getVariable() == 0)
{
throw ExpressionNode::GenericError("ERROR: inserting VARIABLE node w/o variable into ostream");
}
out << *(node.getVariable());
}
else
{
if (node.getType() != NUMBER)
{
int i = node.getType();
std::clog << std::endl << i << std::endl;
}
assert(node.getType() == NUMBER);
out << node.getValue();
}
return out;
}
示例14: while
void Expression::ConvertInfixToPostfix()
{
if (!m_PostfixExpression.empty() || m_InfixExpression.empty())
return;
m_Result = true;
m_Status = true;
std::stack<ExpressionNode> stackOperator;
ExpressionNode::ExpressionNodeType lastType = ExpressionNode::Unknown;
for (PostfixVector::size_type i = 0; i < m_InfixExpression.size(); ++i)
{
ExpressionNode expNode;
expNode.Initialize(m_InfixExpression[i]);
const ExpressionNode::ExpressionNodeType type = expNode.GetType();
if (type == ExpressionNode::Numeric)
{
// Operand, add to postfix expression
m_PostfixExpression.push_back(expNode);
while (!stackOperator.empty() && stackOperator.top().IsUnaryOperator())
{
m_PostfixExpression.push_back(stackOperator.top());
stackOperator.pop();
}
}
else if (type == ExpressionNode::LParenthesis)
{
// Left Parentheses, add to stack
stackOperator.push(expNode);
}
else if (type == ExpressionNode::RParenthesis)
{
// Right Parentheses, reverse search the Left Parentheses, add all operator of the middle
ExpressionNode node;
while (!stackOperator.empty())
{
node = stackOperator.top();
stackOperator.pop();
if (node.GetType() == ExpressionNode::LParenthesis)
{
while (!stackOperator.empty() && stackOperator.top().IsUnaryOperator())
{
m_PostfixExpression.push_back(stackOperator.top());
stackOperator.pop();
}
break;
}
else
m_PostfixExpression.push_back(node);
}
// The lastest node must be Left Parentheses
if (node.GetType() != ExpressionNode::LParenthesis)
{
m_Status = false;
}
}
else
{
if (ExpressionNode::IsUnaryNode(type) && (m_PostfixExpression.empty() ||
(lastType != ExpressionNode::Unknown &&
lastType != ExpressionNode::RParenthesis &&
lastType != ExpressionNode::Numeric)))
{
expNode.SetUnaryOperator();
stackOperator.push(expNode);
}
else if (stackOperator.empty())
{
stackOperator.push(expNode);
}
else
{
ExpressionNode beforeExpNode = stackOperator.top();
if (beforeExpNode.GetType() != ExpressionNode::LParenthesis &&
beforeExpNode.GetPriority() >= expNode.GetPriority())
{
m_PostfixExpression.push_back(beforeExpNode);
stackOperator.pop();
}
stackOperator.push(expNode);
}
}
lastType = type;
}
while (!stackOperator.empty())
{
ExpressionNode beforeExpNode = stackOperator.top();
if (beforeExpNode.GetType() == ExpressionNode::LParenthesis)
{
m_Status = false;
}
m_PostfixExpression.push_back(beforeExpNode);
stackOperator.pop();
}
#ifdef CC_PARSER_TEST
wxString infix, postfix;
//.........这里部分代码省略.........
示例15: registerWith
void registerWith(ExpressionNode<T_element>& e) const
{
e.registerRequiredBy(*this);
}