本文整理汇总了C++中ASTNode::joinChild方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTNode::joinChild方法的具体用法?C++ ASTNode::joinChild怎么用?C++ ASTNode::joinChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTNode
的用法示例。
在下文中一共展示了ASTNode::joinChild方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildSubTree
ASTNode* TestASTMatcher::buildSubTree()
{
ASTNode* plusNode = new ASTNode("", PLUS, 0);
ASTNode* minusNode = new ASTNode("", MINUS, 0);
ASTNode* varNodeB = new ASTNode("b", VARIABLE, 0);
ASTNode* varNodeC = new ASTNode("c", VARIABLE, 0);
ASTNode* constantNode = new ASTNode("1", CONSTANT, 0);
minusNode->joinChild(plusNode);
plusNode->joinChild(varNodeB);
varNodeB->joinNext(varNodeC);
plusNode->joinNext(constantNode);
return minusNode;
}
示例2: buildSubTreeWithDiffValue
ASTNode* TestASTMatcher::buildSubTreeWithDiffValue()
{
ASTNode* timesNode = new ASTNode("", TIMES, 0);
ASTNode* divideNode = new ASTNode("", DIVIDE, 0);
ASTNode* varNodeB = new ASTNode("b", VARIABLE, 0);
ASTNode* varNodeC = new ASTNode("c", VARIABLE, 0);
ASTNode* constantNode = new ASTNode("1", CONSTANT, 0);
divideNode->joinChild(timesNode);
timesNode->joinChild(varNodeB);
varNodeB->joinNext(varNodeC);
timesNode->joinNext(constantNode);
return timesNode;
}
示例3: ifStmt
ASTNode* Parser::ifStmt()
{
matchKeyword("if");
ASTNode* ifNode = new ASTNode("", IF, _stmtNum);
_varTable->addVariable(_token);
ASTNode* varNode = new ASTNode(_token, VARIABLE, 0);
matchName();
matchKeyword("then");
matchKeyword("{");
ASTNode* ifStmtListNode = statementList();
matchKeyword("}");
matchKeyword("else");
matchKeyword("{");
ASTNode* elseStmtListNode = statementList();
matchKeyword("}");
ifNode->joinChild(varNode);
varNode->joinNext(ifStmtListNode);
ifStmtListNode->joinNext(elseStmtListNode);
return ifNode;
}
示例4: procedure
ASTNode* Parser::procedure()
{
matchKeyword("procedure");
if (_procTable->getIndex(_token) > -1) {
throw ParseException(_stmtNum, _token, "Duplicate procedure names");
}
std::string procedure = _token;
ASTNode* procNode = new ASTNode(procedure, PROCEDURE, 0);
matchName();
matchKeyword("{");
int fromStmtNum = _stmtNum + 1;
ASTNode* stmtListNode = statementList();
matchKeyword("}");
int toStmtNum = _stmtNum;
_procTable->addProcedure(procedure, fromStmtNum, toStmtNum);
procNode->joinChild(stmtListNode);
return procNode;
}
示例5: buildTree
ASTNode* TestASTMatcher::buildTree()
{
ASTNode* assignNode = new ASTNode("", ASSIGN, 1);
ASTNode* plusNode = new ASTNode("", PLUS, 0);
ASTNode* minusNode = new ASTNode("", MINUS, 0);
ASTNode* varNodeA = new ASTNode("a", VARIABLE, 0);
ASTNode* varNodeB = new ASTNode("b", VARIABLE, 0);
ASTNode* varNodeC = new ASTNode("c", VARIABLE, 0);
ASTNode* constantNode = new ASTNode("1", CONSTANT, 0);
assignNode->joinChild(varNodeA);
varNodeA->joinNext(minusNode);
minusNode->joinChild(plusNode);
plusNode->joinChild(varNodeB);
varNodeB->joinNext(varNodeC);
plusNode->joinNext(constantNode);
return assignNode;
}
示例6: assignStmt
ASTNode* Parser::assignStmt()
{
_varTable->addVariable(_token);
ASTNode* varNode = new ASTNode(_token, VARIABLE, 0);
matchName();
matchKeyword("=");
ASTNode* assignNode = new ASTNode("", ASSIGN, _stmtNum);
ASTNode* expNode = expression();
matchKeyword(";");
assignNode->joinChild(varNode);
varNode->joinNext(expNode);
return assignNode;
}
示例7: program
ASTNode* Parser::program()
{
ASTNode* progNode = new ASTNode("Simple", PROGRAM, 0);
ASTNode* procNode = procedure();
progNode->joinChild(procNode);
ASTNode* prevProcNode;
while (isKeyword("procedure")) {
prevProcNode = procNode;
procNode = procedure();
prevProcNode->joinNext(procNode);
}
return progNode;
}
示例8: statementList
ASTNode* Parser::statementList()
{
ASTNode* stmtListNode = new ASTNode("", STATEMENT_LIST, 0);
ASTNode* stmtNode = statement();
stmtListNode->joinChild(stmtNode);
ASTNode* prevStmtNode;
while (!isKeyword("}")) {
prevStmtNode = stmtNode;
stmtNode = statement();
prevStmtNode->joinNext(stmtNode);
}
return stmtListNode;
}
示例9: whileStmt
ASTNode* Parser::whileStmt()
{
matchKeyword("while");
ASTNode* whileNode = new ASTNode("", WHILE, _stmtNum);
_varTable->addVariable(_token);
ASTNode* varNode = new ASTNode(_token, VARIABLE, 0);
matchName();
matchKeyword("{");
ASTNode* stmtListNode = statementList();
matchKeyword("}");
whileNode->joinChild(varNode);
varNode->joinNext(stmtListNode);
return whileNode;
}
示例10: buildOperators
void ASTExpressionBuilder::buildOperators()
{
ASTNode* operatorNode;
ASTNode* leftNode;
ASTNode* rightNode;
ASTType type;
if (_operators.back() == "+") {
type = PLUS;
} else if (_operators.back() == "-") {
type = MINUS;
} else if (_operators.back() == "*") {
type = TIMES;
}else if (_operators.back() == "/") {
type = DIVIDE;
}
operatorNode = new ASTNode("", type, 0);
if (!_results.empty()) {
rightNode = _results.back();
_results.pop_back();
} else {
throw ParseException(_token, "Unable to parse expression");
}
if (!_results.empty()) {
leftNode = _results.back();
_results.pop_back();
} else {
throw ParseException(_token, "Unable to parse expression");
}
operatorNode->joinChild(leftNode);
leftNode->joinNext(rightNode);
_results.push_back(operatorNode);
_operators.pop_back();
}