예제 #1
0
파일: CDECL.c 프로젝트: acros/CDECL
void getToken(){
	char* p = currToken.mStr;

	/* skip the blank */
	while ((*p = getchar()) == ' '){};

	if (isalnum(*p)){
		/* copy string until find the next blank */
		while(isalnum( *++p = getchar()));

		ungetc(*p,stdin);
		*p = '\0';
		currToken.mType = classify_string();
		return ; 
	}

	/* the 'type' descriptor is follow with the '*' */
	if(*p == '*'){
		strcpy(currToken.mStr,"pointer to");
		currToken.mType = *p;
		return;	
	}

	currToken.mStr[1] = '\0';
	currToken.mType = *p;
	return;
}
예제 #2
0
/*
	Read the next token into this.string
	if it is alphanumeric, classify_string
	else it must be a single character token
	this.type = the token itself; terminate this.string
	with a nul.
 */
void get_token() {
	char c = 'a';
	while((c = getchar()) != EOF) {
		if(isspace(c))  continue;
		else 			break;
	}

	if(c == EOF) {
		curr_token.type = END;
		return;
	}
	
	if(isalnum(c) || c == '_') {
		int i = 0;
		while(isalnum(c) || c == '_') {
			curr_token.string[i++] = c;
			c = getchar();
		}
		curr_token.string[i] = 0;
		ungetchar(c);

		curr_token.type = classify_string();
		return;
	}
	
	curr_token.type = c;
	if(c == '*') {
		strcpy(curr_token.string, "pointer to ");
	}
	else {
		curr_token.string[0] = c;
		curr_token.string[1] = 0;
	}
}
예제 #3
0
파일: L075_1.C 프로젝트: turmary/smalls
void gettoken(void){
	/* 读入下一个标记,保存在"cur"中 */
	char *p = cur.string;

	/* 略过所有空白符 */
	while((*p = getchar()) == ' ');

	if(isalnum(*p)){
		/* 在标识符中读入a-z, 0-9开头 */
		while(isalnum(*++p = getchar()));
		ungetc(*p, stdin);
		*p = '\0';
		cur.type = classify_string();
		return;
	}

	if(*p == '*'){
		strcpy(cur.string, "pointer to ");
		cur.type = '*';
		return;
	}
	cur.string[1] = '\0';
	cur.type = *p;
	return;
}