Exemplo n.º 1
0
/* 名前idの名前表の位置を返す (未宣言の時エラーとする) */
int searchT(char *id, KindT k)
{
	int i;
	i = tIndex;
	strcpy(nameTable[0].name, id);    /* 番兵をたてる */
	while( strcmp(id, nameTable[i].name) )
		i--;
	if ( i )                          /* 名前があった */
		return i;
	else {                            /* 名前がなかった */
		errorType("undef");
		if (k == varId)
			return enterTvar(id);     /* 変数の時は仮登録 */
		return 0;
	}
}
Exemplo n.º 2
0
Arquivo: table.c Projeto: Leulz/pl0d
int searchT(char *id, KindT k)		/* It returns the index of an element whose name is id. */
							/* It declares an error if it is undefined. */
{
	int i;
	i = tIndex;
	strcpy(nameTable[0].name, id);			/* It puts a sentinel at the beginning of the name table. */
	while( strcmp(id, nameTable[i].name) )
		i--;
	if ( i )							/* It finds the name. */
		return i;
	else {							/* It fails to find the name. */
		errorType("undef");
		if (k==varId) return enterTvar(id);	/* It records id in the name table if it is a variable. */
		return 0;
	}
}
Exemplo n.º 3
0
void varDecl()				/* 変数宣言のコンパイル */
{
	while(1){
		if (token.kind==Id){
			setIdKind(varId);		/* 印字のための情報のセット */
			enterTvar(token.u.id);		/* 変数名をテーブルに、番地はtableが決める */
			token = nextToken();
		}else
			errorMissingId();
		if (token.kind!=Comma){		/* 次がコンマなら変数宣言が続く */
			if (token.kind==Id){		/* 次が名前ならコンマを忘れたことにする */
				errorInsert(Comma);
				continue;
			}else
				break;
		}
		token = nextToken();
	}
	token = checkGet(token, Semicolon);		/* 最後は";"のはず */
}