Esempio n. 1
0
void Parser::ParseTypeDecl()
{
	t = sc.GetNextToken();
	while (true){
		Token t1 = t;
		t = sc.GetNextToken();		
		if (t1.GetType() != identifier || t.GetValue() != "=")
			throw Error("incorrect type declaration", t);
		TableStack.Find(t1.GetValue(), t);
		SymType* Type = ParseType(true);
		Type->SetName(t1.GetValue());
		table->insert(Symb(t1.GetValue(), Type));
		Type->print(os, true);
		os << ";" << endl;
		t = sc.GetNextToken();
		if (t.GetValue() != ";")
			throw Error("\";\" expected", t);
		t = sc.GetNextToken();
		if (t.GetValue() == "var" || t.GetValue() == "const" || t.GetValue() == "procedure" || t.GetValue() == "function" 
			|| t.GetValue() == "begin" || t.GetValue() == "EOF")
			return;
		if (t.GetValue() == "type")
			t = sc.GetNextToken();
	}
}
Esempio n. 2
0
vector<Symb> HC_encode_one(int len, int ct) {
	vector<Symb> paste;
	if (len) {
		paste.push_back(Symb(false, len, 0, 0));
		ct--;
		
		while (ct) {
			int toInsert = min(ct, 6);
			if (toInsert < 3)
				for (int j = 0; j < toInsert; j++)
					paste.push_back(Symb(false, len, 0, 0));
			else
				paste.push_back(Symb(false, 16, toInsert - 3, 2));
			ct -= toInsert;
		}
	} else {
		while (ct) {
			int toInsert = min(ct, 138);
			if (toInsert < 3)
				for (int j = 0; j < toInsert; j++)
					paste.push_back(Symb(false, 0, 0, 0));
			else {
				if (toInsert <= 10)
					paste.push_back(Symb(false, 17, toInsert - 3, 3));
				else 
					paste.push_back(Symb(false, 18, toInsert - 11, 7));
			}
			ct -= toInsert;
		}
	}
	return paste;
}
Esempio n. 3
0
vector<Symb> LZ77_encode(InWindow &slWindow, int blockSize, vector<Symb> &lz77coded, vector<unsigned char> &charList) {
	bool shouldStore = blockSize <= MAX_STORED_SIZE;
	string curStr = "";
	int prevLen = 0, prevDst = 0;

	for (int i = 0; i < min(blockSize, 3); ++i) {
		unsigned char curChr = slWindow.get();
		if (shouldStore) charList.push_back(curChr);
		lz77coded.push_back(Symb(true, curChr, 0, 0));
	}
	for (int i = 3; i < blockSize; i++) {
		unsigned char curChr = slWindow.get();
		if (shouldStore) charList.push_back(curChr);
		curStr += curChr;
		if (curStr.length() < 3)
			continue;

		int dst;
		if (prevLen == 258)
			dst = -1;
		else
			dst = slWindow.find(curStr, prevDst);

		if (dst == -1) {
			vector<Symb> paste = LZ77_encode_one(prevLen, prevDst, curStr);
			lz77coded.insert(lz77coded.end(), paste.begin(), paste.end());
			prevLen = prevDst = 0;
		} else {
			prevLen = curStr.length();
			prevDst = dst;
		}
	}
	vector<Symb> paste = LZ77_encode_one(prevLen, prevDst, curStr);
	lz77coded.insert(lz77coded.end(), paste.begin(), paste.end());
	prevLen = prevDst = 0;
	lz77coded.push_back(Symb(true, 256, 0, 0));

	return lz77coded;
}
Esempio n. 4
0
vector<Symb> LZ77_encode_one(int prevLen, int prevDst, string &curStr) {
	vector<Symb> paste;
	if (prevDst == 0) {
		paste.push_back(Symb(true,(unsigned char) curStr[0], 0, 0));
		curStr.assign(curStr.begin() + 1, curStr.end());
	} else {
		int j = 0;
		while (j + 1 <= 28 && prevLen >= litStartFrom[j + 1]) j++;
		int lenAdd = prevLen - litStartFrom[j];
		int lenAddLen = litExtraBits[j];
		
		paste.push_back(Symb(true, j + 257, lenAdd, lenAddLen));
		
		j = 0;
		while (j + 1 <= 29 && prevDst >= dstStartFrom[j + 1]) j++;
		int dstAdd = prevDst - dstStartFrom[j];
		int dstAddLen = dstExtraBits[j];
		
		paste.push_back(Symb(false, j, dstAdd, dstAddLen));

		curStr = curStr[curStr.length() - 1];
	}
	return paste;
}