Beispiel #1
0
	void Generator::CopyFramePart(const wchar_t* stop, bool generateOutput) {
		wchar_t startCh = 0;
		int endOfStopString = 0;
		wchar_t ch = 0;

		if (stop != NULL) {
			startCh = stop[0];
			endOfStopString = coco_string_length(stop)-1;
		}

		fwscanf(fram, L"%lc", &ch); //	fram.ReadByte();
		while (!feof(fram)) { // ch != EOF
			if (stop != NULL && ch == startCh) {
				int i = 0;
				do {
					if (i == endOfStopString) return; // stop[0..i] found
					fwscanf(fram, L"%lc", &ch); i++;
				} while (ch == stop[i]);
				// stop[0..i-1] found; continue with last read character
				if (generateOutput) {
					wchar_t *subStop = coco_string_create(stop, 0, i);
					fwprintf(gen, L"%ls", subStop);
					coco_string_delete(subStop);
				}
			} else {
				if (generateOutput) { fwprintf(gen, L"%lc", ch); }
				fwscanf(fram, L"%lc", &ch);
			}
		}
		if (stop != NULL) {
			wchar_t *message = coco_string_create_append(L" -- Incomplete or corrupt frame file: ", frameFile);
			errors->Exception(message);
			delete [] message;
		}
	}
wchar_t *SymbolTable::string_create(wchar_t * val)
{
    wchar_t *str = coco_string_create(val);
    coco_strings.push_back(str);
    return str;
    //coco_string_delete
}
Beispiel #3
0
void Parser::Parse() {
    t = NULL;
    la = dummyToken = new Token();
    la->val = coco_string_create(L"Dummy Token");
    Get();
    Taste();

    Expect(0);
}
Beispiel #4
0
SymbolTable::SymbolTable(Parser* parser): 
		tInt(1), tBool(0), tSet(2), var(0), proc(1), scope(2),
		topScope(NULL), e(parser->errors), currentLevel(-1), undefObj(new Object()) {
	undefObj->name = coco_string_create("undef");
	undefObj->type = TYPE_UNDEF;
	undefObj->kind = var;
	undefObj->addr = 0;
	undefObj->level = 0;
	undefObj->next = NULL;
}
Beispiel #5
0
void SymbolTable::openScope(){
	Object* scop = new Object();
	scop->name = coco_string_create("");
	scop->kind = KIND_SCOPE;
	scop->locals = NULL;
	scop->nextAddr = 0;
	scop->next = topScope;
	topScope = scop;
	currentLevel++;
}
Beispiel #6
0
wchar_t* Buffer::GetString(int beg, int end) {
	int len = 0;
	wchar_t *buf = new wchar_t[end - beg];
	int oldPos = GetPos();
	SetPos(beg);
	while (GetPos() < end) buf[len++] = (wchar_t) Read();
	SetPos(oldPos);
	wchar_t *res = coco_string_create(buf, 0, len);
	coco_string_delete(buf);
	return res;
}
Beispiel #7
0
void main(int argc, char** argv)
{
		wchar_t *fileName = coco_string_create(argv[1]);
		Scanner *scanner = new Scanner(fileName);
		Parser *parser = new Parser(scanner);
		parser->Parse();

		coco_string_delete(fileName);
		delete parser;
		delete scanner;
}
Beispiel #8
0
wchar_t* coco_string_create(const wchar_t *value, int startIndex) {
    int valueLen = 0;
    int len = 0;

    if (value) {
        valueLen = wcslen(value);
        len = valueLen - startIndex;
    }

    return coco_string_create(value, startIndex, len);
}
Token* Scanner::NextToken() {
	while (ch == ' ' ||
			ch == 10 || ch == 13
	) NextCh();

	int recKind = noSym;
	int recEnd = pos;
	t = CreateToken();
	t->pos = pos; t->col = col; t->line = line;
	int state = start.state(ch);
	tlen = 0; AddCh();

	switch (state) {
		case -1: { t->kind = eofSym; break; } // NextCh already done
		case 0: {
			case_0:
			if (recKind != noSym) {
				tlen = recEnd - t->pos;
				SetScannerBehindT();
			}
			t->kind = recKind; break;
		} // NextCh already done
		case 1:
			case_1:
			recEnd = pos; recKind = 1;
			if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;}
			else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;}
		case 2:
			case_2:
			recEnd = pos; recKind = 2;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;}
			else {t->kind = 2; break;}
		case 3:
			if (ch == L'=') {AddCh(); goto case_4;}
			else {goto case_0;}
		case 4:
			case_4:
			{t->kind = 3; break;}
		case 5:
			{t->kind = 4; break;}
		case 6:
			{t->kind = 5; break;}
		case 7:
			{t->kind = 6; break;}
		case 8:
			{t->kind = 8; break;}
		case 9:
			{t->kind = 9; break;}

	}
	AppendVal(t);
	return t;
}
Beispiel #10
0
int main (int argc, char *argv[]) {
	if (argc == 2) {
		wchar_t *fileName = coco_string_create(argv[1]);
		Scanner *scanner = new Scanner(fileName);
		Parser *parser = new Parser(scanner);
		parser->tab = new SymbolTable(parser);
		parser->Parse();
		coco_string_delete(fileName);
		delete parser;
		delete scanner;
	} else
		std::cout<<"\n"<<"Usage:\n"<<"\t"<<argv[0]<<" <file_name>\n\n";
	return 0;

}
Beispiel #11
0
	void Generator::GenPrefixFromNamespace() {
		const wchar_t *nsName = tab->nsName;
		if (nsName == NULL || coco_string_length(nsName) == 0) {
			return;
		}
		const int len = coco_string_length(nsName);
		int startPos = 0;
		do {
			int curLen = coco_string_indexof(nsName + startPos, COCO_CPP_NAMESPACE_SEPARATOR);
			if (curLen == -1) { curLen = len - startPos; }
			wchar_t *curNs = coco_string_create(nsName, startPos, curLen);
			fwprintf(gen, L"%ls_", curNs);
			coco_string_delete(curNs);
			startPos = startPos + curLen + 1;
		} while (startPos < len);
	}
Beispiel #12
0
Symbol::Symbol(int typ, const wchar_t* name, int line) {
	n = 0;
	graph = NULL;
	tokenKind = 0;
	deletable = false;
	firstReady = false;
	first = NULL;
	follow = NULL;
	nts = NULL;
	attrPos = NULL;
	semPos = NULL;

	this->typ = typ;
	this->name = coco_string_create(name);
	this->line = line;
}
Beispiel #13
0
int main(int argc, char* argv[])
{
	if(argc == 2)
	{
		wchar_t *fileName = coco_string_create(argv[1]);
		Scanner *scanner = new Scanner(fileName);
		Parser *parser = new Parser(scanner);
		parser->Parse();
		printf("%d errors detected:",parser->errors->count);
	}
	else
	{
		printf("file not specified");
	}


	return 0;
}
void Parser::Get() {
	for (;;) {
		t = la;
		la = scanner->Scan();
		if (la->kind <= maxT) { ++errDist; break; }

		if (dummyToken != t) {
			dummyToken->kind = t->kind;
			dummyToken->pos = t->pos;
			dummyToken->col = t->col;
			dummyToken->line = t->line;
			dummyToken->next = NULL;
			coco_string_delete(dummyToken->val);
			dummyToken->val = coco_string_create(t->val);
			t = dummyToken;
		}
		la = t;
	}
}
Beispiel #15
0
int ParserGen::GenNamespaceOpen(const wchar_t *nsName) {
	if (nsName == NULL || coco_string_length(nsName) == 0) {
		return 0;
	}
	const int len = coco_string_length(nsName);
	int startPos = 0;
	int nrOfNs = 0;
	do {
		int curLen = coco_string_indexof(nsName + startPos, COCO_CPP_NAMESPACE_SEPARATOR);
		if (curLen == -1) { curLen = len - startPos; }
		wchar_t *curNs = coco_string_create(nsName, startPos, curLen);
		fwprintf(gen, L"namespace %ls {\n", curNs);
		coco_string_delete(curNs);
		startPos = startPos + curLen + 1;
		if (startPos < len && nsName[startPos] == COCO_CPP_NAMESPACE_SEPARATOR) {
			++startPos;
		}
		++nrOfNs;
	} while (startPos < len);
	return nrOfNs;
}
Beispiel #16
0
int main (int argc, char *argv[]) {
	if (argc == 2) {
		wchar_t *fileName = coco_string_create(argv[1]);
		Taste::Scanner *scanner = new Taste::Scanner(fileName);
		Taste::Parser *parser = new Taste::Parser(scanner);
		parser->tab = new Taste::SymbolTable(parser);
		parser->gen = new Taste::CodeGenerator();
		parser->Parse();
		if (parser->errors->count == 0) {
			parser->gen->Decode();
			parser->gen->Interpret("Taste.IN");
		}
		coco_string_delete(fileName);
		delete parser->gen;
		delete parser->tab;
		delete parser;
		delete scanner;
	} else
		printf("-- No source file specified\n");

	return 0;

}
Beispiel #17
0
void Parser::Ident(wchar_t* &name) {
    Expect(1);
    name = coco_string_create(t->val);
}
Beispiel #18
0
Token* Scanner::NextToken() {
    while (ch == ' ' ||
            (ch >= 9 && ch <= 10) || ch == 13
          ) NextCh();
    if ((ch == L'/' && Comment0()) || (ch == L'/' && Comment1()) || (ch == L'/' && Comment2())) return NextToken();
    int recKind = noSym;
    int recEnd = pos;
    t = CreateToken();
    t->pos = pos;
    t->col = col;
    t->line = line;
    t->charPos = charPos;
    int state = start.state(ch);
    tlen = 0;
    AddCh();

    switch (state) {
    case -1: {
        t->kind = eofSym;    // NextCh already done
        break;
    }
    case 0: {
case_0:
        if (recKind != noSym) {
            tlen = recEnd - t->pos;
            SetScannerBehindT();
        }
        t->kind = recKind;
        break;
    } // NextCh already done
    case 1:
case_1:
        recEnd = pos;
        recKind = 1;
        if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {
            AddCh();
            goto case_1;
        }
        else {
            t->kind = 1;
            wchar_t *literal = coco_string_create(tval, 0, tlen);
            t->kind = keywords.get(literal, t->kind);
            coco_string_delete(literal);
            break;
        }
    case 2:
case_2:
        recEnd = pos;
        recKind = 2;
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_2;
        }
        else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') {
            AddCh();
            goto case_13;
        }
        else if (ch == L'E' || ch == L'e') {
            AddCh();
            goto case_3;
        }
        else {
            t->kind = 2;
            break;
        }
    case 3:
case_3:
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_5;
        }
        else if (ch == L'+' || ch == L'-') {
            AddCh();
            goto case_4;
        }
        else {
            goto case_0;
        }
    case 4:
case_4:
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_5;
        }
        else {
            goto case_0;
        }
    case 5:
case_5:
        recEnd = pos;
        recKind = 2;
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_5;
        }
        else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') {
            AddCh();
            goto case_13;
        }
        else {
            t->kind = 2;
            break;
        }
    case 6:
case_6:
        recEnd = pos;
        recKind = 2;
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_6;
        }
        else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') {
            AddCh();
            goto case_13;
        }
        else if (ch == L'E' || ch == L'e') {
            AddCh();
            goto case_7;
        }
        else {
            t->kind = 2;
            break;
        }
    case 7:
case_7:
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_9;
        }
        else if (ch == L'+' || ch == L'-') {
            AddCh();
            goto case_8;
        }
        else {
            goto case_0;
        }
    case 8:
case_8:
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_9;
        }
        else {
            goto case_0;
        }
    case 9:
case_9:
        recEnd = pos;
        recKind = 2;
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_9;
        }
        else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') {
            AddCh();
            goto case_13;
        }
        else {
            t->kind = 2;
            break;
        }
    case 10:
case_10:
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_12;
        }
        else if (ch == L'+' || ch == L'-') {
            AddCh();
            goto case_11;
        }
        else {
            goto case_0;
        }
    case 11:
case_11:
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_12;
        }
        else {
            goto case_0;
        }
    case 12:
case_12:
        recEnd = pos;
        recKind = 2;
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_12;
        }
        else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') {
            AddCh();
            goto case_13;
        }
        else {
            t->kind = 2;
            break;
        }
    case 13:
case_13:
        {
            t->kind = 2;
            break;
        }
    case 14:
case_14:
        recEnd = pos;
        recKind = 3;
        if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') {
            AddCh();
            goto case_14;
        }
        else {
            t->kind = 3;
            break;
        }
    case 15:
case_15:
        if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F') || (ch >= L'a' && ch <= L'f')) {
            AddCh();
            goto case_16;
        }
        else {
            goto case_0;
        }
    case 16:
case_16:
        recEnd = pos;
        recKind = 3;
        if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F') || (ch >= L'a' && ch <= L'f')) {
            AddCh();
            goto case_16;
        }
        else if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') {
            AddCh();
            goto case_14;
        }
        else {
            t->kind = 3;
            break;
        }
    case 17:
        if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= 65535)) {
            AddCh();
            goto case_18;
        }
        else {
            goto case_0;
        }
    case 18:
case_18:
        if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= 65535)) {
            AddCh();
            goto case_18;
        }
        else if (ch == 39) {
            AddCh();
            goto case_19;
        }
        else {
            goto case_0;
        }
    case 19:
case_19:
        {
            t->kind = 4;
            break;
        }
    case 20:
case_20:
        if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= 65535)) {
            AddCh();
            goto case_20;
        }
        else if (ch == L'"') {
            AddCh();
            goto case_21;
        }
        else {
            goto case_0;
        }
    case 21:
case_21:
        {
            t->kind = 5;
            break;
        }
    case 22:
    {
        t->kind = 25;
        break;
    }
    case 23:
    {
        t->kind = 26;
        break;
    }
    case 24:
    {
        t->kind = 27;
        break;
    }
    case 25:
    {
        t->kind = 28;
        break;
    }
    case 26:
    {
        t->kind = 29;
        break;
    }
    case 27:
    {
        t->kind = 30;
        break;
    }
    case 28:
    {
        t->kind = 31;
        break;
    }
    case 29:
    {
        t->kind = 32;
        break;
    }
    case 30:
    {
        t->kind = 33;
        break;
    }
    case 31:
    {
        t->kind = 34;
        break;
    }
    case 32:
case_32:
        if (ch == L'.') {
            AddCh();
            goto case_33;
        }
        else {
            goto case_0;
        }
    case 33:
case_33:
        {
            t->kind = 35;
            break;
        }
    case 34:
case_34:
        if (ch == L'e') {
            AddCh();
            goto case_35;
        }
        else {
            goto case_0;
        }
    case 35:
case_35:
        if (ch == L'f') {
            AddCh();
            goto case_36;
        }
        else {
            goto case_0;
        }
    case 36:
case_36:
        if (ch == L'i') {
            AddCh();
            goto case_37;
        }
        else {
            goto case_0;
        }
    case 37:
case_37:
        if (ch == L'n') {
            AddCh();
            goto case_38;
        }
        else {
            goto case_0;
        }
    case 38:
case_38:
        if (ch == L'e') {
            AddCh();
            goto case_39;
        }
        else {
            goto case_0;
        }
    case 39:
case_39:
        if (ch == 10 || ch == 13) {
            AddCh();
            goto case_40;
        }
        else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) {
            AddCh();
            goto case_39;
        }
        else {
            goto case_0;
        }
    case 40:
case_40:
        {
            t->kind = 110;
            break;
        }
    case 41:
case_41:
        if (ch == L'n') {
            AddCh();
            goto case_42;
        }
        else {
            goto case_0;
        }
    case 42:
case_42:
        if (ch == L'd') {
            AddCh();
            goto case_43;
        }
        else {
            goto case_0;
        }
    case 43:
case_43:
        if (ch == L'e') {
            AddCh();
            goto case_44;
        }
        else {
            goto case_0;
        }
    case 44:
case_44:
        if (ch == L'f') {
            AddCh();
            goto case_45;
        }
        else {
            goto case_0;
        }
    case 45:
case_45:
        if (ch == 10 || ch == 13) {
            AddCh();
            goto case_46;
        }
        else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) {
            AddCh();
            goto case_45;
        }
        else {
            goto case_0;
        }
    case 46:
case_46:
        {
            t->kind = 111;
            break;
        }
    case 47:
case_47:
        if (ch == 10 || ch == 13) {
            AddCh();
            goto case_48;
        }
        else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) {
            AddCh();
            goto case_47;
        }
        else {
            goto case_0;
        }
    case 48:
case_48:
        {
            t->kind = 112;
            break;
        }
    case 49:
case_49:
        if (ch == L'f') {
            AddCh();
            goto case_50;
        }
        else {
            goto case_0;
        }
    case 50:
case_50:
        if (ch == 10 || ch == 13) {
            AddCh();
            goto case_51;
        }
        else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) {
            AddCh();
            goto case_50;
        }
        else {
            goto case_0;
        }
    case 51:
case_51:
        {
            t->kind = 113;
            break;
        }
    case 52:
case_52:
        if (ch == L'e') {
            AddCh();
            goto case_53;
        }
        else {
            goto case_0;
        }
    case 53:
case_53:
        if (ch == 10 || ch == 13) {
            AddCh();
            goto case_54;
        }
        else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) {
            AddCh();
            goto case_53;
        }
        else {
            goto case_0;
        }
    case 54:
case_54:
        {
            t->kind = 114;
            break;
        }
    case 55:
case_55:
        if (ch == L'd') {
            AddCh();
            goto case_56;
        }
        else {
            goto case_0;
        }
    case 56:
case_56:
        if (ch == L'i') {
            AddCh();
            goto case_57;
        }
        else {
            goto case_0;
        }
    case 57:
case_57:
        if (ch == L'f') {
            AddCh();
            goto case_58;
        }
        else {
            goto case_0;
        }
    case 58:
case_58:
        if (ch == 10 || ch == 13) {
            AddCh();
            goto case_59;
        }
        else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) {
            AddCh();
            goto case_58;
        }
        else {
            goto case_0;
        }
    case 59:
case_59:
        {
            t->kind = 115;
            break;
        }
    case 60:
case_60:
        if (ch == L'c') {
            AddCh();
            goto case_61;
        }
        else {
            goto case_0;
        }
    case 61:
case_61:
        if (ch == L'l') {
            AddCh();
            goto case_62;
        }
        else {
            goto case_0;
        }
    case 62:
case_62:
        if (ch == L'u') {
            AddCh();
            goto case_63;
        }
        else {
            goto case_0;
        }
    case 63:
case_63:
        if (ch == L'd') {
            AddCh();
            goto case_64;
        }
        else {
            goto case_0;
        }
    case 64:
case_64:
        if (ch == L'e') {
            AddCh();
            goto case_65;
        }
        else {
            goto case_0;
        }
    case 65:
case_65:
        if (ch == 10 || ch == 13) {
            AddCh();
            goto case_66;
        }
        else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) {
            AddCh();
            goto case_65;
        }
        else {
            goto case_0;
        }
    case 66:
case_66:
        {
            t->kind = 116;
            break;
        }
    case 67:
        recEnd = pos;
        recKind = 3;
        if ((ch >= L'8' && ch <= L'9')) {
            AddCh();
            goto case_71;
        }
        else if ((ch >= L'0' && ch <= L'7')) {
            AddCh();
            goto case_72;
        }
        else if (ch == L'.') {
            AddCh();
            goto case_6;
        }
        else if (ch == L'E' || ch == L'e') {
            AddCh();
            goto case_10;
        }
        else if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') {
            AddCh();
            goto case_14;
        }
        else if (ch == L'X' || ch == L'x') {
            AddCh();
            goto case_15;
        }
        else {
            t->kind = 3;
            break;
        }
    case 68:
case_68:
        recEnd = pos;
        recKind = 3;
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_68;
        }
        else if (ch == L'.') {
            AddCh();
            goto case_6;
        }
        else if (ch == L'E' || ch == L'e') {
            AddCh();
            goto case_10;
        }
        else if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') {
            AddCh();
            goto case_14;
        }
        else {
            t->kind = 3;
            break;
        }
    case 69:
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_2;
        }
        else if (ch == L'.') {
            AddCh();
            goto case_32;
        }
        else {
            goto case_0;
        }
    case 70:
case_70:
        if (ch == 9 || (ch >= 11 && ch <= 12) || ch == L' ') {
            AddCh();
            goto case_70;
        }
        else if (ch == L'd') {
            AddCh();
            goto case_34;
        }
        else if (ch == L'u') {
            AddCh();
            goto case_41;
        }
        else if (ch == L'i') {
            AddCh();
            goto case_73;
        }
        else if (ch == L'e') {
            AddCh();
            goto case_74;
        }
        else {
            goto case_0;
        }
    case 71:
case_71:
        if ((ch >= L'0' && ch <= L'9')) {
            AddCh();
            goto case_71;
        }
        else if (ch == L'.') {
            AddCh();
            goto case_6;
        }
        else if (ch == L'E' || ch == L'e') {
            AddCh();
            goto case_10;
        }
        else {
            goto case_0;
        }
    case 72:
case_72:
        recEnd = pos;
        recKind = 3;
        if ((ch >= L'8' && ch <= L'9')) {
            AddCh();
            goto case_71;
        }
        else if ((ch >= L'0' && ch <= L'7')) {
            AddCh();
            goto case_72;
        }
        else if (ch == L'.') {
            AddCh();
            goto case_6;
        }
        else if (ch == L'E' || ch == L'e') {
            AddCh();
            goto case_10;
        }
        else if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') {
            AddCh();
            goto case_14;
        }
        else {
            t->kind = 3;
            break;
        }
    case 73:
case_73:
        if (ch == L'f') {
            AddCh();
            goto case_47;
        }
        else if (ch == L'n') {
            AddCh();
            goto case_60;
        }
        else {
            goto case_0;
        }
    case 74:
case_74:
        if (ch == L'l') {
            AddCh();
            goto case_75;
        }
        else if (ch == L'n') {
            AddCh();
            goto case_55;
        }
        else {
            goto case_0;
        }
    case 75:
case_75:
        if (ch == L'i') {
            AddCh();
            goto case_49;
        }
        else if (ch == L's') {
            AddCh();
            goto case_52;
        }
        else {
            goto case_0;
        }
    case 76:
case_76:
        {
            t->kind = 93;
            break;
        }
    case 77:
    {
        t->kind = 96;
        break;
    }
    case 78:
    {
        t->kind = 99;
        break;
    }
    case 79:
    {
        t->kind = 100;
        break;
    }
    case 80:
        recEnd = pos;
        recKind = 1;
        if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F') || (ch >= L'H' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {
            AddCh();
            goto case_1;
        }
        else if (ch == L'G') {
            AddCh();
            goto case_81;
        }
        else {
            t->kind = 1;
            wchar_t *literal = coco_string_create(tval, 0, tlen);
            t->kind = keywords.get(literal, t->kind);
            coco_string_delete(literal);
            break;
        }
    case 81:
case_81:
        recEnd = pos;
        recKind = 1;
        if ((ch >= L'0' && ch <= L'9') || ch == L'A' || (ch >= L'C' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {
            AddCh();
            goto case_1;
        }
        else if (ch == L'B') {
            AddCh();
            goto case_82;
        }
        else {
            t->kind = 1;
            wchar_t *literal = coco_string_create(tval, 0, tlen);
            t->kind = keywords.get(literal, t->kind);
            coco_string_delete(literal);
            break;
        }
    case 82:
case_82:
        recEnd = pos;
        recKind = 1;
        if ((ch >= L'0' && ch <= L'9') || (ch >= L'B' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {
            AddCh();
            goto case_1;
        }
        else if (ch == L'A') {
            AddCh();
            goto case_83;
        }
        else {
            t->kind = 1;
            wchar_t *literal = coco_string_create(tval, 0, tlen);
            t->kind = keywords.get(literal, t->kind);
            coco_string_delete(literal);
            break;
        }
    case 83:
case_83:
        recEnd = pos;
        recKind = 1;
        if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {
            AddCh();
            goto case_1;
        }
        else if (ch == L'(') {
            AddCh();
            goto case_76;
        }
        else {
            t->kind = 1;
            wchar_t *literal = coco_string_create(tval, 0, tlen);
            t->kind = keywords.get(literal, t->kind);
            coco_string_delete(literal);
            break;
        }

    }
    AppendVal(t);
    return t;
}
Beispiel #19
0
wchar_t* coco_string_create(const wchar_t* value) {
    return coco_string_create(value, 0);
}
Beispiel #20
0
Symbol::Symbol(SymbolType symbolType, wchar_t* const name, DataType * pType) {
	mName = coco_string_create(name);
	mpDataType = pType;
	mSymbolType = symbolType;
}
Beispiel #21
0
Token* Scanner::NextToken() {
	while (ch == ' ' ||
			(ch >= 9 && ch <= 10) || ch == 13
	) NextCh();
	if ((ch == L'/' && Comment0()) || (ch == L'/' && Comment1())) return NextToken();
	int recKind = noSym;
	int recEnd = pos;
	t = CreateToken();
	t->pos = pos; t->col = col; t->line = line; t->charPos = charPos;
	int state = start.state(ch);
	tlen = 0; AddCh();

	switch (state) {
		case -1: { t->kind = eofSym; break; } // NextCh already done
		case 0: {
			case_0:
			if (recKind != noSym) {
				tlen = recEnd - t->pos;
				SetScannerBehindT();
			}
			t->kind = recKind; break;
		} // NextCh already done
		case 1:
			case_1:
			recEnd = pos; recKind = 1;
			if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;}
			else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;}
		case 2:
			case_2:
			recEnd = pos; recKind = 2;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;}
			else {t->kind = 2; break;}
		case 3:
			case_3:
			{t->kind = 3; break;}
		case 4:
			case_4:
			{t->kind = 4; break;}
		case 5:
			if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_6;}
			else if (ch == 92) {AddCh(); goto case_7;}
			else {goto case_0;}
		case 6:
			case_6:
			if (ch == 39) {AddCh(); goto case_9;}
			else {goto case_0;}
		case 7:
			case_7:
			if ((ch >= L' ' && ch <= L'~')) {AddCh(); goto case_8;}
			else {goto case_0;}
		case 8:
			case_8:
			if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'f')) {AddCh(); goto case_8;}
			else if (ch == 39) {AddCh(); goto case_9;}
			else {goto case_0;}
		case 9:
			case_9:
			{t->kind = 5; break;}
		case 10:
			case_10:
			recEnd = pos; recKind = 42;
			if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_10;}
			else {t->kind = 42; break;}
		case 11:
			case_11:
			recEnd = pos; recKind = 43;
			if ((ch >= L'-' && ch <= L'.') || (ch >= L'0' && ch <= L':') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_11;}
			else {t->kind = 43; break;}
		case 12:
			case_12:
			if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;}
			else if (ch == 10 || ch == 13) {AddCh(); goto case_4;}
			else if (ch == L'"') {AddCh(); goto case_3;}
			else if (ch == 92) {AddCh(); goto case_14;}
			else {goto case_0;}
		case 13:
			recEnd = pos; recKind = 42;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_10;}
			else if ((ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_15;}
			else {t->kind = 42; break;}
		case 14:
			case_14:
			if ((ch >= L' ' && ch <= L'~')) {AddCh(); goto case_12;}
			else {goto case_0;}
		case 15:
			case_15:
			recEnd = pos; recKind = 42;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_10;}
			else if ((ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_15;}
			else if (ch == L'=') {AddCh(); goto case_11;}
			else {t->kind = 42; break;}
		case 16:
			{t->kind = 17; break;}
		case 17:
			{t->kind = 20; break;}
		case 18:
			{t->kind = 21; break;}
		case 19:
			case_19:
			{t->kind = 22; break;}
		case 20:
			{t->kind = 25; break;}
		case 21:
			case_21:
			{t->kind = 26; break;}
		case 22:
			case_22:
			{t->kind = 27; break;}
		case 23:
			{t->kind = 28; break;}
		case 24:
			{t->kind = 31; break;}
		case 25:
			{t->kind = 32; break;}
		case 26:
			{t->kind = 33; break;}
		case 27:
			{t->kind = 34; break;}
		case 28:
			{t->kind = 35; break;}
		case 29:
			case_29:
			{t->kind = 39; break;}
		case 30:
			case_30:
			{t->kind = 40; break;}
		case 31:
			recEnd = pos; recKind = 18;
			if (ch == L'.') {AddCh(); goto case_19;}
			else if (ch == L'>') {AddCh(); goto case_22;}
			else if (ch == L')') {AddCh(); goto case_30;}
			else {t->kind = 18; break;}
		case 32:
			recEnd = pos; recKind = 24;
			if (ch == L'.') {AddCh(); goto case_21;}
			else {t->kind = 24; break;}
		case 33:
			recEnd = pos; recKind = 30;
			if (ch == L'.') {AddCh(); goto case_29;}
			else {t->kind = 30; break;}

	}
	AppendVal(t);
	return t;
}
Beispiel #22
0
Token* Scanner::NextToken() {
	while (ch == ' ' ||
			ch == 13
	) NextCh();
	if ((ch == L'/' && Comment0())) return NextToken();
	int recKind = noSym;
	int recEnd = pos;
	t = CreateToken();
	t->pos = pos; t->col = col; t->line = line; t->charPos = charPos;
	int state = start.state(ch);
	tlen = 0; AddCh();

	switch (state) {
		case -1: { t->kind = eofSym; break; } // NextCh already done
		case 0: {
			case_0:
			if (recKind != noSym) {
				tlen = recEnd - t->pos;
				SetScannerBehindT();
			}
			t->kind = recKind; break;
		} // NextCh already done
		case 1:
			case_1:
			recEnd = pos; recKind = 1;
			if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;}
			else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;}
		case 2:
			case_2:
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_3;}
			else {goto case_0;}
		case 3:
			case_3:
			recEnd = pos; recKind = 3;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_3;}
			else {t->kind = 3; break;}
		case 4:
			case_4:
			if (ch == L' ' || (ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_4;}
			else if (ch == L'"') {AddCh(); goto case_5;}
			else {goto case_0;}
		case 5:
			case_5:
			{t->kind = 4; break;}
		case 6:
			if ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_7;}
			else {goto case_0;}
		case 7:
			case_7:
			if (ch == 39) {AddCh(); goto case_8;}
			else {goto case_0;}
		case 8:
			case_8:
			{t->kind = 5; break;}
		case 9:
			{t->kind = 6; break;}
		case 10:
			case_10:
			if (ch == L'e') {AddCh(); goto case_11;}
			else {goto case_0;}
		case 11:
			case_11:
			if (ch == L'l') {AddCh(); goto case_12;}
			else {goto case_0;}
		case 12:
			case_12:
			if (ch == L'o') {AddCh(); goto case_13;}
			else {goto case_0;}
		case 13:
			case_13:
			if (ch == L'c') {AddCh(); goto case_14;}
			else {goto case_0;}
		case 14:
			case_14:
			if (ch == L'i') {AddCh(); goto case_15;}
			else {goto case_0;}
		case 15:
			case_15:
			if (ch == L'd') {AddCh(); goto case_16;}
			else {goto case_0;}
		case 16:
			case_16:
			if (ch == L'a') {AddCh(); goto case_17;}
			else {goto case_0;}
		case 17:
			case_17:
			if (ch == L'd') {AddCh(); goto case_26;}
			else {goto case_0;}
		case 18:
			case_18:
			if (ch == L'i') {AddCh(); goto case_19;}
			else {goto case_0;}
		case 19:
			case_19:
			if (ch == L'r') {AddCh(); goto case_20;}
			else {goto case_0;}
		case 20:
			case_20:
			if (ch == L'e') {AddCh(); goto case_21;}
			else {goto case_0;}
		case 21:
			case_21:
			if (ch == L'c') {AddCh(); goto case_22;}
			else {goto case_0;}
		case 22:
			case_22:
			if (ch == L'c') {AddCh(); goto case_23;}
			else {goto case_0;}
		case 23:
			case_23:
			if (ch == L'i') {AddCh(); goto case_24;}
			else {goto case_0;}
		case 24:
			case_24:
			if (ch == L'o') {AddCh(); goto case_25;}
			else {goto case_0;}
		case 25:
			case_25:
			if (ch == L'n') {AddCh(); goto case_26;}
			else {goto case_0;}
		case 26:
			case_26:
			{t->kind = 7; break;}
		case 27:
			case_27:
			if (ch == L'e') {AddCh(); goto case_28;}
			else {goto case_0;}
		case 28:
			case_28:
			if (ch == L'c') {AddCh(); goto case_29;}
			else {goto case_0;}
		case 29:
			case_29:
			if (ch == L't') {AddCh(); goto case_30;}
			else {goto case_0;}
		case 30:
			case_30:
			if (ch == L'u') {AddCh(); goto case_31;}
			else {goto case_0;}
		case 31:
			case_31:
			if (ch == L'r') {AddCh(); goto case_32;}
			else {goto case_0;}
		case 32:
			case_32:
			if (ch == L'a') {AddCh(); goto case_33;}
			else {goto case_0;}
		case 33:
			case_33:
			{t->kind = 8; break;}
		case 34:
			case_34:
			if (ch == L'c') {AddCh(); goto case_35;}
			else {goto case_0;}
		case 35:
			case_35:
			if (ch == L'e') {AddCh(); goto case_36;}
			else {goto case_0;}
		case 36:
			case_36:
			if (ch == L'n') {AddCh(); goto case_37;}
			else {goto case_0;}
		case 37:
			case_37:
			if (ch == L'd') {AddCh(); goto case_38;}
			else {goto case_0;}
		case 38:
			case_38:
			if (ch == L'i') {AddCh(); goto case_39;}
			else {goto case_0;}
		case 39:
			case_39:
			if (ch == L'd') {AddCh(); goto case_40;}
			else {goto case_0;}
		case 40:
			case_40:
			if (ch == L'o') {AddCh(); goto case_41;}
			else {goto case_0;}
		case 41:
			case_41:
			{t->kind = 9; break;}
		case 42:
			case_42:
			if (ch == L'm') {AddCh(); goto case_43;}
			else {goto case_0;}
		case 43:
			case_43:
			if (ch == L'p') {AddCh(); goto case_44;}
			else {goto case_0;}
		case 44:
			case_44:
			if (ch == L'r') {AddCh(); goto case_45;}
			else {goto case_0;}
		case 45:
			case_45:
			if (ch == L'i') {AddCh(); goto case_46;}
			else {goto case_0;}
		case 46:
			case_46:
			if (ch == L'm') {AddCh(); goto case_47;}
			else {goto case_0;}
		case 47:
			case_47:
			if (ch == L'e') {AddCh(); goto case_48;}
			else {goto case_0;}
		case 48:
			case_48:
			{t->kind = 10; break;}
		case 49:
			case_49:
			if (ch == L'n') {AddCh(); goto case_50;}
			else {goto case_0;}
		case 50:
			case_50:
			if (ch == L'g') {AddCh(); goto case_51;}
			else {goto case_0;}
		case 51:
			case_51:
			if (ch == L'u') {AddCh(); goto case_52;}
			else {goto case_0;}
		case 52:
			case_52:
			if (ch == L'l') {AddCh(); goto case_53;}
			else {goto case_0;}
		case 53:
			case_53:
			if (ch == L'o') {AddCh(); goto case_54;}
			else {goto case_0;}
		case 54:
			case_54:
			{t->kind = 11; break;}
		case 55:
			case_55:
			if (ch == L't') {AddCh(); goto case_56;}
			else {goto case_0;}
		case 56:
			case_56:
			if (ch == L'a') {AddCh(); goto case_57;}
			else {goto case_0;}
		case 57:
			case_57:
			if (ch == L'd') {AddCh(); goto case_58;}
			else {goto case_0;}
		case 58:
			case_58:
			if (ch == L'o') {AddCh(); goto case_59;}
			else {goto case_0;}
		case 59:
			case_59:
			{t->kind = 12; break;}
		case 60:
			case_60:
			recEnd = pos; recKind = 13;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_60;}
			else {t->kind = 13; break;}
		case 61:
			case_61:
			recEnd = pos; recKind = 2;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_61;}
			else if (ch == L'.') {AddCh(); goto case_2;}
			else {t->kind = 2; break;}
		case 62:
			if (ch == L'v') {AddCh(); goto case_10;}
			else if (ch == L'd') {AddCh(); goto case_18;}
			else if (ch == L'l') {AddCh(); goto case_27;}
			else if (ch == L'e') {AddCh(); goto case_63;}
			else if (ch == L'i') {AddCh(); goto case_42;}
			else if (ch == L'a') {AddCh(); goto case_49;}
			else {goto case_0;}
		case 63:
			case_63:
			if (ch == L'n') {AddCh(); goto case_34;}
			else if (ch == L's') {AddCh(); goto case_55;}
			else {goto case_0;}
		case 64:
			if (ch == L'O') {AddCh(); goto case_65;}
			else {goto case_0;}
		case 65:
			case_65:
			if (ch == L'N') {AddCh(); goto case_66;}
			else {goto case_0;}
		case 66:
			case_66:
			if (ch == L'F') {AddCh(); goto case_67;}
			else {goto case_0;}
		case 67:
			case_67:
			if (ch == L'I') {AddCh(); goto case_68;}
			else {goto case_0;}
		case 68:
			case_68:
			if (ch == L'G') {AddCh(); goto case_69;}
			else {goto case_0;}
		case 69:
			case_69:
			{t->kind = 14; break;}
		case 70:
			{t->kind = 15; break;}
		case 71:
			{t->kind = 16; break;}
		case 72:
			case_72:
			{t->kind = 17; break;}
		case 73:
			if (ch == L'U') {AddCh(); goto case_74;}
			else {goto case_0;}
		case 74:
			case_74:
			if (ch == L'N') {AddCh(); goto case_75;}
			else {goto case_0;}
		case 75:
			case_75:
			if (ch == L'C') {AddCh(); goto case_76;}
			else {goto case_0;}
		case 76:
			case_76:
			if (ch == L'I') {AddCh(); goto case_77;}
			else {goto case_0;}
		case 77:
			case_77:
			if (ch == L'O') {AddCh(); goto case_78;}
			else {goto case_0;}
		case 78:
			case_78:
			if (ch == L'N') {AddCh(); goto case_79;}
			else {goto case_0;}
		case 79:
			case_79:
			if (ch == L'E') {AddCh(); goto case_80;}
			else {goto case_0;}
		case 80:
			case_80:
			if (ch == L'S') {AddCh(); goto case_81;}
			else {goto case_0;}
		case 81:
			case_81:
			{t->kind = 18; break;}
		case 82:
			if (ch == L'R') {AddCh(); goto case_83;}
			else {goto case_0;}
		case 83:
			case_83:
			if (ch == L'O') {AddCh(); goto case_84;}
			else {goto case_0;}
		case 84:
			case_84:
			if (ch == L'G') {AddCh(); goto case_85;}
			else {goto case_0;}
		case 85:
			case_85:
			if (ch == L'R') {AddCh(); goto case_86;}
			else {goto case_0;}
		case 86:
			case_86:
			if (ch == L'A') {AddCh(); goto case_87;}
			else {goto case_0;}
		case 87:
			case_87:
			if (ch == L'M') {AddCh(); goto case_88;}
			else {goto case_0;}
		case 88:
			case_88:
			if (ch == L'A') {AddCh(); goto case_89;}
			else {goto case_0;}
		case 89:
			case_89:
			{t->kind = 19; break;}
		case 90:
			{t->kind = 26; break;}
		case 91:
			{t->kind = 34; break;}
		case 92:
			{t->kind = 35; break;}
		case 93:
			case_93:
			{t->kind = 36; break;}
		case 94:
			{t->kind = 37; break;}
		case 95:
			case_95:
			{t->kind = 49; break;}
		case 96:
			case_96:
			{t->kind = 52; break;}
		case 97:
			case_97:
			{t->kind = 53; break;}
		case 98:
			if (ch == L'=') {AddCh(); goto case_99;}
			else {goto case_0;}
		case 99:
			case_99:
			{t->kind = 54; break;}
		case 100:
			{t->kind = 55; break;}
		case 101:
			{t->kind = 56; break;}
		case 102:
			{t->kind = 57; break;}
		case 103:
			{t->kind = 58; break;}
		case 104:
			{t->kind = 59; break;}
		case 105:
			{t->kind = 60; break;}
		case 106:
			if (ch == L'A') {AddCh(); goto case_109;}
			else {goto case_0;}
		case 107:
			recEnd = pos; recKind = 51;
			if (ch == L'-') {AddCh(); goto case_95;}
			else if (ch == L'=') {AddCh(); goto case_96;}
			else {t->kind = 51; break;}
		case 108:
			recEnd = pos; recKind = 50;
			if (ch == L'=') {AddCh(); goto case_97;}
			else {t->kind = 50; break;}
		case 109:
			case_109:
			if (ch == L'R') {AddCh(); goto case_110;}
			else {goto case_0;}
		case 110:
			case_110:
			if (ch == L'G') {AddCh(); goto case_72;}
			else if (ch == L'F') {AddCh(); goto case_93;}
			else {goto case_0;}

	}
	AppendVal(t);
	return t;
}
Beispiel #23
0
Token* Scanner::NextToken() {
	while (ch == ' ' ||
			ch == 10 || ch == 13
	) NextCh();

	int recKind = noSym;
	int recEnd = pos;
	t = CreateToken();
	t->pos = pos; t->col = col; t->line = line;
	int state = start.state(ch);
	tlen = 0; AddCh();

	switch (state) {
		case -1: { t->kind = eofSym; break; } // NextCh already done
		case 0: {
			case_0:
			if (recKind != noSym) {
				tlen = recEnd - t->pos;
				SetScannerBehindT();
			}
			t->kind = recKind; break;
		} // NextCh already done
		case 1:
			case_1:
			if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;}
			else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;}
		case 2:
			case_2:
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;}
			else {t->kind = 2; break;}
		case 3:
			case_3:
			if (ch == L'e') {AddCh(); goto case_4;}
			else {t->kind = noSym; break;}
		case 4:
			case_4:
			if (ch == L'x') {AddCh(); goto case_5;}
			else {t->kind = noSym; break;}
		case 5:
			case_5:
			if (ch == L';') {AddCh(); goto case_6;}
			else {t->kind = noSym; break;}
		case 6:
			case_6:
			{t->kind = 4; break;}
		case 7:
			case_7:
			if (ch == L'c') {AddCh(); goto case_8;}
			else {t->kind = noSym; break;}
		case 8:
			case_8:
			if (ch == L't') {AddCh(); goto case_9;}
			else {t->kind = noSym; break;}
		case 9:
			case_9:
			if (ch == L';') {AddCh(); goto case_10;}
			else {t->kind = noSym; break;}
		case 10:
			case_10:
			{t->kind = 5; break;}
		case 11:
			{t->kind = 6; break;}
		case 12:
			case_12:
			{t->kind = 7; break;}
		case 13:
			{t->kind = 9; break;}
		case 14:
			{t->kind = 10; break;}
		case 15:
			{t->kind = 11; break;}
		case 16:
			{t->kind = 13; break;}
		case 17:
			{t->kind = 14; break;}
		case 18:
			{t->kind = 15; break;}
		case 19:
			if (ch == L'h') {AddCh(); goto case_3;}
			else if (ch == L'o') {AddCh(); goto case_7;}
			else if (ch == L'=') {AddCh(); goto case_12;}
			else {t->kind = noSym; break;}

	}
	AppendVal(t);
	return t;
}
Beispiel #24
0
void Errors::SynErr(int line, int col, int n) {
    wchar_t* s;
    switch (n) {
    case 0:
        s = coco_string_create(L"EOF expected");
        break;
    case 1:
        s = coco_string_create(L"ident expected");
        break;
    case 2:
        s = coco_string_create(L"number expected");
        break;
    case 3:
        s = coco_string_create(L"\"+\" expected");
        break;
    case 4:
        s = coco_string_create(L"\"-\" expected");
        break;
    case 5:
        s = coco_string_create(L"\"true\" expected");
        break;
    case 6:
        s = coco_string_create(L"\"false\" expected");
        break;
    case 7:
        s = coco_string_create(L"\"*\" expected");
        break;
    case 8:
        s = coco_string_create(L"\"/\" expected");
        break;
    case 9:
        s = coco_string_create(L"\"void\" expected");
        break;
    case 10:
        s = coco_string_create(L"\"(\" expected");
        break;
    case 11:
        s = coco_string_create(L"\")\" expected");
        break;
    case 12:
        s = coco_string_create(L"\"{\" expected");
        break;
    case 13:
        s = coco_string_create(L"\"}\" expected");
        break;
    case 14:
        s = coco_string_create(L"\"==\" expected");
        break;
    case 15:
        s = coco_string_create(L"\"<\" expected");
        break;
    case 16:
        s = coco_string_create(L"\">\" expected");
        break;
    case 17:
        s = coco_string_create(L"\"=\" expected");
        break;
    case 18:
        s = coco_string_create(L"\";\" expected");
        break;
    case 19:
        s = coco_string_create(L"\"?\" expected");
        break;
    case 20:
        s = coco_string_create(L"\":\" expected");
        break;
    case 21:
        s = coco_string_create(L"\"if\" expected");
        break;
    case 22:
        s = coco_string_create(L"\"else\" expected");
        break;
    case 23:
        s = coco_string_create(L"\"while\" expected");
        break;
    case 24:
        s = coco_string_create(L"\"for\" expected");
        break;
    case 25:
        s = coco_string_create(L"\"read\" expected");
        break;
    case 26:
        s = coco_string_create(L"\"write\" expected");
        break;
    case 27:
        s = coco_string_create(L"\"program\" expected");
        break;
    case 28:
        s = coco_string_create(L"\"int\" expected");
        break;
    case 29:
        s = coco_string_create(L"\"bool\" expected");
        break;
    case 30:
        s = coco_string_create(L"\",\" expected");
        break;
    case 31:
        s = coco_string_create(L"??? expected");
        break;
    case 32:
        s = coco_string_create(L"invalid AddOp");
        break;
    case 33:
        s = coco_string_create(L"invalid RelOp");
        break;
    case 34:
        s = coco_string_create(L"invalid Factor");
        break;
    case 35:
        s = coco_string_create(L"invalid MulOp");
        break;
    case 36:
        s = coco_string_create(L"invalid Stat");
        break;
    case 37:
        s = coco_string_create(L"invalid Stat");
        break;
    case 38:
        s = coco_string_create(L"invalid Type");
        break;

    default:
    {
        wchar_t format[20];
        coco_swprintf(format, 20, L"error %d", n);
        s = coco_string_create(format);
    }
    break;
    }
    wprintf(L"-- line %d col %d: %ls\n", line, col, s);
    coco_string_delete(s);
    count++;
}
Beispiel #25
0
TokenRef Scanner::NextToken() {
  while (ch == ' ' ||
			(ch >= 9 && ch <= 10) || ch == 13 || ch == ' '
  ) NextCh();
	if ((ch == '/' && Comment0()) || (ch == '/' && Comment1())) return NextToken();
  int recKind = noSym;
  size_t recEnd = pos;

  t = CreateToken();
  t->pos = pos; t->col = col; t->line = line; t->charPos = charPos;
  int state = start.state(ch);
  tlen = 0; AddCh();

  switch (state) {
  case -1: { t->kind = eofSym; break; } // NextCh already done
  case 0: {
    case_0:
    if (recKind != noSym) {
      tlen = recEnd - t->pos;
      SetScannerBehindT();
    }

    t->kind = recKind; break;
  } // NextCh already done
		case 1:
			case_1:
			recEnd = pos; recKind = 1;
			if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) {AddCh(); goto case_1;}
			else {t->kind = 1; char *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;}
		case 2:
			case_2:
			if ((ch >= '0' && ch <= '9')) {AddCh(); goto case_3;}
			else {goto case_0;}
		case 3:
			case_3:
			recEnd = pos; recKind = 3;
			if ((ch >= '0' && ch <= '9')) {AddCh(); goto case_3;}
			else {t->kind = 3; break;}
		case 4:
			case_4:
			if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_5;}
			else {goto case_0;}
		case 5:
			case_5:
			if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_6;}
			else {goto case_0;}
		case 6:
			case_6:
			if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_7;}
			else {goto case_0;}
		case 7:
			case_7:
			if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_8;}
			else {goto case_0;}
		case 8:
			case_8:
			if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_9;}
			else {goto case_0;}
		case 9:
			case_9:
			recEnd = pos; recKind = 4;
			if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_10;}
			else {t->kind = 4; break;}
		case 10:
			case_10:
			if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_11;}
			else {goto case_0;}
		case 11:
			case_11:
			{t->kind = 4; break;}
		case 12:
			if ((ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) {AddCh(); goto case_13;}
			else {goto case_0;}
		case 13:
			case_13:
			recEnd = pos; recKind = 5;
			if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) {AddCh(); goto case_13;}
			else {t->kind = 5; break;}
		case 14:
			case_14:
			if (ch <= '!' || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 65535)) {AddCh(); goto case_14;}
			else if (ch == '"') {AddCh(); goto case_15;}
			else if (ch == 92) {AddCh(); goto case_17;}
			else {goto case_0;}
		case 15:
			case_15:
			{t->kind = 6; break;}
		case 16:
			case_16:
			recEnd = pos; recKind = 2;
			if ((ch >= '0' && ch <= '9')) {AddCh(); goto case_16;}
			else if (ch == '.') {AddCh(); goto case_2;}
			else {t->kind = 2; break;}
		case 17:
			case_17:
			if (ch <= '!' || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 65535)) {AddCh(); goto case_14;}
			else if (ch == 92) {AddCh(); goto case_17;}
			else if (ch == '"') {AddCh(); goto case_18;}
			else {goto case_0;}
		case 18:
			case_18:
			recEnd = pos; recKind = 6;
			if (ch <= '!' || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 65535)) {AddCh(); goto case_14;}
			else if (ch == '"') {AddCh(); goto case_15;}
			else if (ch == 92) {AddCh(); goto case_17;}
			else {t->kind = 6; break;}
		case 19:
			{t->kind = 11; break;}
		case 20:
			{t->kind = 12; break;}
		case 21:
			{t->kind = 15; break;}
		case 22:
			{t->kind = 16; break;}
		case 23:
			{t->kind = 20; break;}
		case 24:
			{t->kind = 31; break;}
		case 25:
			{t->kind = 32; break;}
		case 26:
			{t->kind = 36; break;}
		case 27:
			{t->kind = 43; break;}
		case 28:
			{t->kind = 45; break;}
		case 29:
			{t->kind = 47; break;}
		case 30:
			{t->kind = 90; break;}
		case 31:
			{t->kind = 91; break;}
		case 32:
			{t->kind = 93; break;}
		case 33:
			recEnd = pos; recKind = 49;
			if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_4;}
			else {t->kind = 49; break;}

  }
  AppendVal(t);

  return t;
}
Beispiel #26
0
int wmain(int argc, wchar_t *argv[]) {
#elif defined __GNUC__
int main(int argc, char *argv_[]) {
    wchar_t ** argv = new wchar_t*[argc];
    for (int i = 0; i < argc; ++i) {
        argv[i] = coco_string_create(argv_[i]);
    }
#else
#error unknown compiler!
#endif

    wprintf(L"CocoXml/R (Oct 11, 2008)\n");

    wchar_t *srcName = NULL, *nsName = NULL, *frameDir = NULL, *ddtString = NULL, *traceFileName = NULL;
    wchar_t *outDir = NULL;
    char *chTrFileName = NULL;

    for (int i = 1; i < argc; i++) {
        if (coco_string_equal(argv[i], L"-namespace") && i < argc - 1) nsName = coco_string_create(argv[++i]);
        else if (coco_string_equal(argv[i], L"-frames") && i < argc - 1) frameDir = coco_string_create(argv[++i]);
        else if (coco_string_equal(argv[i], L"-trace") && i < argc - 1) ddtString = coco_string_create(argv[++i]);
        else if (coco_string_equal(argv[i], L"-o") && i < argc - 1) outDir = coco_string_create_append(argv[++i], L"/");
        else srcName = coco_string_create(argv[i]);
    }

#if defined __GNUC__
    for (int i = 0; i < argc; ++i) {
        coco_string_delete(argv[i]);
    }
    delete [] argv; argv = NULL;
#endif

    if (argc > 0 && srcName != NULL) {
        int pos = coco_string_lastindexof(srcName, '/');
        if (pos < 0) pos = coco_string_lastindexof(srcName, '\\');
        wchar_t* file = coco_string_create(srcName);
        wchar_t* srcDir = coco_string_create(srcName, 0, pos+1);

        CocoXml::Scanner *scanner = new CocoXml::Scanner(file);
        CocoXml::Parser  *parser  = new CocoXml::Parser(scanner);

        traceFileName = coco_string_create_append(srcDir, L"trace.txt");
        chTrFileName = coco_string_create_char(traceFileName);

        if ((parser->trace = fopen(chTrFileName, "w")) == NULL) {
            wprintf(L"-- could not open %ls\n", chTrFileName);
            exit(1);
        }

        parser->tab  = new CocoXml::Tab(parser);
        parser->xsdata  = new CocoXml::XmlScannerData(parser);
        parser->pgen = new CocoXml::ParserGen(parser);

        parser->tab->srcName  = coco_string_create(srcName);
        parser->tab->srcDir   = coco_string_create(srcDir);
        parser->tab->nsName   = coco_string_create(nsName);
        parser->tab->frameDir = coco_string_create(frameDir);
        parser->tab->outDir   = coco_string_create(outDir != NULL ? outDir : srcDir);

        if (ddtString != NULL) parser->tab->SetDDT(ddtString);

        parser->Parse();

        fclose(parser->trace);

        // obtain the FileSize
        parser->trace = fopen(chTrFileName, "r");
        fseek(parser->trace, 0, SEEK_END);
        long fileSize = ftell(parser->trace);
        fclose(parser->trace);
        if (fileSize == 0)
            remove(chTrFileName);
        else
            wprintf(L"trace output is in %ls\n", chTrFileName);

        wprintf(L"%d errors detected\n", parser->errors->count);
        if (parser->errors->count != 0) {
            exit(1);
        }

        delete parser->pgen;
        delete parser->xsdata;
        delete parser->tab;
        delete parser;
        delete scanner;
        coco_string_delete(file);
        coco_string_delete(srcDir);
    } else {
        wprintf(L"Usage: CocoXml Grammar.ATG {Option}\n");
        wprintf(L"Options:\n");
        wprintf(L"  -namespace <namespaceName>\n");
        wprintf(L"  -frames    <frameFilesDirectory>\n");
        wprintf(L"  -trace     <traceString>\n");
        wprintf(L"  -o         <outputDirectory>\n");
        wprintf(L"Valid characters in the trace string:\n");
        wprintf(L"  A  trace automaton\n");
        wprintf(L"  F  list first/follow sets\n");
        wprintf(L"  G  print syntax graph\n");
        wprintf(L"  I  trace computation of first sets\n");
        wprintf(L"  J  list ANY and SYNC sets\n");
        wprintf(L"  P  print statistics\n");
        wprintf(L"  S  list symbol table\n");
        wprintf(L"  X  list cross reference table\n");
        wprintf(L"XmlScanner.frame and XmlParser.frame files needed in ATG directory\n");
        wprintf(L"or in a directory specified in the -frames option.\n");
    }

    coco_string_delete(srcName);
    coco_string_delete(nsName);
    coco_string_delete(frameDir);
    coco_string_delete(ddtString);
    coco_string_delete(chTrFileName);
    coco_string_delete(traceFileName);

    return 0;
}
Token* Scanner::NextToken() {
	while (ch == ' ' ||
			(ch >= 9 && ch <= 10) || ch == 13
	) NextCh();
	if ((ch == L'(' && Comment0())) return NextToken();
	int recKind = noSym;
	int recEnd = pos;
	t = CreateToken();
	t->pos = pos; t->col = col; t->line = line; t->charPos = charPos;
	int state = start.state(ch);
	tlen = 0; AddCh();

	switch (state) {
		case -1: { t->kind = eofSym; break; } // NextCh already done
		case 0: {
			case_0:
			if (recKind != noSym) {
				tlen = recEnd - t->pos;
				SetScannerBehindT();
			}
			t->kind = recKind; break;
		} // NextCh already done
		case 1:
			case_1:
			recEnd = pos; recKind = 1;
			if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;}
			else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;}
		case 2:
			case_2:
			{t->kind = 2; break;}
		case 3:
			case_3:
			{t->kind = 3; break;}
		case 4:
			case_4:
			{t->kind = 4; break;}
		case 5:
			case_5:
			recEnd = pos; recKind = 5;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_5;}
			else if ((ch >= L'D' && ch <= L'E')) {AddCh(); goto case_6;}
			else {t->kind = 5; break;}
		case 6:
			case_6:
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_8;}
			else if (ch == L'+' || ch == L'-') {AddCh(); goto case_7;}
			else {goto case_0;}
		case 7:
			case_7:
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_8;}
			else {goto case_0;}
		case 8:
			case_8:
			recEnd = pos; recKind = 5;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_8;}
			else {t->kind = 5; break;}
		case 9:
			case_9:
			{t->kind = 6; break;}
		case 10:
			case_10:
			recEnd = pos; recKind = 4;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_10;}
			else if ((ch >= L'A' && ch <= L'F')) {AddCh(); goto case_13;}
			else if (ch == L'H') {AddCh(); goto case_4;}
			else if (ch == L'.') {AddCh(); goto case_5;}
			else if (ch == L'X') {AddCh(); goto case_9;}
			else {t->kind = 4; break;}
		case 11:
			case_11:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;}
			else if (ch == 92) {AddCh(); goto case_14;}
			else if (ch == L'"') {AddCh(); goto case_3;}
			else {goto case_0;}
		case 12:
			case_12:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;}
			else if (ch == 92) {AddCh(); goto case_15;}
			else if (ch == 39) {AddCh(); goto case_3;}
			else {goto case_0;}
		case 13:
			case_13:
			if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_13;}
			else if (ch == L'H') {AddCh(); goto case_4;}
			else if (ch == L'X') {AddCh(); goto case_9;}
			else {goto case_0;}
		case 14:
			case_14:
			if ((ch >= 1 && ch <= 9) || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= L't') || (ch >= L'v' && ch <= L'~')) {AddCh(); goto case_11;}
			else if (ch == L'u') {AddCh(); goto case_16;}
			else {goto case_0;}
		case 15:
			case_15:
			if ((ch >= 1 && ch <= 9) || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= L't') || (ch >= L'v' && ch <= L'~')) {AddCh(); goto case_12;}
			else if (ch == L'u') {AddCh(); goto case_17;}
			else {goto case_0;}
		case 16:
			case_16:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;}
			else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_18;}
			else if (ch == 92) {AddCh(); goto case_14;}
			else if (ch == L'"') {AddCh(); goto case_3;}
			else {goto case_0;}
		case 17:
			case_17:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;}
			else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_19;}
			else if (ch == 92) {AddCh(); goto case_15;}
			else if (ch == 39) {AddCh(); goto case_3;}
			else {goto case_0;}
		case 18:
			case_18:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;}
			else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_20;}
			else if (ch == 92) {AddCh(); goto case_14;}
			else if (ch == L'"') {AddCh(); goto case_3;}
			else {goto case_0;}
		case 19:
			case_19:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;}
			else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_21;}
			else if (ch == 92) {AddCh(); goto case_15;}
			else if (ch == 39) {AddCh(); goto case_3;}
			else {goto case_0;}
		case 20:
			case_20:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;}
			else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_22;}
			else if (ch == 92) {AddCh(); goto case_14;}
			else if (ch == L'"') {AddCh(); goto case_3;}
			else {goto case_0;}
		case 21:
			case_21:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;}
			else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_23;}
			else if (ch == 92) {AddCh(); goto case_15;}
			else if (ch == 39) {AddCh(); goto case_3;}
			else {goto case_0;}
		case 22:
			case_22:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;}
			else if (ch == 92) {AddCh(); goto case_14;}
			else if (ch == L'"') {AddCh(); goto case_3;}
			else {goto case_0;}
		case 23:
			case_23:
			if (ch == 10 || ch == 13) {AddCh(); goto case_2;}
			else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;}
			else if (ch == 92) {AddCh(); goto case_15;}
			else if (ch == 39) {AddCh(); goto case_3;}
			else {goto case_0;}
		case 24:
			{t->kind = 7; break;}
		case 25:
			{t->kind = 8; break;}
		case 26:
			case_26:
			{t->kind = 10; break;}
		case 27:
			case_27:
			{t->kind = 12; break;}
		case 28:
			{t->kind = 15; break;}
		case 29:
			{t->kind = 16; break;}
		case 30:
			{t->kind = 18; break;}
		case 31:
			{t->kind = 19; break;}
		case 32:
			{t->kind = 22; break;}
		case 33:
			case_33:
			{t->kind = 23; break;}
		case 34:
			{t->kind = 24; break;}
		case 35:
			{t->kind = 26; break;}
		case 36:
			{t->kind = 34; break;}
		case 37:
			{t->kind = 35; break;}
		case 38:
			{t->kind = 36; break;}
		case 39:
			case_39:
			{t->kind = 42; break;}
		case 40:
			{t->kind = 44; break;}
		case 41:
			{t->kind = 46; break;}
		case 42:
			{t->kind = 47; break;}
		case 43:
			{t->kind = 48; break;}
		case 44:
			{t->kind = 49; break;}
		case 45:
			{t->kind = 52; break;}
		case 46:
			recEnd = pos; recKind = 9;
			if (ch == L'=') {AddCh(); goto case_26;}
			else {t->kind = 9; break;}
		case 47:
			recEnd = pos; recKind = 11;
			if (ch == L'=') {AddCh(); goto case_27;}
			else {t->kind = 11; break;}
		case 48:
			recEnd = pos; recKind = 31;
			if (ch == L'=') {AddCh(); goto case_33;}
			else {t->kind = 31; break;}
		case 49:
			recEnd = pos; recKind = 45;
			if (ch == L'.') {AddCh(); goto case_39;}
			else {t->kind = 45; break;}

	}
	AppendVal(t);
	return t;
}
Beispiel #28
0
Comment::Comment(char* start, char* stop, bool nested) {
	this->start = coco_string_create(start);
	this->stop = coco_string_create(stop);
	this->nested = nested;
}
Beispiel #29
0
Token* Scanner::NextToken() {
	while (ch == ' ' ||
			(ch >= 9 && ch <= 10) || ch == 13
	) NextCh();

	int recKind = noSym;
	int recEnd = pos;
	t = CreateToken();
	t->pos = pos; t->col = col; t->line = line; t->charPos = charPos;
	int state = start.state(ch);
	tlen = 0; AddCh();

	switch (state) {
		case -1: { t->kind = eofSym; break; } // NextCh already done
		case 0: {
			case_0:
			if (recKind != noSym) {
				tlen = recEnd - t->pos;
				SetScannerBehindT();
			}
			t->kind = recKind; break;
		} // NextCh already done
		case 1:
			case_1:
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;}
			else {goto case_0;}
		case 2:
			case_2:
			recEnd = pos; recKind = 2;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;}
			else {t->kind = 2; break;}
		case 3:
			if ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_4;}
			else {goto case_0;}
		case 4:
			case_4:
			if ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_4;}
			else if (ch == L'"') {AddCh(); goto case_5;}
			else {goto case_0;}
		case 5:
			case_5:
			{t->kind = 3; break;}
		case 6:
			case_6:
			recEnd = pos; recKind = 4;
			if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_6;}
			else {t->kind = 4; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;}
		case 7:
			case_7:
			recEnd = pos; recKind = 1;
			if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_7;}
			else if (ch == L'.') {AddCh(); goto case_1;}
			else {t->kind = 1; break;}
		case 8:
			{t->kind = 6; break;}
		case 9:
			{t->kind = 7; break;}
		case 10:
			{t->kind = 9; break;}
		case 11:
			{t->kind = 10; break;}
		case 12:
			{t->kind = 11; break;}
		case 13:
			if (ch == L'.') {AddCh(); goto case_14;}
			else {goto case_0;}
		case 14:
			case_14:
			{t->kind = 12; break;}
		case 15:
			{t->kind = 13; break;}
		case 16:
			{t->kind = 17; break;}
		case 17:
			{t->kind = 18; break;}
		case 18:
			{t->kind = 22; break;}
		case 19:
			{t->kind = 23; break;}
		case 20:
			{t->kind = 31; break;}
		case 21:
			{t->kind = 33; break;}
		case 22:
			case_22:
			{t->kind = 53; break;}
		case 23:
			case_23:
			{t->kind = 54; break;}
		case 24:
			case_24:
			{t->kind = 55; break;}
		case 25:
			case_25:
			{t->kind = 56; break;}
		case 26:
			{t->kind = 61; break;}
		case 27:
			{t->kind = 62; break;}
		case 28:
			{t->kind = 63; break;}
		case 29:
			recEnd = pos; recKind = 26;
			if (ch == L'=') {AddCh(); goto case_22;}
			else {t->kind = 26; break;}
		case 30:
			recEnd = pos; recKind = 57;
			if (ch == L'>') {AddCh(); goto case_23;}
			else if (ch == L'=') {AddCh(); goto case_24;}
			else {t->kind = 57; break;}
		case 31:
			recEnd = pos; recKind = 58;
			if (ch == L'=') {AddCh(); goto case_25;}
			else {t->kind = 58; break;}

	}
	AppendVal(t);
	return t;
}
void Errors::SynErr(int line, int col, int n) {
	wchar_t* s;
	switch (n) {
			case 0: s = coco_string_create(L"EOF expected"); break;
			case 1: s = coco_string_create(L"ident expected"); break;
			case 2: s = coco_string_create(L"number expected"); break;
			case 3: s = coco_string_create(L"\":=\" expected"); break;
			case 4: s = coco_string_create(L"\";\" expected"); break;
			case 5: s = coco_string_create(L"\"display\" expected"); break;
			case 6: s = coco_string_create(L"\":hex;\" expected"); break;
			case 7: s = coco_string_create(L"\":oct;\" expected"); break;
			case 8: s = coco_string_create(L"\"halt\" expected"); break;
			case 9: s = coco_string_create(L"\"+\" expected"); break;
			case 10: s = coco_string_create(L"\"-\" expected"); break;
			case 11: s = coco_string_create(L"\"*\" expected"); break;
			case 12: s = coco_string_create(L"\"/\" expected"); break;
			case 13: s = coco_string_create(L"\"%\" expected"); break;
			case 14: s = coco_string_create(L"\"^\" expected"); break;
			case 15: s = coco_string_create(L"\"(\" expected"); break;
			case 16: s = coco_string_create(L"\")\" expected"); break;
			case 17: s = coco_string_create(L"??? expected"); break;
			case 18: s = coco_string_create(L"invalid Expon"); break;

		default:
		{
			wchar_t format[20];
			coco_swprintf(format, 20, L"error %d", n);
			s = coco_string_create(format);
		}
		break;
	}
	wprintf(L"-- line %d col %d: %ls\n", line, col, s);
	coco_string_delete(s);
	count++;
}