예제 #1
0
void Parser::parseStatement(){
	if(isNext(tc_ID)){
		SymbolTableEntry* entry = m_currentToken->getSymTabEntry();
		match(tc_ID);
		parseStatementPrime(entry);
	}
	else if(isNext(tc_IF)){
		match(tc_IF);
		SymbolTableEntry* exp = parseExpression();
		SymbolTableEntry* f = newLabel();
		SymbolTableEntry* end = newLabel();
		m_code->generate(cd_EQ, exp, m_symbolTable->lookup(CodeFalse), f);
		match(tc_THEN);
		if(m_parserError){
			TokenCode synch[] = {tc_ID, tc_BEGIN, tc_IF, tc_WHILE, tc_NONE};
			recover(synch);
//			if(isNext(tc_THEN)){
//				match(tc_THEN);
//			}
		}
		parseStatement();
		m_code->generate(cd_GOTO, NULL, NULL, end);
		m_code->generate(cd_LABEL, NULL, NULL, f);
		match(tc_ELSE);
		if(m_parserError){
			TokenCode synch[] = {tc_ID, tc_BEGIN, tc_IF, tc_WHILE, tc_NONE};
			recover(synch);
//			if(isNext(tc_ELSE)){
//				match(tc_ELSE);
//			}
		}
		parseStatement();
		m_code->generate(cd_LABEL, NULL, NULL, end);
	}
	else if(isNext(tc_WHILE)){
		match(tc_WHILE);
		SymbolTableEntry* start = newLabel();
		m_code->generate(cd_LABEL, NULL, NULL, start);
		SymbolTableEntry* exp = parseExpression();
		SymbolTableEntry* end = newLabel();
		m_code->generate(cd_EQ, exp, m_symbolTable->lookup(CodeFalse), end);
		match(tc_DO);
		if(m_parserError){
			TokenCode synch[] = {tc_ID, tc_BEGIN, tc_IF, tc_WHILE, tc_NONE};
			recover(synch);
//			if(isNext(tc_DO)){
//				match(tc_DO);
//			}
		}
		parseStatement();
		m_code->generate(cd_GOTO, NULL, NULL, start);
		m_code->generate(cd_LABEL, NULL, NULL, end);
	}
	else{
		parseCompoundStatement();
	}
}
예제 #2
0
void Parser::parseSubprogramDeclarations(){
	if(isNext(tc_FUNCTION) || isNext(tc_PROCEDURE)){
		parseSubprogramDeclaration();
		match(tc_SEMICOL);
		if(m_parserError){
			TokenCode synch[] = {tc_FUNCTION, tc_PROCEDURE, tc_BEGIN, tc_NONE};
			recover(synch);
//			if(isNext(tc_SEMICOL)){
//				match(tc_SEMICOL);
//			}
		}
		parseSubprogramDeclarations();
	}
}
예제 #3
0
// 声明
void CodeGenerator::Decla() {
    while(isNext("type")) {
        string Type = getToken().value;
        string var = "";
        while(!isNext(";")) {
            var = getToken().value;
            addVar(var, Type);
            if(isNext(";")) break;
            match(",");
        }
        if(var != "") addVar(var, Type);
        match(";");
    }
}
예제 #4
0
파일: pexp.c 프로젝트: cccnqu1/cccwd
int T() {
	printf("<T>");
	if (isNext(DIGITS)) {
		while (isNext(DIGITS)) {
			cnext();
		}
	} else if (isNext("(")) {
		cnext();
		E();
		cnext();
	} else if (ch != '\0') {
		printf("error!");
	}
	printf("</T>");
}
예제 #5
0
	/*! \brief Create the VTK vertex definition
	 *
	 */
	std::string get_vertex_list()
	{
		//! vertex node output string
		std::string v_out;

		size_t k = 0;

		//! For each sub-domain
		for (size_t i = 0 ; i < vg.size() ; i++)
		{
			// For each position in the cell
			for (size_t j = 0 ; j < vg.get(i).g.size() ; j++)
			{
				// If there are no grid in this position
				if (vg.get(i).g.get(j).grids.size() == 0)
						continue;
				//! For each grid point create a vertex
				auto it = vg.get(i).g.get(j).grids.get(0)->getIterator();

				while (it.isNext())
				{
					v_out += "1 " + std::to_string(k) + "\n";

					++k;
					++it;
				}
			}
		}
		// return the vertex list
		return v_out;
	}
예제 #6
0
    void lastProp()
	{
		// Create point data properties
		v_out += "SCALARS domain float\n";

		// Default lookup table
		v_out += "LOOKUP_TABLE default\n";

		// Produce point data
		for (size_t k = 0 ; k < vv.size() ; k++)
		{
			//! Get a vertex iterator
			auto it = vv.get(k).g.getIterator();

			// if there is the next element
			while (it.isNext())
			{
				if (it.get() < vv.get(k).mark)
					v_out += "1.0\n";
				else
					v_out += "0.0\n";

				// increment the iterator and counter
				++it;
			}
		}
	}
예제 #7
0
	/*! \brief Create the VTK point definition
	 *
	 */
	std::string get_point_list()
	{
		//! vertex node output string
		std::stringstream v_out;

		//! For each defined grid

		for (size_t i = 0 ; i < vps.size() ; i++)
		{
			//! write the particle position
			auto it = vps.get(i).g.getIterator();

			// if there is the next element
			while (it.isNext())
			{
				Point<pair::first::value_type::dims,typename pair::first::value_type::coord_type> p;
				p = vps.get(i).g.get(it.get());

				if (pair::first::value_type::dims == 2)
					v_out << p.toString() << " 0.0" << "\n";
				else
					v_out << p.toString() << "\n";

				// increment the iterator and counter
				++it;
			}
		}

		// return the vertex list
		return v_out.str();
	}
	/*! \brief Apply the kernel expression to a particle
	 *
	 * \param vd vector with the particles positions
	 * \param cl Cell-list
	 * \param v_exp expression to execute for each particle
	 * \param key to which particle to apply the expression
	 * \param lker kernel function
	 *
	 * \return the result of apply the kernel on the particle key
	 *
	 */
	inline static typename std::remove_reference<rtype>::type apply(const vector & vd, NN_type & cl, const exp & v_exp, const vect_dist_key_dx & key, Kernel & lker)
	{
	    // accumulator
	    typename std::remove_reference<rtype>::type pse = set_zero<typename std::remove_reference<rtype>::type>::create();

	    // property of the particle x
	    rtype prp_p = v_exp.value(key);

	    // position of particle p
	    auto & p = vd.getPos(key);

	    // Get the neighborhood of the particle
	    auto NN = cl.template getNNIterator<NO_CHECK>(cl.getCell(p));
	    while(NN.isNext())
	    {
	    	auto nnp = NN.get();

	    	// Calculate contribution given by the kernel value at position p,
	    	// given by the Near particle, exclude itself
	    	if (nnp != key.getKey())
	    	{
	    	    // property of the particle x
	    		rtype prp_q = v_exp.value(nnp);

	    	    pse += lker.value(key.getKey(),nnp,prp_p,prp_q,vd);
	    	}

	    	// Next particle
	    	++NN;
	    }

	    return pse;
	}
예제 #9
0
파일: Chomp.cpp 프로젝트: Lasconik/BoardCPP
void Chomp::handle(const char& c){
  /**
   * Cette fonction vérifie les touches tapées au clavier
   * par les joueurs.
   * @param c représente le caractère taper au clavier
   */
  if(checkMove(c) ){
    return;
  }
  
  // si le joueur veut quitter le jeux
  if (c == 'x') {
    Game::getInstance()->mainMenu();
    return;
  }

  // si le joueur veux executer une action, ici joueur une piece
  if (c == 'p' || c == MARK) {
    /* vérifie si b est en position gagnante 
     * avec le coup jouer */
    if( isNext(mPointer, mSuccessors) ){
      mBoard.at(mPointer.fst(), mPointer.snd()) = mCurrentPlayer->getColor(); 
      fillcolor(mPointer.fst(), mPointer.snd());
      mCurrentPlayer = opponent();
    }
  }
}
예제 #10
0
SymbolTableEntry* Parser::parseTermPrime(SymbolTableEntry* prevEntry){
	if(isNext(tc_MULOP)){
		OpType t = m_currentToken->getOpType();
		match(tc_MULOP);
		SymbolTableEntry* factor = parseFactor();
		SymbolTableEntry* temp = newTemp();
		if(t == op_MULT){
			m_code->generate(cd_MULT, prevEntry, factor, temp);
		}
		else if(t == op_DIVIDE){
			m_code->generate(cd_DIVIDE, prevEntry, factor, temp);
		}
		else if(t == op_DIV){
			m_code->generate(cd_DIV, prevEntry, factor, temp);
		}
		else if(t == op_MOD){
			m_code->generate(cd_MOD, prevEntry, factor, temp);
		}
		else{
			m_code->generate(cd_AND, prevEntry, factor, temp);
		}
		prevEntry = parseTermPrime(temp);
	}
	return prevEntry;
}
예제 #11
0
void Parser::parseStatementListPrime(){
	if(isNext(tc_SEMICOL)){
		match(tc_SEMICOL);
		parseStatement();
		parseStatementListPrime();
	}
}
예제 #12
0
	/*! \brief Calculate the local center of mass on direction dir
	 *
	 * WARNING: with CM we mean the sum of the particle coordinate over one direction
	 *
	 * \tparam dir Direction witch to calculate the center of mass
	 *
	 * \param start from where the last leafs start
	 */
	template<unsigned int dir> void local_cm(size_t start)
	{
		typedef Point<dim,T> s;

		// reset the counters and accumulators
		cm.fill(0);
		cm_cnt.fill(0);

		// Calculate the local CM
		auto it = lp.getIterator();

		while (it.isNext())
		{
			// vector key
			auto key =  it.get();

			size_t lbl = lp_lbl.get(key) - start;

			// add the particle coordinate to the CM accumulator
			cm.get(lbl) += lp.template get<s::x>(key)[dir];

			// increase the counter
			cm_cnt.get(lbl)++;

			++it;
		}
	}
예제 #13
0
	inline meta_prop(const openfpm::vector< ele_g > & vg, std::string & v_out)
	{
    	// actual string size
    	size_t sz = v_out.size();

		// Produce the point properties header
    	v_out += get_point_property_header_impl<I::value,ele_g,has_attributes<typename ele_g::value_type::value_type>::value>("");

		// If the output has changed, we have to write the properties
		if (v_out.size() != sz)
		{
			// Produce point data

			for (size_t k = 0 ; k < vg.size() ; k++)
			{
				//! Get a vertex iterator
				auto it = vg.get(k).g.getIterator();

				// if there is the next element
				while (it.isNext())
				{
					prop_write_out<vtk_dims<T>::value,T>::template write<decltype(vg),decltype(it),I>(v_out,vg,k,it);

					// increment the iterator and counter
					++it;
				}
			}
		}
	}
예제 #14
0
void Parser::parseDeclarations(){
	if(isNext(tc_VAR)){
		match(tc_VAR);
		EntryList ids = *(new EntryList());
		parseIdentifierList(ids);
		match(tc_COLON);
		if(m_parserError){
			TokenCode synch[] = {tc_ARRAY, tc_INTEGER, tc_REAL, tc_NONE};
			recover(synch);
//			if(isNext(tc_COLON)){
//				match(tc_COLON);
//			}
		}
		parseType();
		m_code->generateVariables(ids);
		match(tc_SEMICOL);
		if(m_parserError){
			TokenCode synch[] = {tc_VAR, tc_FUNCTION, tc_BEGIN, tc_PROCEDURE, tc_NONE};
			recover(synch);
//			if(isNext(tc_SEMICOL)){
//				match(tc_SEMICOL);
//			}
		}
		parseDeclarations();
	}
}
예제 #15
0
void Parser::parseExpressionListPrime(EntryList& expList){
	if(isNext(tc_COMMA)){
		match(tc_COMMA);
		expList.push_back(parseExpression());
		parseExpressionListPrime(expList);
	}
}
예제 #16
0
SymbolTableEntry* Parser::parseExpressionPrime(SymbolTableEntry* prevEntry){
	SymbolTableEntry* result = prevEntry;
	if(isNext(tc_RELOP)){
		OpType t = m_currentToken->getOpType();
		match(tc_RELOP);
		SymbolTableEntry* exp = parseSimpleExpression();
		result = newTemp();
		SymbolTableEntry* tr = newLabel();
		SymbolTableEntry* end = newLabel();
		if(t == op_LT){
			m_code->generate(cd_LT, prevEntry, exp, tr);
		}
		else if(t == op_LE){
			m_code->generate(cd_LE, prevEntry, exp, tr);
		}
		else if(t == op_GT){
			m_code->generate(cd_GT, prevEntry, exp, tr);
		}
		else if(t == op_GE){
			m_code->generate(cd_GE, prevEntry, exp, tr);
		}
		else if(t == op_EQ){
			m_code->generate(cd_EQ, prevEntry, exp, tr);
		}
		else{
			m_code->generate(cd_NE, prevEntry, exp, tr);
		}
		m_code->generate(cd_ASSIGN, m_symbolTable->lookup(CodeFalse), NULL, result);
		m_code->generate(cd_GOTO, NULL, NULL, end);
		m_code->generate(cd_LABEL, NULL, NULL, tr);
		m_code->generate(cd_ASSIGN, m_symbolTable->lookup(CodeTrue), NULL, result);
		m_code->generate(cd_LABEL, NULL, NULL, end);
	}
	return result;
}
예제 #17
0
void Parser::parseIdentifierListPrime(EntryList& idList){
	if(isNext(tc_COMMA)){
		match(tc_COMMA);
		if(isNext(tc_ID)){
			idList.push_back(m_currentToken->getSymTabEntry());
		}
		match(tc_ID);
		if(m_parserError){
			TokenCode synch[] = {tc_COMMA, tc_COLON, tc_NONE};
			recover(synch);
//			if(isNext(tc_ID)){
//				match(tc_ID);
//			}
		}
		parseIdentifierListPrime(idList);
	}
}
예제 #18
0
파일: parselib2.c 프로젝트: cccnqu1/cccwd
int next(char *set) {
	if (isNext(set))
		cnext();
	else {
		printf("error!");
		exit(1);
	}
}
template <unsigned int dim> void test_skin_iterator(Box<3,size_t> & bx1, Box<3,size_t> & bx2, grid_sm<3,void> & g_sm,size_t (& bc)[dim] , size_t vol_test)
{
	grid_cpu<3,aggregate<size_t>> gtest(g_sm.getSize());
	gtest.setMemory();
	auto it = gtest.getSubIterator(0);

	while (it.isNext())
	{
		auto key = it.get();

		gtest.get<0>(key) = 0;

		++it;
	}

	size_t count = 0;
	grid_skin_iterator_bc<3> gsi(g_sm,bx1,bx2,bc);

	while (gsi.isNext() == true)
	{
		auto key = gsi.get();

		gtest.get<0>(key) += 1;

		count++;

		++gsi;
	}

	BOOST_REQUIRE_EQUAL(count,(size_t)vol_test);

	bool ret = true;
	auto it2 = gtest.getSubIterator(0);

	while (it2.isNext())
	{
		auto key = it2.get();

		ret &= gtest.get<0>(key) <= 1;

		++it2;
	}

	BOOST_REQUIRE_EQUAL(ret,true);
}
예제 #20
0
파일: pexp.c 프로젝트: cccnqu1/cccwd
int E() {
	printf("<E>");
	T();
	if (isNext("+-*/")) {
		cnext();
		E();
	}
	printf("</E>");
}
예제 #21
0
void Parser::parseStatementPrime(SymbolTableEntry* prevEntry){
	if(isNext(tc_LBRACKET) || isNext(tc_ASSIGNOP)){
		SymbolTableEntry* var = parseVariablePrime(prevEntry);
		match(tc_ASSIGNOP);
		if(m_parserError){
			TokenCode synch[] = {tc_ID, tc_NUMBER, tc_LPAREN, tc_NOT, tc_ADDOP, tc_NONE};
			recover(synch);
//			if(isNext(tc_ASSIGNOP)){
//				match(tc_ASSIGNOP);
//			}
		}
		SymbolTableEntry* exp = parseExpression();
		m_code->generate(cd_ASSIGN, exp, NULL, var);
	}
	else{
		parseProcedureStatementPrime(prevEntry);
	}
}
예제 #22
0
	/*! \brief Get the next element
	 *
	 * \return cell list iterator
	 *
	 */
	inline Cell_list_iterator operator++()
	{
		fp();
		while (isNext() && this->get() >= NN.get_gm())
		{
			fp();
		}

		return *this;
	}
예제 #23
0
SymbolTableEntry* Parser::parseFactorPrime(SymbolTableEntry* prevEntry){
	if(isNext(tc_LBRACKET)){
		parseVariablePrime(prevEntry);
	}
	else if(isNext(tc_LPAREN)){
		match(tc_LPAREN);
		parseExpressionList(prevEntry);
		match(tc_RPAREN);
		if(m_parserError){
			TokenCode synch[] = {tc_RPAREN, tc_END, tc_ADDOP, tc_MULOP, tc_RELOP, tc_THEN, tc_DO, tc_COMMA, tc_RBRACKET, tc_SEMICOL, tc_ELSE, tc_NONE};
			recover(synch);
//			if(isNext(tc_RPAREN)){
//				match(tc_RPAREN);
//			}
		}
		//m_code->generate(cd_CALL, prevEntry, NULL, NULL);
	}
	return prevEntry;
}
예제 #24
0
//Read the file and extract its contents to 
//the directory of the zipfile.
int do_extract(char *inputzip)
{
    char *extract_dir = dirname(inputzip);

    if ( (extract_dir != NULL) && (strlen(extract_dir) > 0) ) 
    {
        // ensure directory is created first
        char *dir = (char *) malloc(strlen(extract_dir) + 2);
        if(!dir)
        {
            return 0;
        }

        sprintf(dir, "%s/", extract_dir);
        mkdirs(dir);
        free(dir);
        chdir(extract_dir);
        free(extract_dir);
    }
    if (! openZipFileReader(inputzip)) 
    {
        return 0;
    }

    bool next = isNext();

    // We must have at least one entry
    if (!next) {  
        //sprintf(message,"Error: no entries in zip file.\n");
        return 0;
    }

    while (next) {
        readAndWrite();
        next = isNext();
    }

    closeZipFileReader();
    return 1;
}
예제 #25
0
SymbolTableEntry* Parser::parseFactor(){
	SymbolTableEntry* factor = NULL;
	SymbolTableEntry* result = m_symbolTable->lookup(CodeFalse);
	if(isNext(tc_ID)){
		factor = m_currentToken->getSymTabEntry();
		match(tc_ID);
		result = parseFactorPrime(factor);
	}
	else if(isNext(tc_LPAREN)){
		match(tc_LPAREN);
		result = parseExpression();
		match(tc_RPAREN);
		if(m_parserError){
			TokenCode synch[] = {tc_RPAREN, tc_END, tc_ADDOP, tc_MULOP, tc_RELOP, tc_THEN, tc_DO, tc_COMMA, tc_RBRACKET, tc_SEMICOL, tc_ELSE, tc_NONE};
			recover(synch);
//			if(isNext(tc_RPAREN)){
//				match(tc_RPAREN);
//			}
		}
	}
	else if(isNext(tc_NOT)){
		match(tc_NOT);
		factor = parseFactor();
		result = newTemp();
		m_code->generate(cd_NOT, factor, NULL, result);
	}
	else{
		result = m_currentToken->getSymTabEntry();
		match(tc_NUMBER);
		if(m_parserError){
			TokenCode synch[] = {tc_RPAREN, tc_END, tc_ADDOP, tc_MULOP, tc_RELOP, tc_THEN, tc_DO, tc_COMMA, tc_RBRACKET, tc_SEMICOL, tc_ELSE, tc_NONE};
			recover(synch);
//			if(isNext(tc_NUMBER)){
//				match(tc_NUMBER);
//			}
		}
	}
	return result;
}
예제 #26
0
//Read the file and extract its contents to the
//to the directory of the zipfile.
void do_read(char *inputzip, char* outputdir)
{
  char *extract_dir = NULL;

  if (outputdir != NULL)
      extract_dir = dirname(outputdir);
  else
      extract_dir = dirname(inputzip);

  if ( (extract_dir != NULL) && (strlen(extract_dir) > 0) ) 
  {
     // ensure directory is created first
     char *dir = (char *) malloc(strlen(extract_dir) + 2);
     sprintf(dir, "%s/", extract_dir);
     mkdirs(dir);
     free(dir);

     chdir(extract_dir);
  }
  openZipFileReader(inputzip);
  fprintf(stderr,"Archive: %s\n",inputzip);

  bool next = isNext();

  // We must have atleast one entry
  if (!next) {  
    sprintf(message,"Error: no entries in zip file.\n");
    l_abort(message);
  }

  while (next) {
    readAndWrite();
    next = isNext();
  }

  closeZipFileReader();
  if (remove_input_zip_file) remove(inputzip);
}
예제 #27
0
void Parser::parseArguments(){
	if(isNext(tc_LPAREN)){
		match(tc_LPAREN);
		parseParameterList();
		match(tc_RPAREN);
		if(m_parserError){
			TokenCode synch[] = {tc_COLON, tc_SEMICOL, tc_NONE};
			recover(synch);
//			if(isNext(tc_RPAREN)){
//				match(tc_RPAREN);
//			}
		}
	}
}
예제 #28
0
void Parser::parseProcedureStatementPrime(SymbolTableEntry* prevEntry){
	if(isNext(tc_LPAREN)){
		match(tc_LPAREN);
		parseExpressionList(prevEntry);
		match(tc_RPAREN);
		if(m_parserError){
			TokenCode synch[] = {tc_END, tc_SEMICOL, tc_ELSE, tc_NONE};
			recover(synch);
//			if(isNext(tc_RPAREN)){
//				match(tc_RPAREN);
//			}
		}
	}
}
예제 #29
0
	void decompose()
	{
		if (Mg.nparts[0] != 1)
		{
			// Decompose
			METIS_PartGraphRecursive(Mg.nvtxs, Mg.ncon, Mg.xadj, Mg.adjncy, Mg.vwgt, Mg.vsize, Mg.adjwgt, Mg.nparts, Mg.tpwgts, Mg.ubvec, Mg.options, Mg.objval, Mg.part);

			// vertex id

			size_t id = 0;

			// For each vertex store the processor that contain the data

			auto it = g.getVertexIterator();

			while (it.isNext())
			{
				g.vertex(it).template get<i>() = Mg.part[id];

				++id;
				++it;
			}
		}
		else
		{
			// Trivially assign all the domains to the processor 0

			auto it = g.getVertexIterator();

			while (it.isNext())
			{
				g.vertex(it).template get<i>() = 0;

				++it;
			}
		}
	}
예제 #30
0
	/*! \brief Create the VTK point definition
	 *
	 */
	std::string get_point_list()
	{
		//! vertex node output string
		std::stringstream v_out;

		//! For each sub-domain
		for (size_t i = 0 ; i < vg.size() ; i++)
		{
			// For each position in the cell
			for (size_t j = 0 ; j < vg.get(i).g.size() ; j++)
			{
				// If there are no grid in this position
				if (vg.get(i).g.get(j).grids.size() == 0)
					continue;

				//! Get the iterator
				auto it = vg.get(i).g.get(j).grids.get(0)->getIterator();

				//! Where the grid is defined
				Box<pair::first::dims,typename pair::second> dom;

				// Calculate the offset of the grid considering its cell position
				Point<pair::first::dims,typename pair::second> middle = vg.get(i).spacing / 2;
				Point<pair::first::dims,typename pair::second> one;
				one.one();
				one = one + toPoint<pair::first::dims,typename pair::second>::convert(vg.get(i).g.get(j).cmb);
				Point<pair::first::dims,typename pair::second> offset = pmul(middle,one) + vg.get(i).offset;

				// if there is the next element
				while (it.isNext())
				{
					Point<pair::first::dims,typename pair::second> p;
					p = it.get().toPoint();
					p = pmul(p,vg.get(i).spacing) + offset;

					if (pair::first::dims == 2)
						v_out << p.toString() << " 0.0" << "\n";
					else
						v_out << p.toString() << "\n";

					// increment the iterator
					++it;
				}
			}
		}

		// return the vertex list
		return v_out.str();
	}