Esempio n. 1
0
void DB_Set::insert_cmd_interpret(token& t, vector<Table*> r)
{
	string name = t[0].get_value();
	Table* ptr = lookup(name);
	if(ptr != nullptr)
	{
		if(t[1].get_type() == expr)
		{
			Table* e = expr_interpret(t[1], r);
			if(e != nullptr) DB_Engine::insert_relation(ptr, *e);
		}
		else if(t[1].get_type() == insert_list)
		{
			token* itr = &(t[1]);
			Tuple tup = ptr->get_Template_Tuple();
			vector<Attribute> attrs = tup.get_Attributes();
			int i = 0;
			while((*itr).get_type() == insert_list)
			{
				if(attrs[i].get_Length() == -1) attrs[i].set_Int_Value(stoi((*itr)[0][0].get_value()));
				else if(attrs[i].get_Length() != -1) attrs[i].set_String_Value((*itr)[0][0].get_value());
				itr = &((*itr)[1]);
				++i;
			}
			Tuple new_tup(attrs);
			DB_Engine::insert_tuple(ptr, attrs);
		}
	}
	else cout<<"No table found\n";
}
Esempio n. 2
0
void DB_Set::query_interpret(token& t, vector<Table*> r)
{
	Table* e = expr_interpret(t[1], r);
	if(e != nullptr) 
	{
		e->set_Name(t[0].get_value());
		tables.push_back(e);
	}
}
Esempio n. 3
0
int main(int argc, char* argv[]) {
  if(argc !=2 ) {
    fprintf(stderr,"usage: expr-parser FILE\n");
    exit(1);
  }
  
  Expr* expr = expr_parse(argv[1]);
  printf("expr = ");
  expr_print(expr);
  printf("\n%d\n", expr_interpret(expr));
}
Esempio n. 4
0
Table* DB_Set::atomic_expr_interpret(token& t, vector<Table*> r)
{
	if(t[0].get_type() == identifier) return (lookup(t[0].get_value()));
	else if(t[0].get_type() == expr) return (expr_interpret(t[0], r));
	else return nullptr;
}