All pastes #514382 Raw Edit

Stuff

public text v1 · immutable
#514382 ·published 2007-05-27 18:29 UTC
rendered paste body
/** vonneumann.h **/

#ifndef _VONNEUMANN_H
#define _VONNEUMANN_H

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <fstream>

class Compilador
{
	private:
 		std::string MyString;
		std::string VariavelStr;
		typedef std::vector<char> Vector_Char;
		typedef std::vector<std::string> Vector_Str;
		int Result;
		
	protected:
		std::map<std::string, std::string> MyVectorStr;
		
	public:
		Compilador(std::string MyFileStr);
		virtual ~Compilador();
//  		template<typename T> T imprimi( T type_one, T type_dois, ... );
};

Compilador::Compilador ( std::string MyFileStr )
{
	Vector_Char Interpreta;
	Vector_Str InterpretaStr;
	MyMap map;
	char cath_char;
	
	std::ifstream file;
	file.open( MyFileStr.c_str(), std::ifstream::in );
	while( file.eof ) {
		file.get(cath_char);
		while( cath_char != ' ' )
			Interpreta.push_back(cath_char);
		
		if( MyString == "cria" ) {
			file >> MyString;
			VariavelStr = MyString;
			file >> MyString;
			if ( MyString.c_str() == "=" ){
				file >> MyString;
				MyVectorStr[VariavelStr] = MyString;
			}
			else
			{
				MyVectorStr[VariavelStr];
			}
		}
		else if ( MyString == "imprimi" )
		{
			file >> MyString;
			InterpretaStr.push_back(MyVectorStr[MyString]);
			
			file >> MyString;
			if ( MyString.c_str() == "+" ){
				file >> MyString;
				InterpretaStr.push_back(MyVectorStr[MyString]);
				ResultStr = InterpretaStr[0] + InterpretaStr[1];
			}
			else if ( MyString.c_str() == "-" )
			{
				file >> MyString;
				InterpretaStr.push_back(MyVectorStr[MyString]);
				ResultStr = InterpretaStr[0] - InterpretaStr[1];
			}
			else if ( MyString.c_str() == "*" )
			{
				file >> MyString;
				InterpretaStr.push_back(MyVectorStr[MyString]);
				ResultStr = InterpretaStr[0] * InterpretaStr[1];
			}
			else if ( MyString.c_str() == "/" )
			{
				file >> MyString;
				InterpretaStr.push_back(MyVectorStr[MyString]);
				ResultStr = InterpretaStr[0] / InterpretaStr[1];
			}
			else if ( MyString.c_str() == "%" )
			{
				file >> MyString;
				InterpretaStr.push_back(MyVectorStr[MyString]);
				ResultStr = InterpretaStr[0] % InterpretaStr[1];
			}
			else
			{
				std::cout<< MyVectorStr[MyString];
			}
		}
		else
		{
			std::cout<< "Erro :"<< MyString<< " Not declared, or not valid"<< std::endl;	
		}
	}
}

Compilador::~Compilador()
{
	
}
#endif

/** vonneuman.cpp **/

#include "vonneuman.h"

using namespace std;

int main(int argc, char **argv)
{
	if ( argc == 2 ){
		Compilador compila( argv[1] );
	}else{
		cout <<"Erro falta de parametros"<< endl;
	}
	return 0;
}