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_ ); }
/** * 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; }
ParseTree* ExpressionParser::reduce(TreeNode* op, ParseTree* lhs, ParseTree* rhs) { ParseTree* root = new ParseTree(op); root->left(lhs); root->right(rhs); return root; }
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; }
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; } } }
void testExample(const string& filename) { Parser p; p.parseFile(filename); ParseTree* t = p.tree(); CHECK(t->validate()); testIdempotent(t); }
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; }
void CodeGenerator::ProcessReturnTerm(int flags) { infunc(CodeGenerator::ProcessKeywordTerm); ParseTree *tree; if (!(flags & FLAGS_IN_FUNCTION)) throw CompileError("(Line %d) Cannot specify return keyword outside of a function", CUR_TOKEN.line); INC_TOKEN; // Does this function return any values? if (cur_class->cur_function->GetReturnType().id == VARIABLE_TYPEID_VOID) { // Can only end here if (CUR_TOKEN.type != TOKEN_END_OF_LINE) throw CompileError("(Line %d) Cannot specify return value for void function", CUR_TOKEN.line); return; } // Allocate the parse tree if ((tree = new ParseTree) == NULL) throw CError("Couldn't allocate parse tree"); // Build the parse tree tree->Build(tokeniser, TOKEN_END_OF_LINE, TOKEN_NULL); // Reduce it tree->Optimise(); if (g_Object) { tree->CompleteTypes(flags | FLAGS_IMPLICIT_ASSIGNMENT); tree->GenerateCode(flags | FLAGS_IMPLICIT_ASSIGNMENT); } // Don't need the tree delete tree; // Mark the return cur_class->cur_function->had_return = 1; if (g_Object) { // Pop the return value to a safe place if (cur_class->cur_function->GetReturnType().id != VARIABLE_TYPEID_VOID) g_Object->WriteOp(OPCODE_POP_RETURN); // Write the return code cur_class->cur_function->WriteReturn(g_Object); } outfunc; }
int main(int argc, char **argv ) { ParseTree ptree; string fname=""; if (argc > 1) { fname.append(argv[1]); } ptree.init(fname); ptree.build(); ptree.execute(); }
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()); } }
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); }
/** * 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); }
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; }
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(); }
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; } }
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; } } } }
Call::Call() : Token(true) { read_next_token(); function_name = next_token(); read_next_token(); // "(" token String args_terminator = ")"; while (args_terminator != peek_next_token()) { ParseTree* tree = new ParseTree(); tree->buildTree(); args_list.push_back(tree); } read_next_token(); // args terminator }
ParseTree* ObjectReader::createParseTree(messageqcpp::ByteStream& b) { CLASSID id = ZERO; ParseTree* ret; b >> (id_t&) id; if (id == NULL_CLASS) return NULL; if (id != PARSETREE) throw UnserializeException("Not a ParseTree"); ret = new ParseTree(); ret->left(createParseTree(b)); ret->right(createParseTree(b)); ret->data(createTreeNode(b)); return ret; }
void makePrior() { getG(); for(I2Dmap::iterator iter = tsgP.begin();iter != tsgP.end();++iter) { unsigned int rSym = iter->first; ParseTree* tree = getTree(rSym); prior.insert(make_pair(rSym,pow(.5,double(tree->size())))); //prior.insert(make_pair(rSym,.00000001)); delete tree; } for(I2Dmap::iterator iter = tagP.begin();iter != tagP.end();++iter) { unsigned int rSym = iter->first; ParseTree* tree = getTree(rSym); prior.insert(make_pair(rSym,pow(.5,double(tree->size())))); //prior.insert(make_pair(rSym,.00000001)); delete tree; } clearG(); }
void copyTree() { //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))"); ArithmeticColumn a(exp); ParseTree* pt = const_cast<ParseTree*>(a.expression()); ParseTree* newTree = new ParseTree(); // copy 1st time newTree->copyTree(*pt); // copy 2nd time, see if the existing tree is deleted. newTree->copyTree (*pt); // explicitly delete the 2nd copied tree delete newTree; }
int main( int argc, char* argv[] ) { try { // Create a new parse tree. ParseTree* parseTree = new ParseTree(); // Print the parse tree. parseTree->printLatex(std::cout); delete(parseTree); } catch (Exception* exception) { exception->print(); delete(exception); } catch(...) { std::cerr << "Unknown exception occurred.\n"; } }
void appendSimpleFilter ( ParseTree*& ptree, SimpleFilter* filter ) { if( ptree->data() == 0 ) { // degenerate case, this filter goes at this node ptree->data( filter ); } else if( ptree->right() == 0 && ptree->left() == 0 ) { // this will be the case when there is a single node in the tree // that contains a filter. Here we want to make the root node an // 'and' operator, push the existing down to the lhs and make a // new node for the new filter ParseTree* newLhs = new ParseTree( ptree->data() ); ParseTree* newRhs = new ParseTree( filter ); Operator* op = new Operator(); op->data("and"); ptree->data( op ); ptree->left( newLhs ); ptree->right( newRhs ); } else { // this will be the case once we have a tree with an 'and' at the // root node, a filter in the lhs, and an arbitrary height tree // with the same properties on the rhs. Because all operators // are guaranteed to be and for now we simply insert a new rhs // node and "push down" the existing tree Operator* op = new Operator(); op->data("and"); ParseTree* newRhs = new ParseTree( op ); newRhs->left( new ParseTree( filter ) ); newRhs->right( ptree->right() ); ptree->right( newRhs ); } }
void ConstituencyInstance::Initialize( const std::vector<std::string> &forms, const std::vector<std::string> &lemmas, const std::vector<std::string> &tags, const std::vector<std::vector<std::string> > &morph, const ParseTree &parse_tree) { SequenceInstance::Initialize(forms, tags); lemmas_ = lemmas; morph_ = morph; std::string info; parse_tree.SaveToString(&info); parse_tree_.LoadFromString(info); }
bool PtIntersector::operator()(const ParseTree & pt, Scalar * score) const { if (score) { *score = 0.0; } const ParseInfo * ref = reference_->rootNode()->parseInfo( reference_ ); const ParseInfo * cur = pt.rootNode()->parseInfo( &pt ); const int left = std::max<int>(ref->left(), cur->left()); const int right = std::min<int>(ref->right(), cur->right()); if (right < left) { return false; } const int top = std::max<int>(ref->top(), cur->top()); const int bottom = std::min<int>(ref->bottom(), cur->bottom()); if (bottom < top) { return false; } const int intersectionArea = (right - left + 1) * (bottom - top + 1); const int rectArea = cur->area(); if (dividedByUnion_) { const int referenceArea = ref->area(); const int unionArea = referenceArea + rectArea - intersectionArea; if (intersectionArea >= unionArea * threshold_) { if (score) { *score = static_cast<Scalar>(intersectionArea) / unionArea; } return true; } } else { if (intersectionArea >= rectArea * threshold_) { if (score) { *score = static_cast<Scalar>(intersectionArea) / rectArea; } return true; } } return false; }
void SubAdapterStep::addExpression(const JobStepVector& exps, JobInfo& jobInfo) { // maps key to the index in the RG map<uint32_t, uint32_t> keyToIndexMap; const vector<uint32_t>& keys = fRowGroupIn.getKeys(); for (size_t i = 0; i < keys.size(); i++) keyToIndexMap[keys[i]] = i; // combine the expression to one parse tree ParseTree* filter = NULL; for (JobStepVector::const_iterator it = exps.begin(); it != exps.end(); it++) { ExpressionStep* e = dynamic_cast<ExpressionStep*>(it->get()); idbassert(e); e->updateInputIndex(keyToIndexMap, jobInfo); if (filter != NULL) { ParseTree* left = filter; ParseTree* right = new ParseTree(); right->copyTree(*(e->expressionFilter())); filter = new ParseTree(new LogicOperator("and")); filter->left(left); filter->right(right); } else { filter = new ParseTree(); filter->copyTree(*(e->expressionFilter())); } } // add to the expression wrapper if (fExpression.get() == NULL) fExpression.reset(new funcexp::FuncExpWrapper()); fExpression->addFilter(boost::shared_ptr<execplan::ParseTree>(filter)); }
execplan::ParseTree* ScalarSub::transform_between() { //idbassert(fGwip.rcWorkStack.size() >= 3); if (fGwip.rcWorkStack.size() < 3) { fGwip.fatalParseError = true; fGwip.parseErrorText = IDBErrorInfo::instance()->errorMsg(ERR_NON_SUPPORT_SCALAR); return NULL; } ReturnedColumn* op3 = fGwip.rcWorkStack.top(); fGwip.rcWorkStack.pop(); ReturnedColumn* op2 = fGwip.rcWorkStack.top(); fGwip.rcWorkStack.pop(); ReturnedColumn* op1 = fGwip.rcWorkStack.top(); fGwip.rcWorkStack.pop(); fColumn.reset(op1); ParseTree* lhs = NULL; ParseTree* rhs = NULL; PredicateOperator* op_LE = new PredicateOperator("<="); PredicateOperator* op_GE = new PredicateOperator(">="); SubSelect* sub2 = dynamic_cast<SubSelect*>(op3); fSub = (Item_subselect*)(fFunc->arguments()[2]); if (sub2) { rhs = buildParseTree(op_LE); delete sub2; } else { SOP sop; sop.reset(op_LE); rhs = new ParseTree(new SimpleFilter(sop, fColumn.get(), op3)); } SubSelect* sub1 = dynamic_cast<SubSelect*>(op2); fSub = (Item_subselect*)(fFunc->arguments()[1]); if (sub1) { lhs = buildParseTree(op_GE); delete sub1; } else { SOP sop; sop.reset(op_GE); lhs = new ParseTree(new SimpleFilter(sop, fColumn.get(), op2)); } if (!rhs || !lhs) { fGwip.fatalParseError = true; fGwip.parseErrorText = "non-supported scalar subquery"; fGwip.parseErrorText = IDBErrorInfo::instance()->errorMsg(ERR_NON_SUPPORT_SCALAR); return NULL; } ParseTree* pt = new ParseTree (new LogicOperator("and")); pt->left(lhs); pt->right(rhs); return pt; }
void Q1() { string sql = "\ select\ c_custkey,\ c_name,\ sum(l_extendedprice * (1 - l_discount)) as revenue,\ c_acctbal,\ n_name,\ c_address,\ c_phone,\ c_comment\ from\ customer,\ orders,\ lineitem,\ nation\ where\ c_custkey = o_custkey\ and l_orderkey = o_orderkey\ and o_orderdate >= date ':1'\ and o_orderdate < date ':1' + interval '3' month\ and l_returnflag = 'R'\ and c_nationkey = n_nationkey\ group by\ c_custkey,\ c_name,\ c_acctbal,\ c_phone,\ n_name,\ c_address,\ c_comment\ order by\ revenue desc;"; CalpontSelectExecutionPlan csep; // Returned columns CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnList; SimpleColumn *c1 = new SimpleColumn("tpch.customer.l_returnflag"); returnedColumnList.push_back(c1); SimpleColumn *c2 = new SimpleColumn("tpch.customer.c_name"); returnedColumnList.push_back(c2); ArithmeticColumn *c3 = new ArithmeticColumn("sum(tpch.lineitem.l_extendedprice*(1-tpch.lineitem.l_discount))"); c3->alias("revenue"); returnedColumnList.push_back(c3); SimpleColumn *c4 = new SimpleColumn("tpch.customer.c_acctbal"); returnedColumnList.push_back(c4); SimpleColumn *c5 = new SimpleColumn("tpch.nation.n_name"); returnedColumnList.push_back(c5); SimpleColumn *c6 = new SimpleColumn("tpch.customer.c_address"); returnedColumnList.push_back(c6); SimpleColumn *c7 = new SimpleColumn("tpch.customer.c_phone"); returnedColumnList.push_back(c7); SimpleColumn *c8 = new SimpleColumn("tpch.costomer.c_comment"); returnedColumnList.push_back(c8); csep.returnedCols(returnedColumnList); // Filters CalpontSelectExecutionPlan::FilterTokenList filterTokenList; SimpleFilter *f1 = new SimpleFilter (new Operator("="), new SimpleColumn("tpch.customer.c_custkey"), new SimpleColumn("tpch.orders.o_custkey")); filterTokenList.push_back(f1); filterTokenList.push_back( new Operator ("and")); SimpleFilter *f2 = new SimpleFilter (new Operator("="), new SimpleColumn("tpch.lineitem.l_orderkey"), new SimpleColumn("tpch.orders.o_orderkey")); filterTokenList.push_back(f2); filterTokenList.push_back( new Operator ("and")); SimpleFilter *f3 = new SimpleFilter (new Operator(">="), new SimpleColumn("tpch.orders.o_orderdate"), new ArithmeticColumn("date(':1')")); filterTokenList.push_back(f3); filterTokenList.push_back( new Operator ("and")); SimpleFilter *f4 = new SimpleFilter (new Operator("<"), new SimpleColumn("tpch.orders.o_orderdate"), new ArithmeticColumn("date(':1') + interval ('3', month)")); filterTokenList.push_back(f4); filterTokenList.push_back( new Operator ("and")); SimpleFilter *f5 = new SimpleFilter (new Operator("="), new SimpleColumn("tpch.lineitem.l_returnflag"), new ConstantColumn("R")); filterTokenList.push_back(f5); filterTokenList.push_back( new Operator ("and")); SimpleFilter *f6 = new SimpleFilter (new Operator("="), new SimpleColumn("tpch.customer.c_nationkey"), new SimpleColumn("tpch.nation.n_nationkey")); filterTokenList.push_back(f6); csep.filterTokenList(filterTokenList); ParseTree *pt = const_cast<ParseTree*>(csep.filters()); pt->drawTree ("q10.dot"); // Group by CalpontSelectExecutionPlan::GroupByColumnList groupByList; groupByList.push_back(c1->clone()); groupByList.push_back(c2->clone()); groupByList.push_back(c4->clone()); groupByList.push_back(c7->clone()); groupByList.push_back(c5->clone()); groupByList.push_back(c6->clone()); groupByList.push_back(c8->clone()); csep.groupByCols (groupByList); // Order by CalpontSelectExecutionPlan::OrderByColumnList orderByList; ArithmeticColumn *o1 = new ArithmeticColumn(*c3); o1->asc(false); orderByList.push_back(o1); csep.orderByCols(orderByList); cout << csep; }
/** * Handle MySQL's plugin functions * This is mostly for handling the null related functions that MySQL adds to the execution plan */ void InSub::handleFunc(gp_walk_info* gwip, Item_func* func) { if (func->functype() == Item_func::TRIG_COND_FUNC || func->functype() == Item_func::COND_OR_FUNC) { // purpose: remove the isnull() function from the parsetree in ptWorkStack. // IDB handles the null semantics in the join operation // trigcond(or_cond) is the only form we recognize for now if (func->argument_count() > 2) { fGwip.fatalParseError = true; fGwip.parseErrorText = "Unsupported item in IN subquery"; return; } Item_cond* cond; if (func->functype() == Item_func::TRIG_COND_FUNC) { Item* item; if (func->arguments()[0]->type() == Item::REF_ITEM) item = (Item_ref*)(func->arguments()[0])->real_item(); else item = func->arguments()[0]; cond = (Item_cond*)(item); } else { cond = (Item_cond*)(func); } if (cond->functype() == Item_func::COND_OR_FUNC) { // (cache=item) case. do nothing. ignore trigcond()? if (cond->argument_list()->elements == 1) return; // (cache=item or isnull(item)) case. remove "or isnull()" if (cond->argument_list()->elements == 2) { // don't know how to deal with this. don't think it's a fatal error either. if (gwip->ptWorkStack.empty()) return; ParseTree* pt = gwip->ptWorkStack.top(); if (!pt->left() || !pt->right()) return; SimpleFilter* sf = dynamic_cast<SimpleFilter*>(pt->left()->data()); //assert (sf && sf->op()->op() == execplan::OP_ISNULL); if (!sf || sf->op()->op() != execplan::OP_ISNULL) return; delete sf; sf = dynamic_cast<SimpleFilter*>(pt->right()->data()); //idbassert(sf && sf->op()->op() == execplan::OP_EQ); if (!sf || sf->op()->op() != execplan::OP_EQ) return; // set NULLMATCH for both operand. It's really a setting for the join. // should only set NULLMATCH when the subtype is NOT_IN. for some IN subquery // with aggregation column, MySQL inefficiently convert to: // (cache=item or item is null) and item is not null, which is equivalent to // cache = item. Do not set NULLMATCH for this case. // Because we don't know IN or NOTIN yet, set candidate bit and switch to NULLMATCH // later in handleNot function. if (sf->lhs()->joinInfo() & JOIN_CORRELATED) sf->lhs()->joinInfo(sf->lhs()->joinInfo() | JOIN_NULLMATCH_CANDIDATE); if (sf->rhs()->joinInfo() & JOIN_CORRELATED) sf->rhs()->joinInfo(sf->rhs()->joinInfo() | JOIN_NULLMATCH_CANDIDATE); pt = pt->right(); gwip->ptWorkStack.pop(); gwip->ptWorkStack.push(pt); } } else if (cond->functype() == Item_func::EQ_FUNC) { // not in (select const ...) if (gwip->ptWorkStack.empty()) return; ParseTree* pt = gwip->ptWorkStack.top(); SimpleFilter* sf = dynamic_cast<SimpleFilter*>(pt->data()); if (!sf || sf->op()->op() != execplan::OP_EQ) return; if (sf->lhs()->joinInfo() & JOIN_CORRELATED) sf->lhs()->joinInfo(sf->lhs()->joinInfo() | JOIN_NULLMATCH_CANDIDATE); if (sf->rhs()->joinInfo() & JOIN_CORRELATED) sf->rhs()->joinInfo(sf->rhs()->joinInfo() | JOIN_NULLMATCH_CANDIDATE); } } }
void trimNsave(std::ofstream& ofs, double tsgCut, double tagCut, double adjCut) { ofs << int(nSym) << "\n"; for(size_t i=0;i<nSym;++i) { ofs << syms[i] << "\n"; } getG(); vector<pair<unsigned int,double> > srt; for(I2Dmap::iterator iter = tsgP.begin();iter != tsgP.end();++iter) { ParseTree* tree = getTree(iter->first); if(iter->second > tsgCut || tree->isPCFG()) { srt.push_back(*iter); } else { //printf("ELIM %s\n",toString(tree).c_str()); } delete tree; } sort(srt.begin(),srt.end(),Rulesort(this)); ofs << int(srt.size()) << "\n"; printf("%d -> %d TSG rules\n",int(nTSG),int(srt.size())); for(vector<pair<unsigned int,double> >::iterator iter= srt.begin();iter!=srt.end();++iter) { unsigned int rSym = iter->first; double prob = iter->second; ParseTree* tree = getTree(rSym); ofs << toString(tree) << "\n" << prob << "\n"; delete tree; } srt.clear(); set<unsigned int> allowB; for(unsigned int i =nSym*2+1;i<goodmanIndex;++i) { unsigned int bS = baseSym[i]; if(ptsyms.count(bS) == 0 && bS != nSym*2 && tagP.count(i) == 0) { string s = getAKey(i); if(aKeys.count(s) > 0 && adjoinP[aKeys[s]] > adjCut) { allowB.insert(baseSym[i]); } } } for(I2Dmap::iterator iter = tagP.begin();iter != tagP.end();++iter) { ParseTree* tree = getTree(iter->first); if(iter->second > tagCut && allowB.count(baseSym[iter->first]) > 0) srt.push_back(*iter); delete tree; } sort(srt.begin(),srt.end(),Rulesort(this)); ofs << int(srt.size()) << "\n"; printf("%d -> %d TAG rules\n",int(nTAG),int(srt.size())); for(vector<pair<unsigned int,double> >::iterator iter= srt.begin();iter!=srt.end();++iter) { unsigned int rSym = iter->first; double prob = iter->second; ParseTree* tree = getTree(rSym); ofs << toString(tree) << "\n" << prob << "\n"; delete tree; } vector<pair<string,double> > aaa; for(S2Imap::iterator i = aKeys.begin(); i != aKeys.end();++i) { double p = adjoinP[i->second]; if(p > adjCut) aaa.push_back(make_pair(i->first,p)); } printf("%d -> %d Adjunction groups\n",int(aKeys.size()),int(aaa.size())); ofs << int(aaa.size()) << "\n"; sort(aaa.begin(),aaa.end(),Psort()); for(size_t i=0;i<aaa.size();++i) { ofs << aaa[i].first << "\n" << aaa[i].second << "\n"; } }
//main method int main(int argc, char *argv[]) { //set the default arguments char target[10] = "osx"; char abi[10] = "macho64"; char output[PATH_MAX] = "output.asm"; char *input; //parse the arguments for(int i = 1; i < argc; i++) { //format if(strcmp(argv[i], "-f") == 0) { if(i+1 >= argc) { printf("Format not specified\n"); return 0; } strcpy(abi, argv[i+1]); i++; if(strcmp(abi, "macho") != 0 && strcmp(abi, "macho32") != 0 && strcmp(abi, "macho64") != 0) { printf("Unknown format: %s\n", abi); return 0; } } //target else if(strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--target") == 0) { if(i+1 >= argc) { printf("Target not specified\n"); return 0; } strcpy(target, argv[i+1]); i++; if(strcmp(target, "osx") != 0 && strcmp(target, "win") != 0 && strcmp(target, "ubu") != 0) { printf("Unknown target: %s\n", target); return 0; } } //output file else if(strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--output") == 0) { if(i+1 >= argc) { printf("Output file not specified\n"); return 0; } strcpy(output, argv[i+1]); i++; } //input file else if(input == NULL) { input = (char*)malloc(sizeof(argv[i])); strcpy(input, argv[i]); } //invalid else { printf("Unknown argument: %s\n", argv[i]); return 0; } } //initialize the symbol table and parse tree SymbolTable *symbolTable = new SymbolTable(); ParseTree *parseTree = new ParseTree(); //get the lexical analyzer input file FILE *lex_file = fopen("lex_table.csv", "r"); if(lex_file == NULL) { printf("Could not find lex syntax file!\n"); printf("The file should be placed in the same directory and named 'lex_table.csv'\n"); return 0; } //get the code input file if(argc < 2) { printf("Please add the input file to the arguments\n"); printf("(example ./compiler test)\n"); return 0; } FILE *infile = fopen(input, "r"); if(infile == NULL) { printf("Could not find the input file: %s\n", argv[1]); printf("Please ensure that it exists\n"); return 0; } //get the syntax analyzer input file FILE *syn_file = fopen("parse_table.csv", "r"); if(syn_file == NULL) { printf("Could not find the parse table file!\n"); printf("The file should be placed in the same directory and named 'parse_table.csv'\n"); return 0; } //create the lexical analyzer and syntax analyzer LexicalAnalyzer *lexicalAnalyzer = new LexicalAnalyzer(lex_file, infile); SyntaxAnalyzer *syntaxAnalyzer = new SyntaxAnalyzer(syn_file, lexicalAnalyzer, symbolTable, parseTree); //close the opened files fclose(lex_file); fclose(syn_file); //complete the parsing int ret = syntaxAnalyzer->parse(); if(ret == 0) { if(strcmp(target, "osx") == 0) { if(strcmp(abi, "macho32") == 0) { CodeGenerator_macho32_osx *c = new CodeGenerator_macho32_osx(symbolTable, output); parseTree->get_root()->accept(c); c->write_exit(); c->write_code(); } else if(strcmp(abi, "macho64") == 0) { CodeGenerator_macho64_osx *c = new CodeGenerator_macho64_osx(symbolTable, output); parseTree->get_root()->accept(c); c->write_exit(); c->write_code(); } else { printf("Currently, the compatible Ubuntu formats are:\n\tmacho32\n\tmacho64\n"); } } else if(strcmp(target, "win") == 0) { printf("Windows is not currently supported\n"); } else if(strcmp(target, "ubu") == 0) { if(strcmp(abi, "macho32") == 0) { CodeGenerator_macho32_ubu *c = new CodeGenerator_macho32_ubu(symbolTable, output); parseTree->get_root()->accept(c); c->write_exit(); c->write_code(); } else { printf("Currently, the compatible Ubuntu formats are:\n\tmacho32\n"); } } } fclose(infile); return 0; }