Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by NguyenVietNamSon ( 5 years ago )
void REALLOC(string *&a, int oldSize, int newSize)
{
	string *temp = a;
	a = new string[newSize];

	int Min = min(oldSize, newSize);
	for(int i = 0; i < Min; ++i)
		a[i] = temp[i];

	delete[] temp;
}

void SymbolTable::run(string filename)
{
	string *Name = new string[100];
	string *Type = new string[100];
	int Size = 100;
	int Count = 0;

	bool isRes = false;
	ifstream FileIn(filename);

	while(!FileIn.eof())
	{
		string str;
		getline(FileIn, str);

		int length = (int)str.length();
		int i = 0;
		while(str[i] != ' ') i++;

		string s1 = str.substr(0, i);

		if(s1 == "INSERT")
		{
			int j = i;
			i++;
			while(str[i] != ' ') i++;

			string name = str.substr(j,  i - j);

			string type = str.substr(i + 1, length - (i + 1));

			if(Count >= Size)
			{
				REALLOC(Name, Size, Size + 100);
				REALLOC(Type, Size, Size + 100);
				Size += 100;
			}

			bool check = true;
			for(int i = 0; i < Count; ++i)
			{
				if(Name[i] == name)
				{
					check = false;
					break;
				}
			}

			if(isRes == true)
                cout << "\n";

			if(check == true)
			{
				Name[Count] = name;
				Type[Count] = type;
				Count++;

				cout << "success";

				isRes = true;
			}
			else
            {
				throw Redeclared(str);
				break;
            }
		}
	}
	delete[] Name;
	delete[] Type;
}

 

Revise this Paste

Your Name: Code Language: