本文整理汇总了C++中ParseTree类的典型用法代码示例。如果您正苦于以下问题:C++ ParseTree类的具体用法?C++ ParseTree怎么用?C++ ParseTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParseTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
/**
* Build an expression tree with the tokens
*/
ParseTree* ExpressionParser::reduce(TreeNode* op, ParseTree* value)
{
char c = op->data().at(0);
switch (c) {
case 'M':
case 'm':
{
ParseTree *root = new ParseTree(op);
ParseTree *lhs = new ParseTree(new ConstantColumn("0", ConstantColumn::NUM));
root->left(lhs);
root->right(value);
return root;
}
case 'I':
case 'i':
delete op;
return value;
default:
idbassert(0);
}
ostringstream oss;
oss << "ExpressionParser::reduce(TreeNode*,ParseTree*): invalid input token: >" << op->data() << '<';
throw std::runtime_error(oss.str());
return 0;
}
示例2: ParseTree
ParseTree* ExpressionParser::reduce(TreeNode* op, ParseTree* lhs, ParseTree* rhs)
{
ParseTree* root = new ParseTree(op);
root->left(lhs);
root->right(rhs);
return root;
}
示例3: infunc
void CodeGenerator::ProcessParseTree(int flags)
{
infunc(CodeGenerator::ProcessParseTree);
ParseTree *tree;
// Allocate some space for the parse tree
if ((tree = new ParseTree) == NULL)
throw CError("Couldn't allocate parse tree");
// Build the parse tree (steps passed all the tokens)
tree->Build(tokeniser, TOKEN_END_OF_LINE, TOKEN_NULL);
// Reduce the tree if possible
tree->Optimise();
if (g_Object)
{
tree->CompleteTypes(flags);
tree->GenerateCode(flags);
// Yacka
// tree->Debug();
}
// The tree is no longer needed
delete tree;
outfunc;
}
示例4: print
void print (PTNode node) {
ParseTree * ptree = dynamic_cast <ParseTree *> (node);
if (ptree) {
for (PTNode n : ptree->getBody ()) {
std::cout << n->toString (text::COLOUR) << std::endl;
}
}
}
示例5: testExample
void testExample(const string& filename)
{
Parser p;
p.parseFile(filename);
ParseTree* t = p.tree();
CHECK(t->validate());
testIdempotent(t);
}
示例6: setDerivedFilter
ParseTree* setDerivedFilter(ParseTree*& n, map<string, ParseTree*>& filterMap,
erydbSelectExecutionPlan::SelectList& derivedTbList)
{
if (!(n->derivedTable().empty()))
{
// @todo replace virtual column of n to real column
// all simple columns should belong to the same derived table
erydbSelectExecutionPlan *csep = NULL;
for (uint i = 0; i < derivedTbList.size(); i++)
{
erydbSelectExecutionPlan *plan = dynamic_cast<erydbSelectExecutionPlan*>(derivedTbList[i].get());
if (plan->derivedTbAlias() == n->derivedTable())
{
csep = plan;
break;
}
}
// should never be null; if null then give up optimization.
if (!csep)
return n;
// 2. push the filter to the derived table filter stack, or 'and' with
// the filters in the stack
map<string, ParseTree*>::iterator mapIter = filterMap.find(n->derivedTable());
if ( mapIter == filterMap.end())
{
filterMap.insert(pair<string, ParseTree*>(n->derivedTable(), n));
}
else
{
ParseTree* pt = new ParseTree(new LogicOperator("and"));
pt->left(mapIter->second);
pt->right(n);
mapIter->second = pt;
}
int64_t val = 1;
n = new ParseTree(new ConstantColumn(val));
}
else
{
Operator *op = dynamic_cast<Operator*>(n->data());
if (op && (op->op() == OP_OR || op->op() == OP_XOR))
{
return n;
}
else
{
ParseTree *lhs = n->left();
ParseTree *rhs = n->right();
if (lhs)
n->left(setDerivedFilter(lhs, filterMap, derivedTbList));
if (rhs)
n->right(setDerivedFilter(rhs, filterMap, derivedTbList));
}
}
return n;
}
示例7: main
int main(int argc, char **argv ) {
ParseTree ptree;
string fname="";
if (argc > 1) {
fname.append(argv[1]);
}
ptree.init(fname);
ptree.build();
ptree.execute();
}
示例8: setDerivedTable
void setDerivedTable(execplan::ParseTree* n)
{
ParseTree *lhs = n->left();
ParseTree *rhs = n->right();
Operator *op = dynamic_cast<Operator*>(n->data());
// if logic operator then lhs and rhs can't be both null
if (op)
{
if (!lhs || lhs->derivedTable() == "*")
{
n->derivedTable(rhs ? rhs->derivedTable() : "*");
}
else if (!rhs || rhs->derivedTable() == "*")
{
n->derivedTable(lhs->derivedTable());
}
else if (lhs->derivedTable() == rhs->derivedTable())
{
n->derivedTable(lhs->derivedTable());
}
else
{
n->derivedTable("");
}
}
else
{
n->data()->setDerivedTable();
n->derivedTable(n->data()->derivedTable());
}
}
示例9: main
int main(int argc, char **argv ) {
ParseTree ptree;
string fname="";
if (argc > 1) {
fname.append(argv[1]);
}
ptree.init(fname);
ptree.build();
std::map<std::string,double> symbolTable;
cout << "\n\n" << endl;
ptree.execute(symbolTable);
}
示例10: idbassert
/**
* This is invoked when a NOT function is got. It's usually the case NOT<IN optimizer>
* This function will simple turn the semi join to anti join
*
*/
void InSub::handleNot()
{
ParseTree *pt = fGwip.ptWorkStack.top();
ExistsFilter *subFilter = dynamic_cast<ExistsFilter*>(pt->data());
idbassert(subFilter);
subFilter->notExists(true);
SCSEP csep = subFilter->sub();
const ParseTree* ptsub = csep->filters();
if (ptsub)
ptsub->walk(makeAntiJoin);
ptsub = csep->having();
if (ptsub)
ptsub->walk(makeAntiJoin);
}
示例11: arithmeticExpression_1
void arithmeticExpression_1()
{
cout << "\narithmetic expression: " << endl;
string exp("substr(a)+ 100.00 * sum(tpch.part.p_type) / sum(tpch.lineitem.l_extendedprice *(1-tpch.lineitem.l_discount))");
cout << exp << endl;
ArithmeticColumn a(exp, 0);
ParseTree* pt = const_cast<ParseTree*>(a.expression());
if (pt != NULL)
{
pt->walk(walkfnString);
pt->drawTree("arithmeticExpression_1.dot");
}
cout << " --- end of test 6 ---" << endl;
}
示例12:
bool
SemanticAnalysis::analyze()
{
ParseTree *tree = tu_->tree();
StatementList *statements = tree->statements();
for (size_t i = 0; i < statements->length(); i++) {
Statement *stmt = statements->at(i);
if (stmt->isFunctionStatement())
stmt->accept(this);
if (!cc_.canContinueProcessing())
return false;
}
return cc_.phasePassed();
}
示例13: isEqual
bool TrainExample::isEqual(const ParseTree & pt) const
{
assert(pts().size() >= 2);
const ParseInfo * p = pts()[0].rootNode()->parseInfo(&pts()[0]);
const ParseInfo * p1 = pt.rootNode()->parseInfo(&pt);
assert(p);
assert(p1);
return (pts()[0].dataId() == pt.dataId()) &&
(p->c_ == p1->c_) && (p->l_ == p1->l_) &&
(p->x_ == p1->x_) && (p->y_ == p1->y_ );
}
示例14: CollectWordLabelCounts
void ExtractGHKM::CollectWordLabelCounts(
ParseTree &root,
const Options &options,
std::map<std::string, int> &wordCount,
std::map<std::string, std::string> &wordLabel)
{
std::vector<const ParseTree*> leaves;
root.GetLeaves(std::back_inserter(leaves));
for (std::vector<const ParseTree *>::const_iterator p = leaves.begin();
p != leaves.end(); ++p) {
const ParseTree &leaf = **p;
const std::string &word = leaf.GetLabel();
const ParseTree *ancestor = leaf.GetParent();
// If unary rule elimination is enabled and this word is at the end of a
// chain of unary rewrites, e.g.
// PN-SB -> NE -> word
// then record the constituent label at the top of the chain instead of
// the part-of-speech label.
while (!options.allowUnary &&
ancestor->GetParent() &&
ancestor->GetParent()->GetChildren().size() == 1) {
ancestor = ancestor->GetParent();
}
const std::string &label = ancestor->GetLabel();
++wordCount[word];
wordLabel[word] = label;
}
}
示例15: buildTree
void TurboParser::buildTree()
{
bool *doneList;
int sizeOfTree = treeTable.size();
doneList = new bool[sizeOfTree];
ParseTree tree;
//cout << sizeof(doneList) << " " << sizeOfTree<<endl;
for (int i=0; i<sizeOfTree; i++) {
doneList[i] = false;
}
//cout << treeTable[1][0][0] << endl;
for (int i=0; i<sizeOfTree; i++) {
//cout << treeTable[i][1] << endl;
//cout << i <<endl;
if(treeTable[i][0][0] != 0 && treeTable[i][3] == "0") {
//cout<<"once coming here \n";
tree.buildNode(treeTable[i]);
doneList[i] = true;
}
}
bool finished = false;
while(finished == false) {
for (int i=0; i<sizeOfTree; i++) {
if(doneList[i] == false) {
if(tree.buildNode(treeTable[i]) == true) {
doneList[i] = true;
break;
}
}
}
finished = true;
for (int i=0; i<sizeOfTree; i++) {
if(doneList[i] == false) {
finished = false;
break;
}
}
}
}