Esempio n. 1
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"\"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++;
}
Esempio n. 2
0
Object* SymbolTable::add(int l, int c, wchar_t* name, int kind, int type){
	Object* obj = new Object();
	Object* p = topScope->locals;
	Object* last = NULL;
	
//	wprintf(L"%ls\n", name);
	obj->name = name;
	obj->kind = kind;
	obj->type = type;
	obj->level = currentLevel;
	while(p != NULL){
		if(coco_string_equal(p->name, name)){
			wchar_t str[272];
			coco_swprintf(str, 272, L"%ls declared twice", name);
			putError(l, c, str);
		}
		last = p;
		p = p->next;
	}
	if(last == NULL)
		topScope->locals = obj;
	else
		last->next = obj;
	if(kind = var)
		obj->addr = topScope->nextAddr++;
	return obj;
}
Esempio n. 3
0
Object* SymbolTable::find(int l, int c, wchar_t* name){
	Object* obj;
	Object* scope = topScope;
	while(scope != NULL){
		obj = scope->locals;
		while(obj != NULL){
			if(coco_string_equal(obj->name, name))
				return obj;
			obj = obj->next;
		}
		scope = scope->next;
	}
	wchar_t str[272];
	coco_swprintf(str, 272, L"%ls is undeclared", name);
	putError(l, c, str);
	return undefObj;
}
Esempio n. 4
0
void ParserGen::GenErrorMsg (int errTyp, Symbol *sym) {
	errorNr++;
	const int formatLen = 1000;
	wchar_t format[formatLen];
	coco_swprintf(format, formatLen, L"\t\t\tcase %d: s = coco_string_create(L\"", errorNr);
	coco_string_merge(err, format);
	if (errTyp == tErr) {
		if (sym->name[0] == L'"') {
			coco_swprintf(format, formatLen, L"%ls expected", tab->Escape(sym->name));
			coco_string_merge(err, format);
		} else {
			coco_swprintf(format, formatLen, L"%ls expected", sym->name);
			coco_string_merge(err, format);
		}
	} else if (errTyp == altErr) {
		coco_swprintf(format, formatLen, L"invalid %ls", sym->name);
		coco_string_merge(err, format);
	} else if (errTyp == syncErr) {
		coco_swprintf(format, formatLen, L"this symbol not expected in %ls", sym->name);
		coco_string_merge(err, format);
	}
	coco_swprintf(format, formatLen, L"\"); break;\n");
	coco_string_merge(err, format);
}
Esempio n. 5
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++;
}