Ejemplo n.º 1
0
string getRead(ifstream& readFile){
	string read,header,inter;
	char c;
	for(uint64_t i(0);i<1;++i){
		getline(readFile,header);
		getline(readFile,read);
	point:
		c=readFile.peek();
		if(c=='>'){
			if(read.size()>2){
				bool fail(false);
				for(uint64_t j(0);(j)<read.size();++j){
					if(read[j]!='A' and read[j]!='C' and read[j]!='T' and read[j]!='G'){
						fail=true;
						break;
					}
				}
				if(!fail){
					return read;
				}
			}
			read="";
		}else{
			if(!readFile.eof()){
				getline(readFile,inter);
				read+=inter;
				goto point;
			}else{
				if(read.size()>2){
					bool fail(false);
					for(uint64_t j(0);(j)<read.size();++j){
						if(read[j]!='A' and read[j]!='C' and read[j]!='T' and read[j]!='G'){
							fail=true;
							break;
						}
					}
					if(!fail){
							return read;
					}
				}
				return "";
			}
		}
	}
	return "";
}
Ejemplo n.º 2
0
Item::Item(ifstream &theFile)
    : sum(0.0), mean(0.0), min(0.0), q25(0.0), median(0.0), q75(0.0), max(0.0),
      statInformation(false), valid_values( true ), data_status_description()
{
    theFile >> name;
    theFile >> count;
    ReadWhitespaces(theFile);
    if(theFile.peek() != '-')
    {
        theFile >> mean;
        theFile >> median;
        theFile >> min;
        theFile >> max;
        theFile >> sum;
        if(count >= 2)
        {
            theFile >> variance;
        }
Ejemplo n.º 3
0
// Read protein entry's ACCESSION ID ( AC )by specified file position
bool CFastaParser::ReadEntryAC(string& strAC, long   lPosEntryStart, ifstream& ifDB)
{
	std::streamsize tLength = MAX_AC_LENGTH_PRO;
	char* pszBuf = new char[MAX_AC_LENGTH_PRO];


	ifDB.seekg(lPosEntryStart, ios::beg);

	if (ifDB.peek() == '>') 					//skip the char '>'
		ifDB.get();

	ifDB.getline(pszBuf, tLength - 1, ' ');

	strAC = pszBuf ;
	strAC = strAC.substr(0, strAC.find_last_not_of('\r')+1);
	delete pszBuf;
	return true;
}
Ejemplo n.º 4
0
void GetStrs(ifstream & fin, vector<string> & vistr)
{
	size_t len;
	string str;
	char ch;
	// check that there is something to read
	while (fin.peek() && !fin.eof()) 
	{
		fin.read((char *) &len, sizeof(size_t));
		for (size_t i = 0; i < len; i++)
		{
			fin.read(&ch, sizeof(char));
			str.push_back(ch);
		}
		vistr.push_back(str);
		str.clear();
	}
}
Ejemplo n.º 5
0
bool hasNextLog (ifstream & file)
{
#ifdef MAP
    cout << "Appel à la methode Read::hasNextLog" << endl;
#endif

	if ( !file.eof() && file.peek() != char_traits<wchar_t>::eof() )
	{
#ifdef MAP
	cout << "Read::hasNextLog = true" << endl;
#endif
		return true;
	}
#ifdef MAP
	cout << "Read::hasNextLog = false" << endl;
#endif
	return false;
} //----- Fin de hasNextLog
Ejemplo n.º 6
0
void
ignoreComment(ifstream& inpt)
{
  ECString nxt;
  char a;
  inpt.get(a);
  if(a == '/')
    {
      char b = inpt.peek();
      if(b == '*')
	{
	  while(inpt)
	    {
	      inpt >> nxt;
	      if(nxt == "*/") break;
	    }
	  return;
	}
    }
Ejemplo n.º 7
0
//
// Name: readStream()
// Discription: Reads the stream and gets the full instruction, then returning.
// Parameters: ifstream &stream - Stream to read from.
// Returns: bool - true errors, false no errors.
//
bool I_Let::readStream(ifstream &stream) {
    if (debug)
        readLineForDebug(stream);

    // var
    checkForEndOfLine();
    string var;
    stream >> var;
    int num = vars->asciiNumber(var);
    if (num == -1) {
        string error = "Variable unknown: ";
        error += var;
        reportError(error.c_str());
    } else {
        theVar = vars->asciiNumber(var);
        vars->isUsed(theVar);
    }

    // =
    checkForEndOfLine();
    char c = stream.peek();
    if (c != '=') {
        reportError("Missing \"=\" in let command.");
        return true;
    } else{
        char c[1];
        stream.read(c,1);
    }

    // Expression
    checkForEndOfLine();
    e.setVariableClass(vars);
    e.setDebug(debug);
    e.type = type;
    e.readStream(stream);

    return (moveToTheEndOfTheLine(stream));
}
Ejemplo n.º 8
0
string getFormFile(long start,long frame)
{
	

	char c;
	c=myfile.peek();;
	myfile.seekg(start);
	string toret;
	while(myfile.tellg()<start+frame && !myfile.eof())
		  {
			  int pos=myfile.tellg();
			  // c=myfile.peek();;
			  myfile>>c;
			 // cout<<"C:"<<c<<endl;
			  if(c=='a')c='A';
			  if(c=='t' || c=='u' || c=='U')c='T';
			  if(c=='g')c='G';
			  if(c=='c')c='C';
			  if(c=='.' ||c==' ' || c=='\n' || c=='>')continue;
			  toret+=c;
		  };
	return toret;
};
Ejemplo n.º 9
0
dll::dll(ifstream & infile)
{
	char buffer[100];
	int length;
	root = NULL;

	while(infile.eof() == false)
	{
		char * name;
		int classrooms, max_students, age_group;



		infile.getline(buffer, 100, ':');
		length = strlen(buffer);
		name = new char[length+1];
		strcpy(name, buffer);

		infile.getline(buffer, 5, ':');
		classrooms = atoi(buffer);

		infile.getline(buffer, 5, ':');
		max_students = atoi(buffer);

		infile.getline(buffer, 5);
		age_group = atoi(buffer);

		school current(name, classrooms, max_students, age_group);
		add(current);

		delete [] name;

		infile.peek();


	}
}
Ejemplo n.º 10
0
//DC <valor> (para fonte DC)
void Tensao::carregaParamDC(ifstream &arq)
{
	int i = 0;
	while(arq.good() && arq.peek() != '\n')
	{
		switch(i)
		{
			case 0: 
				arq >> m_DC;
				break;
			default:
				arq>>m_ignora;
				break;
		}
		i++;
	}
	if(i!=1)
	{
		cout<< m_nome <<" DC: Numero de parametros errado" << i << "/1"<<endl;
		arq.close();
		m_erro = true;
	}
	cout<<m_nome<<" DC: "<<m_nome_a<<" "<<m_nome_b<<" "<<m_DC<<endl;
}
Ejemplo n.º 11
0
int ParameterList::readNext(ifstream in,char * tmp){
	int tmp_lenght;
	//remove all leading spaces
	while(in.peek()==32) in.get();
	//check if end of line
	if((in.peek()==10 || in.peek()==13)) 
		return-1;

	in>>tmp;
	
	if(in.eof()) return -1;
	tmp_lenght=strlen(tmp);
	// look for comment sign
	if((int)strcspn(tmp,"#")<tmp_lenght){
		//found comment: read till the end and go to next line
		while(!(in.peek()==10 || in.peek()==13)) in.get();
		//remove end of line
		while((in.peek()==10 || in.peek()==13)) in.get();
		return -1;
	}
	return 1;


}
bool lexicalAnalyzer::checkAndAddTokens(char charToBeChecked, vector<Token> &tokenList, int& lineNumber, ifstream& in){
    Token tokenToBeAdded = Token();
    string tempString = string(1, charToBeChecked);
    char nextChar = in.peek();
    char tempChar;
    int currLine = lineNumber;
    bool endstring = false;
    int aposCount = 1;
    
    if(isspace(charToBeChecked)){
        return true;
    }
    
    else if(isalpha(charToBeChecked)){
        string word = string(1, charToBeChecked);
        while(isalnum(nextChar)){
            in.get(tempChar);
            word += string(1, tempChar);
            //cout << word << endl;
            if (isToken(word) != ""){
                if(!isalnum(in.peek())){
                    tokenToBeAdded = Token (isToken(word), word, lineNumber);
                    tokenList.push_back(tokenToBeAdded);
                    return true;
                }
            }
            nextChar = in.peek();
        }
    tokenToBeAdded = Token ("ID", word, lineNumber);
    tokenList.push_back(tokenToBeAdded);
    return true;
        //cout << word << endl;
    } //Keep Reading from input

    switch (charToBeChecked){
        case ',':
            tokenToBeAdded = Token ("COMMA", tempString, lineNumber);
            tokenList.push_back(tokenToBeAdded);
            return true;
            //output comma
            break;
        case ':':
            if(nextChar == '-'){
                tempString += nextChar;
                in.get(tempChar);
                tokenToBeAdded = Token ("COLON_DASH", tempString, lineNumber);
                tokenList.push_back(tokenToBeAdded);
                return true;
            }
            else{
                tokenToBeAdded = Token ("COLON", tempString, lineNumber);
                tokenList.push_back(tokenToBeAdded);
                return true;
            }
            //check if it's a c-dash, then output colon
        case '.':
            tokenToBeAdded = Token ("PERIOD", tempString, lineNumber);
            tokenList.push_back(tokenToBeAdded);
            return true;
            //create token object for period, and add to tokenList
        case '?':
            tokenToBeAdded = Token ("Q_MARK", tempString, lineNumber);
            tokenList.push_back(tokenToBeAdded);  
            return true;
            //create token object for qmark, and add to tokenList
        case '(':
            tokenToBeAdded = Token ("LEFT_PAREN", tempString, lineNumber);
            tokenList.push_back(tokenToBeAdded);
            return true;
            //create token object for lparenth, and add to tokenList
        case ')':
            tokenToBeAdded = Token ("RIGHT_PAREN", tempString, lineNumber);
            tokenList.push_back(tokenToBeAdded);
            return true;
            //create token object for r parenth, and add to tokenList
        case '#':
            if (nextChar == '|'){
                in.get(tempChar);
                tempString += string(1, tempChar);
                if(in.peek() == '|'){
                    in.get(tempChar);
                    tempString += string(1, tempChar);
                    if(in.peek() == '#'){
                        in.get(tempChar);
                        tempString += string(1, tempChar);
                        tokenToBeAdded = Token ("COMMENT", tempString, currLine);
                        tokenList.push_back(tokenToBeAdded);
                        return true;
                    }
                }
                do {
                    if(in.eof()){
                        tokenToBeAdded = Token ("UNDEFINED", tempString, currLine);
                        tokenList.push_back(tokenToBeAdded);
                        return false;
                    }
                    in.get(tempChar);
                    if(tempChar == '\n'){
                        lineNumber++;
                    }
                    tempString += string(1, tempChar);
                    nextChar = in.peek();
                } while(nextChar != '|');
                
                in.get(tempChar);
                tempString += string(1, tempChar);
                nextChar = in.peek();
                
                if(nextChar == '#'){
                    in.get(tempChar);
                    tempString += string(1, tempChar);
                    tokenToBeAdded = Token ("COMMENT", tempString, currLine);
                    tokenList.push_back(tokenToBeAdded);
                    return true;
                }
                else return false;
            }
            else{
                while(nextChar != '\n' && !in.eof()){
                    in.get(tempChar);
                    tempString += string(1, tempChar);
                    nextChar = in.peek();
                }
                tokenToBeAdded = Token ("COMMENT", tempString, currLine);
                tokenList.push_back(tokenToBeAdded);
                return true;
            }
            //peek for |, and add appropriate token.
            break;
        case '\'':
            in.get(tempChar);
            tempString += string(1, tempChar);
            nextChar = in.peek();
            while(endstring == false){
                nextChar = in.peek();
                if(tempChar == '\n') lineNumber++;
                if(tempChar == '\'' && nextChar == '\''){
                    in.get(tempChar);
                    tempString += string(1, tempChar);
                    aposCount += 2;
                    in.get(tempChar);
                    tempString += string(1, tempChar);
                }
                else if(tempChar == '\''){
                    tokenToBeAdded = Token ("STRING", tempString, currLine);
                    tokenList.push_back(tokenToBeAdded);
                    return true;
                }
                else if(in.eof()){
                    tokenToBeAdded = Token ("UNDEFINED", tempString, currLine);
                    tokenList.push_back(tokenToBeAdded);
                    return false;
                }
                else{
                    in.get(tempChar);
                    tempString += string(1, tempChar);
                }
            }
           
        default:
            tokenToBeAdded = Token ("UNDEFINED", tempString, currLine);
            tokenList.push_back(tokenToBeAdded);
         }
    return true;
}
// This will eath through white spaces.
void eatspaces(ifstream &inp)
{
    while(inp.peek() == ' ' || inp.peek() == '\n') inp.get();
}
Ejemplo n.º 14
0
/**
* Constructor responsible for reading data from the EDF file.
* It reads data from the header and stores key-value pairs in dictionry.
* Also EDF image is read.
*/
edf_reader::edf_reader(ifstream &in){
    
    char buffer[256], value_string[256];
    double value;
    char a = ' ';
    bool is_header = 0;
    int dim1, dim2;
    //
    //read first character from the file
    //
    in.get(a);
    //
    // read file until bace closing the header is met
    //
    while(in.peek()!='}'){
        //
	//prevention from corrupted bits in file
	//
	if(in.fail()){
            in.clear(in.rdstate() & ~ios::failbit);
            in.getline(buffer, 255);
            break;
        }
	//
	//check if the header begins
	//
	if((a=='{') || is_header==1){
	    //
	    //set flag if first time in the loop 
	    //
	    if(!is_header){
	        in.get(a);
	        is_header = 1;
	    }
	    //
	    //get key 
	    //
	    in.getline(buffer, 255,' ');
	    string key(buffer);
	    //
	    //check if key corresponds to float value
	    //
	    if(!strcmp(buffer,"Center_1")||!strcmp(buffer,"Center_2")||!strcmp(buffer,"DDummy")||!strcmp(buffer,"Dummy")||!strcmp(buffer,"Offset_2")||!strcmp(buffer,"Psize_1")||!strcmp(buffer,"Psize_2")||!strcmp(buffer,"SampleDistance")||!strcmp(buffer,"SaxsDataVersion")||!strcmp(buffer,"WaveLength")||!strcmp(buffer,"EDF_BinarySize")||!strcmp(buffer,"Image")||!strcmp(buffer, "Offset_1")) {
	        
	        //
		//get value corresponding to key
		//
		in.getline(buffer, 255, '=');
		while(in.peek()==' ')in.ignore(1,'\n');
                in >> value;
		//
		//store pairs key-double value in key_double dictionary
		//
		key_double.insert(pair<string, double>(key, value));        
	    }
	    
	    //
	    //get dimension separately and store in dictionary
	    //
	    
	    else if(!strcmp(buffer,"Dim_1")){
	        in.getline(buffer, 255, '=');
		while(in.peek()==' ')in.ignore(1,'\n');
                in >> value;
		dim1 = (int)value;
		(void)dim1; // TODO unused varable - quiet warnings
		key_double.insert(pair<string, double>(key, value));	            
	    }
Ejemplo n.º 15
0
bool isEmpty(ifstream& pFile)
{
    return pFile.peek() == ifstream::traits_type::eof();
}
Ejemplo n.º 16
0
QualityScores::QualityScores(ifstream& qFile){
	try {
		
		m = MothurOut::getInstance();
		
		seqName = "";
		int score;
		
		qFile >> seqName; 
		m->getline(qFile);
		//cout << seqName << endl;	
		if (seqName == "")	{
			m->mothurOut("Error reading quality file, name blank at position, " + toString(qFile.tellg()));
			m->mothurOutEndLine(); 
		}
		else{
			seqName = seqName.substr(1);
		}
		
		string qScoreString = m->getline(qFile);
		//cout << qScoreString << endl;
		while(qFile.peek() != '>' && qFile.peek() != EOF){
			if (m->control_pressed) { break; }
			string temp = m->getline(qFile);
			//cout << temp << endl;
			qScoreString +=  ' ' + temp;
		}
		//cout << "done reading " << endl;	
		istringstream qScoreStringStream(qScoreString);
		int count = 0;
		while(!qScoreStringStream.eof()){
			if (m->control_pressed) { break; }
			string temp;
			qScoreStringStream >> temp;  m->gobble(qScoreStringStream);
			
			//check temp to make sure its a number
			if (!m->isContainingOnlyDigits(temp)) { m->mothurOut("[ERROR]: In sequence " + seqName + "'s quality scores, expected a number and got " + temp + ", setting score to 0."); m->mothurOutEndLine(); temp = "0"; }
			convert(temp, score);
			
			//cout << count << '\t' << score << endl;
			qScores.push_back(score);
			count++;
		}
		//qScores.pop_back();
		
//		string scores = "";
//		
//		while(!qFile.eof()){	
//			
//			qFile >> seqName; 
//			
//			//get name
//			if (seqName.length() != 0) { 
//				seqName = seqName.substr(1);
//				while (!qFile.eof())	{	
//					char c = qFile.get(); 
//					//gobble junk on line
//					if (c == 10 || c == 13){	break;	}
//				} 
//				m->gobble(qFile);
//			}
//			
//			//get scores
//			while(qFile){
//				char letter=qFile.get();
//				if((letter == '>')){	qFile.putback(letter);	break;	}
//				else if (isprint(letter)) { scores += letter; }
//			}
//			m->gobble(qFile);
//			
//			break;
//		}
//		
//		//convert scores string to qScores
//		istringstream qScoreStringStream(scores);
//		
//		int score;
//		while(!qScoreStringStream.eof()){
//			
//			if (m->control_pressed) { break; }
//			
//			qScoreStringStream >> score;
//			qScores.push_back(score);
//		}
//		
//		qScores.pop_back();

		seqLength = qScores.size();
		//cout << "seqlength = " << seqLength << '\t' << count << endl;
		
	}
	catch(exception& e) {
		m->errorOut(e, "QualityScores", "QualityScores");
		exit(1);
	}							
	
}
Ejemplo n.º 17
0
string lexer(ifstream &file){
	
	char c;
	string lexeme = "", token ="", both="";
	bool notfound = true;


	do{
		c = file.get();

		///////////////////////////////////////////////////////////////////
		/// Identifier DFSM
		///////////////////////////////////////////////////////////////////
		if(isalpha(c)){
		
		
			/* state 2*/
			lexeme += c;
			token = "identifier";
			notfound = false;
				
					/* state 3*/			/* state 4*/			/* state 5*/
			while(isalpha(file.peek()) || isdigit(file.peek()) || file.peek()=='_'){
				
				c = file.get();
				lexeme += c;
			}

			int size= lexeme.size();

			if(lexeme[size-1] == '_'){

				token = "unknown";

			}
			///////////////////////////////////////////////////////////////////


			

			///////////////////////////////////////////////////////////////////
			// Keyword
			///////////////////////////////////////////////////////////////////
			if(lexeme=="function")
				token = "keyword";
			else if(lexeme=="int")
				token = "keyword";
			else if(lexeme=="boolean")
				token = "keyword";
			else if(lexeme=="real")
				token = "keyword";
			else if(lexeme=="if")
				token = "keyword";
			else if(lexeme=="else")
				token = "keyword";
			else if(lexeme=="return")
				token = "keyword";
			else if(lexeme=="write")
				token = "keyword";
			else if(lexeme=="read")
				token = "keyword";
			else if(lexeme=="while")
				token = "keyword";
			else if(lexeme=="endif")
				token = "keyword";
			else if(lexeme=="function")
				token = "true";
			else if(lexeme=="false")
				token = "keyword";

		} 

		///////////////////////////////////////////////////////////////////
		// Interger aand Real DFSM
		///////////////////////////////////////////////////////////////////
		/*For real and integer we combined both DFSM into one. Which either recieves a digit or a '.' */
		else if(isdigit(c)){
		
				
			    lexeme += c;
				token = "integer";
				notfound = false;

				
				while(isdigit(file.peek()) || file.peek()=='.'){
					
					c = file.get();
					lexeme += c;
					
					if( c=='.' )
						token = "real";

				}
		///////////////////////////////////////////////////////////////////

		}
		///////////////////////////////////////////////////////////////////
		// Operator, Separator and Unkown
		///////////////////////////////////////////////////////////////////
		else
		switch(c){
			case 'ÿ':
				lexeme = lexeme + c;
				notfound = false;
				token = "EndofFile";

			case '\n':
				lexeme = lexeme + c;
				notfound = false;
				token = "EndofLine";
				lexeme = "EndofLine";
				break;

			case '\t':
				break;

			case ' ':
				break;

			case '$':
				lexeme = lexeme + c;
				if(file.peek()=='$'){
					c = file.get();
					lexeme = lexeme + c;
					notfound = false;
					token = "separator";
				}else{
					notfound = false;
					token = "unknown";
				}
				break;

			case '{':
				lexeme += c;
				notfound = false;
				token = "separator";
				break;

			case '}':
				notfound = false;
				token = "separator";
				lexeme += c;
				break;

			case ';':
				lexeme = lexeme + c;
				notfound = false;
				token = "separator";
				break;

			case '(':
				lexeme = lexeme + c;
				notfound = false;
				token = "separator";
				break;

			case ')':
				lexeme = lexeme + c;
				notfound = false;
				token = "separator";
				break;

			case ':':
				lexeme = lexeme + c;
				notfound = false;
				token = "separator";

				if(file.peek()=='='){
					c = file.get();
					lexeme += c;
					token = "operator";
				}

				break;

			case '[':
				lexeme = lexeme + c;
				notfound = false;
				token = "separator";
				break;

			case ']':
				lexeme = lexeme + c;
				notfound = false;
				token = "separator";
				break;

			case ',':
				lexeme = lexeme + c;
				notfound = false;
				token = "separator";
				break;

			case '=':
				lexeme = lexeme + c;
				notfound = false;
				token = "operator";

				if(file.peek()=='>'){
					c = file.get();
					lexeme += c;
				}
				break;

			case '>':
				lexeme = lexeme + c;
				notfound = false;
				token = "operator";
				break;

			case '<':
				lexeme = lexeme + c;
				notfound = false;
				token = "operator";

				if(file.peek()=='='){
					c = file.get();
					lexeme += c;
				}
				break;

			case '/':
				lexeme = lexeme + c;
				notfound = false;
				token = "operator";

				if(file.peek()=='='){
					c = file.get();
					lexeme += c;
				}
				break;

			case '*':
				lexeme = lexeme + c;
				notfound = false;
				token = "operator";
				break;

			case '+':
				lexeme = lexeme + c;
				notfound = false;
				token = "operator";
				break;

			case '-':
				lexeme = lexeme + c;
				notfound = false;
				token = "operator";
				break;

			default:
				lexeme = lexeme + c;
				notfound = false;
				token = "unknown";
				
		}			

	}while(notfound);

	both = token + " " + lexeme;

	return both;

}
Ejemplo n.º 18
0
/** **/
token getToken(ifstream &is) {
	char lastChar;
	token ret;
	ret.type = static_cast<int>(token_ident::eof);
	ret.value = "";

	// get char
	is.get(lastChar);

	// kill "spaces"
	while (lastChar==' ' || lastChar=='\t' || lastChar=='\r') {
		if(is.eof()) return ret;
   		is.get(lastChar);
	}

	// singletons
	ret.value += lastChar;
	if(lastChar=='(') {	ret.type = static_cast<int>(token_ident::list_open); return ret; }
	if(lastChar==')') {	ret.type = static_cast<int>(token_ident::list_close); return ret; }
	if(lastChar=='[') {	ret.type = static_cast<int>(token_ident::option_open); return ret; }
	if(lastChar==']') {	ret.type = static_cast<int>(token_ident::option_close); return ret; }
	if(lastChar=='{') {	ret.type = static_cast<int>(token_ident::block_open); return ret; }
	if(lastChar=='}') {	ret.type = static_cast<int>(token_ident::block_close); return ret; }
	
	// delimiter?
	if(isDelimiter(lastChar)) {
		// merge delimiters
		//return buildWord(isDelimiter, is, lastChar, static_cast<int>(token_ident::delimiter));

		while(isDelimiter(lastChar)) {
			if(is.eof()) return ret;
   			is.get(lastChar);
		}

		// last read was NOT valid: restore it, cut it!
		is.seekg(-1, ios::cur);

		ret.type = static_cast<int>(token_ident::delimiter); 
		return ret;
	}

	// get identifyers and controll words
	if (isalpha(lastChar)) { // identifier: [a-zA-Z][a-zA-Z0-9]*
		auto fp = [](int c)->int{return isalnum(c);};
		return buildWord(fp, is, lastChar, static_cast<int>(token_ident::identifier));
	}

	// get numbers
	if (isdigit(lastChar)) {   // Number: [0-9.]+
		auto fp = [](int c)->int{return isdigit(c);};
		return buildWord(fp, is, lastChar, static_cast<int>(token_ident::number));
	
		//TODO: use for something - should we check for "this is a number"?
		//NumVal = strtod(NumStr.c_str(), 0);
	}

	// get comments
	if (lastChar == '#') {
		auto fp = [](int c)->int{ return (c!='\n' && c!='\r'); };
		return buildWord(fp, is, lastChar, static_cast<int>(token_ident::oneline_comment));
	}
	if (lastChar == '/' && is.peek() == '/') {
		auto fp = [](int c)->int{ return (c!='\n' && c!='\r'); };
		return buildWord(fp, is, lastChar, static_cast<int>(token_ident::oneline_comment));
	}	

	// get operants
	if(isOperator(lastChar)) {
		return buildWord(isOperator, is, lastChar, static_cast<int>(token_ident::operand));
	}

	if(lastChar == '"') {
		string StrValue = "";
		//TODO: needs an advanced lambda function. since its the only "block"-lex we do so far
		// i leave it as it was

		do {
			if(is.eof()) {
				ret.type = static_cast<int>(token_ident::string);
				ret.value = "Unsescaped String (EOF)";
				return ret;
			}

   			is.get(lastChar);
			if(lastChar=='"') break;
			if(lastChar=='\n' || lastChar=='\r') {
				ret.type = static_cast<int>(token_ident::string);
				ret.value = "Unsescaped String";
				return ret;
			}

			StrValue += lastChar;
		} while (1);

		ret.type = static_cast<int>(token_ident::string);
		ret.value = StrValue;
    	return ret;
	}

	// whatever.
	ret.type = 0;
	ret.value = "unknown";
	return ret;
}
Ejemplo n.º 19
0
bool Netlist::carregar(ifstream &arq)
{
	arq.ignore(MAX_LINHA,'\n');
	while(arq.good())
	{
		Elemento *elemento = NULL;
		switch(arq.peek())
		{
			case '.':
				carregarParametros(arq);
				break;
			case 'R':
				//arq.ignore();
				elemento = new Resistor(arq);
				break;
			
			case 'L':
				//arq.ignore();
				elemento = new Indutor(arq);
				break;
			case 'C':
				//arq.ignore();
				elemento = new Capacitor(arq);
				break;
			case 'O':
				//arq.ignore();
				elemento = new Ampop(arq);
				break;
			case 'V':			
				//arq.ignore();
				elemento = new Tensao(arq);
				break;
			case 'I':			
				//arq.ignore();
				elemento = new Corrente(arq);
				break;
			
			case 'E':			
				//arq.ignore();
				elemento = new Tensaotensao(arq);
				break;
			case 'F':			
				//arq.ignore();
				elemento = new Correntecorrente(arq);
				break;
			case 'G':			
				//arq.ignore();
				elemento = new Correntetensao(arq);
				break;
			case 'H':			
				//arq.ignore();
				elemento = new Tensaocorrente(arq);
				break;

			case 'W':
			case 'M':			
				//arq.ignore();
				elemento = new Mos(arq);
				break;
            case 'K':
                //arq.ignore();
                elemento = new Acoplamento(arq);
                break;
			case 'D':			
				//arq.ignore();
				elemento = new Diodo(arq);
				break;
			default:
				arq.ignore(MAX_LINHA,'\n');
				break;
		}
		if(elemento)
		{
			if(elemento->getErro())
				return false;
			elemento->associaMatriz(&m_matriz);
			m_elementos.push_back(elemento);		
		}
		elemento = NULL;
	}

	cout<<"O Circuito possui "<<m_elementos.size()<<" elemento(s) e "<<m_matriz.m_numVariaveis<<" variaveis"<<endl;

	cout<<"Variaveis:"<<endl;

	for(int i=1;i<=m_matriz.m_numVariaveis;i++)
	{
		cout<<i<<":"<<m_matriz.getNomeVariavel(i)<<endl;
	}

	string metodo;
	if(m_metodo == GEAR)
		metodo = "GEAR";
	else if(m_metodo == BE)
		metodo = "BE";
	else if(m_metodo == TRAP)
		metodo = "TRAP";

	cout<<"metodo="<<metodo<<",passo="<<m_passo<<",passos internos="<<m_passosInternos<<",tempo de analise="<<m_t<<endl;
	cout<<endl;

	return true;
}
Ejemplo n.º 20
0
BOOL static getField(ifstream& fin, CString& marker, CString& contents)
{
	static BOOL bNextLineIsBlank=FALSE;
	if(bNextLineIsBlank)
	{
		bNextLineIsBlank=FALSE;
		marker = "BLANKLINE";
		contents ="";
		return TRUE;
	}

	ASSERTX(fin.is_open());

	const int kBuffSize = 5000;	// CURRENTLY MAX FIELD SIZE TOO!

	CString sField;
	LPTSTR buff = sField.GetBuffer(kBuffSize+2);
	LPTSTR start_buff = buff;

	fin.eatwhite();
	char* b = buff;
	BOOL bFoundBlank = FALSE;
	do
	{
		fin.getline(b, kBuffSize - (b-buff), '\n');
		b += fin.gcount();
		if(fin.gcount())
		{
			*(b-1) = '\n'; // put a carriage return in place of the null terminator
			*b = '\0';		// null terminate in case the next getline fails
		}
		while(fin.peek() == '\n') // keep swallowing blank lines until we see what's at the end of them
		{
			fin.get(); // swallow the \n;
			if(fin.peek() == '\\')	 // if the blanks are followed by a record, then this constitutes a true blank line
			{
				bFoundBlank=TRUE;
				break;
			}
		}
	} while (!bFoundBlank && fin.good() && fin.gcount() && fin.peek() != '\\');

	bNextLineIsBlank = bFoundBlank; // will be used on the next call

	if( (kBuffSize-1) <= (b-buff))	// to long (and thus fin.gcount() == 0)
	{
		CString s;
		s.Format("The interlinear file appears to have a line which is longer than the maximum of %d characters which csCleanITX can handle.\n",
					kBuffSize);
		throw(s);

	}

	if(!buff[0])	// end of file
	{	sField.ReleaseBuffer(-1);
		return FALSE;
	}

	// eat white space before the SFM Code (will always be there after a \dis)
	while(*buff && _ismbcspace(*buff))
	{
		*buff='~'; // a hack so that iSpaceLoc, below, isn't set to the space between the "\dis" and marker
		++buff;
	}


	int iSpaceLoc ;
	// figure out where the marker ends and field contents begin
	iSpaceLoc = sField.FindOneOf(" \t\n");
	if(iSpaceLoc <= 1)// [0] should be the slash, [1] at least one char
	{	sField.ReleaseBuffer(-1);
		return FALSE;
	}


	start_buff[iSpaceLoc] = '\0';
	marker = buff + 1; // +1 to skip the slash
	marker.TrimRight();

	contents = start_buff + iSpaceLoc+1;
	contents.TrimLeft();
	contents.TrimRight();

	sField.ReleaseBuffer(-1);
	return TRUE;
}
int yylex()
{
	int c;

	while (1)
	{
		yytextclear();
		int c;
		while ((c = fin.get()) == ' ' || c == '\t' || c == '\n')	
	
		continue;	

		if (c == '/')	
		{
			if (fin.peek() == '*')	
			{
				fin.get();	
				while (c = fin.get())
				{
				if ((c == '*' && fin.peek() == '/') || c == '\n')
					break;					
				}
				fin.get();	
					continue; 
			}
			else 
				yytext[0]='/';
				yytext[1]=0;
				return DIVOP; //MULOP be * | / 
		}

		if (c == EOF){
			return EOFSY;
		}

		if (c == ':' && fin.peek() == '=')
		{
			yytext[0]=c;
			yytext[1]=fin.get();
			yytext[2]=0;
			return ASSIGNOPP;
		}
		if (c == '('){
			yytext[0] = '(';
			yytext[1]=0;
			return LPAREN;
		}
		if (c == ')'){
			yytext[0] = ')';
			yytext[1]=0;
			return RPAREN;
		}

		if (c == '+'){
			yytext[0] = '+';
			yytext[1]=0;
			return ADDOP; //ADDOP can be + | - 
		}
		if (c == '-'){
			yytext[0] = '-';
			yytext[1]=0;
			return SUBOP; //ADDOP can be + | - 
		}
		if (c == '*'){
			yytext[0] = '*';
			yytext[1]=0;
			return MULOP; //MULOP can be * | / 
		}
		
		if (c >= '0' && c <= '9') 
		{
			int dec = 0;	
			yytext[0] = c;
			int i = 1;
			while (((c = fin.get()) >= '0' && c <= '9') || (c == '.')) 
			{
				if (c == '.')	
					dec++;
				if (dec == 2)
					throw exception();
				yytext[i] = c;
				i++;
			}
			yytext[i]=0;
			fin.unget();	
			return NUMCONST;
		}
		else 
		{
			yytext[0] = toupper(c);
			int i = 1;
			while ((c = fin.get()) != ' ' && c != '\t' && c != '\n' && c != EOF && c != ':' && c != '(' && c != ')' && c != '+' && c != '-' && c != '*' && c != '/')
			{
				yytext[i] = toupper(c);
				i++;
			}
			yytext[i] = 0; 
			fin.unget();	
			
			if (_stricmp(yytext, "read") == 0)
			{
				return READSY;
			}
			
			if (_stricmp(yytext, "write") == 0)
			{
				return WRITESY;
			}

			return ID;
		}
	}
}
Ejemplo n.º 22
0
Token Scanner::GetNextToken()
{
	char currentChar, c;

	ClearBuffer();
	currentChar = NextChar();
	while (!sourceFile.eof())
	{
		if (isspace(currentChar))
			currentChar = NextChar();     // do nothing
		else if (isalpha(currentChar))
		{                                // identifier
			BufferChar(currentChar);
			c = sourceFile.peek();
			while (isalnum(c) || c == '_')
			{
				currentChar = NextChar();
				BufferChar(currentChar);
				c = sourceFile.peek();
			}
			return CheckReserved();
		}
		else if (isdigit(currentChar))
		{                                // integer literal
			BufferChar(currentChar);
			c = sourceFile.peek();
			while (isdigit(c))
			{
				currentChar = NextChar();
				BufferChar(currentChar);
				c = sourceFile.peek();
				if (c == ".") {
					currentChar = NextChar();
					BufferChar(currentChar);
					c = sourceFile.peek();
					while (isdigit(c))
					{
						currentChar = NextChar();
						BufferChar(currentChar);
						c = sourceFile.peek();
					}
					return FLOAT_LIT;
				}
			}
			return INT_LIT;
		}
		// Added section here: start
		else if (currentChar == '[')
			return LSTAPLE;
		else if (currentChar == ']')
			return RSTAPLE;
		else if (currentChar == '{')
			return LMUSTACHE;
		else if (currentChar == '}')
			return RMUSTACHE;
		// Added section here: end
		else if (currentChar == '(')
			return LBANANA;
		else if (currentChar == ')')
			return RBANANA;
		else if (currentChar == ';')
			return SEMICOLON;
		else if (currentChar == ',')
			return COMMA;
		else if (currentChar == ':') {
			return COLON;
		}
		else if (currentChar == '*') {
			BufferChar(currentChar);
			return MULT_OP;
		}
		else if (currentChar == '/') {
			BufferChar(currentChar);
			return DIV_OP;
		}
		else if (currentChar == '+')
		{
			BufferChar(currentChar);
			return PLUS_OP;
		}
		else if (currentChar == '<')
		{
			if (sourceFile.peek() == '=')
			{                             // := operator
				BufferChar(currentChar);
				currentChar = NextChar();
				BufferChar(currentChar);
				return LE_OP;
			}
			else {
				BufferChar(currentChar);
				return LT_OP;
			}
		}
		else if (currentChar == '>')
		{
			if (sourceFile.peek() == '=')
			{                             // := operator
				BufferChar(currentChar);
				currentChar = NextChar();
				BufferChar(currentChar);
				return GE_OP;
			}
			else {
				BufferChar(currentChar);
				return GT_OP;
			}
		}
		else if (currentChar == '!')
		{
			if (sourceFile.peek() == '!')
			{                             // := operator
				BufferChar(currentChar);
				currentChar = NextChar();
				BufferChar(currentChar);
				return EQ_OP2;
			}
			else if (sourceFile.peek() == '='){
				BufferChar(currentChar);
				currentChar = NextChar();
				BufferChar(currentChar);
				return NE_OP;
			}
			else {
				LexicalError(currentChar);
			}
		}
		else if (currentChar == 'F' || currentChar == 'T')
		{
			if (sourceFile.peek() == 'A')
			{                             // := operator
				BufferChar(currentChar);
				currentChar = NextChar();
				BufferChar(currentChar);
				if (sourceFile.peek() == 'L') {
					BufferChar(currentChar);
					currentChar = NextChar();
					BufferChar(currentChar);
					if (sourceFile.peek() == 'S') {
						BufferChar(currentChar);
						currentChar = NextChar();
						BufferChar(currentChar);
						if (sourceFile.peek() == 'E') {
							BufferChar(currentChar);
							currentChar = NextChar();
							BufferChar(currentChar);
							return BOOL_LIT;
						}
						else {
							LexicalError(currentChar);
						}
					}
					else {
						LexicalError(currentChar);
					}
				}
				else {
					LexicalError(currentChar);
				}
			}
			else if (sourceFile.peek() == 'R'){
				BufferChar(currentChar);
				currentChar = NextChar();
				BufferChar(currentChar);
				if (sourceFile.peek() == 'U') {
					BufferChar(currentChar);
					currentChar = NextChar();
					BufferChar(currentChar);
					if (sourceFile.peek() == 'E') {
						BufferChar(currentChar);
						currentChar = NextChar();
						BufferChar(currentChar);
						return BOOL_LIT;
					}
					else {
						LexicalError(currentChar);
					}
				}
				else {
					LexicalError(currentChar);
				}
			}
			else {
				LexicalError(currentChar);
			}
		}
		else if (currentChar == '=')
		{
			if (sourceFile.peek() == '=')
			{                             // := operator
				BufferChar(currentChar);
				currentChar = NextChar();
				BufferChar(currentChar);
				return EQ_OP1;
			}
			else {
				return ASSIGN_OP;
			}
		}
		else if (currentChar == '-')  
			if (sourceFile.peek() == '-') // comment
				do  // skip comment
					currentChar = NextChar();
				while (currentChar != '\n');
			else
			{
				BufferChar(currentChar);      // minus operator
				return MINUS_OP;
			}
		else if (currentChar == '"')		// string character
			do {
				currentChar = NextChar();
				c = sourceFile.peek();
				if (currentChar == '"' && c == '"'){
					currentChar = NextChar();
				}
				else if (currentChar == '"' && c != '"'){
					return CHEESE_LIT;
				}
				stringBuffer += currentChar;
			}
			while (c != '\n');
		else
			LexicalError(currentChar);
	} // end while
	return EOF_SYM;
}
Ejemplo n.º 23
0
map::map(ifstream  &infile)
{
	size = 25;
	char buffer[13] ={0};
	section = new vertex[size];

	for(int i = 0; i<size; ++i)
	{
		int a = i%5;

		if(a > 0)
		    	section[i].add_edge(section[i].head, i);
		if(a < 4)
			section[i].add_edge(section[i].head, i+2);
		if(i>4)
			section[i].add_edge(section[i].head, i-4);
		if(i<20)
			section[i].add_edge(section[i].head, i+6);



	}



	//input loop
	infile.peek();
	while(!infile.eof())
	{
		int age_4, age_10, age_13, age_18, age_60, age_retired, median_income = 0;
		char race;
		float latt, longit;



		infile.getline(buffer, 14, ':');
		latt = atof(buffer);
		if(latt == 0.0)
            return;

		infile.getline(buffer, 14, ':');
		longit = atof(buffer);

		infile.getline(buffer, 3, ':');
		age_4 = atoi(buffer);

		infile.getline(buffer, 3, ':');
		age_10 = atoi(buffer);

		infile.getline(buffer, 3, ':');
		age_13 = atoi(buffer);

		infile.getline(buffer, 3, ':');
		age_18 = atoi(buffer);

		infile.getline(buffer, 3, ':');
		age_60 = atoi(buffer);

		infile.getline(buffer, 3, ':');
		age_retired = atoi(buffer);

		infile.getline(buffer, 10, ':');
		median_income = atoi(buffer);

		infile.get(race);
		//infile.ignore();

        location * current;
		current = new location(latt, longit);
	
		section[current->sector()].add(age_4, age_10, age_13, age_18, age_60, age_retired, median_income, race);
	delete current;
        infile.peek();
	}

}
Ejemplo n.º 24
0
 bool at_eof(ifstream &ifstream) {
     return ifstream.peek() == ifstream::traits_type::eof();
 }
Ejemplo n.º 25
0
int getNextToken(){
	while(!infile.eof()) {
		char c = infile.peek();			
		if (c == '/') {			
			infile.get(c);
			char c2 = infile.peek();			
			if(c2 == '/') { 	// found a comment.
				infile.get(c);							
				while(c != '\n' && !infile.eof()){
					infile.get(c);
				}
			}else{			
				keyword = "";
				keyword += c;
				return KEYWORD_TOKEN;
			}	
		}else if(checkIfLetter(c)){	 							
			keyword = "";
			while((checkIfLetter(c) || checkIfDigit(c) || c == '_' ) && !infile.eof()){
				infile.get(c);			
				keyword += c;			
				c = infile.peek();
			}
			if(infile.eof() && treeStack.size() > 1){
				cout << "Error... stack not empty but reached end of file.\n";
				exit(1);
			}
			string* p = find(keyList, keyList + 20, keyword);
			if(p != (keyList + 20)){		
				return KEYWORD_TOKEN;
			}else{
				return IDENTIFIER_TOKEN;
			}
		}else if(find(operatorList, operatorList + 26, c) != operatorList + 26){
			keyword = "";
			infile.get(c);			
			char c2 = infile.peek();
			keyword += c;
			if(find(operatorList, operatorList + 26, c2) != operatorList + 26){
				infile.get(c);
				keyword += c;						
			}
			return KEYWORD_TOKEN;
		}else if(checkIfDigit(c)){		
			keyword = "";					
			while(checkIfDigit(c) && !infile.eof()){
				infile.get(c);			
				keyword += c;			
				c = infile.peek();
			}
			if(infile.eof() && treeStack.size() > 1){
				cout << "Error... stack not empty but reached end of file.\n";
				exit(1);
			}
			return INTEGER_TOKEN;
		}else if(checkIfPunction(c)){
			infile.get(c);
			keyword = "";
			keyword += c;
			return KEYWORD_TOKEN;
		}else if(c == '\''){						
			infile.get(c);
			keyword = "";
			keyword += c;
			do{
				infile.get(c);
				keyword += c;
				if ((find(stringList, stringList + 9, c) == stringList + 9) && 
					(find(operatorList, operatorList + 26, c) == operatorList + 26) && !checkIfLetter(c) && !checkIfDigit(c)){
					return 0;
				}
			}while(c != '\'' && !infile.eof());
			if(infile.eof() && treeStack.size() > 1){
				cout << "Error... stack not empty but reached end of file.\n";
				exit(1);
			}
			return STRING_TOKEN;
		}else{
			infile.get(c);
		}		
	}
	return 0;
}
Ejemplo n.º 26
0
// function defined by Michael Main for input data
bool is_more_stuff_there(ifstream& f)
{
    return (f && (f.peek() != EOF));
}