コード例 #1
0
ファイル: scanner.c プロジェクト: lgarsten/vpcc
// consume input until next character is found. ignores whitespace, comments
// and preprocessor directives. return value of -1 indicates
// error condition (such as end of file) - treat as clean end of input
// condition even if it is an actual error. return value >0 indicates ASCII
// character code also stored in variable "character".
int findNextCharacter() {
	int inComment; // are we scanning a comment?
	inComment = 0;

	while (1) {
		if (inComment) {
			character = getchar();

			if (character == 10) // ASCII code 10 = linefeed
				inComment = 0;
			else if (character == 13) // ASCII code 13 = carriage return
				inComment = 0;
			else if (character == -1) // end of file is represented by -1
				return character;
		} else if (isCharacterWhitespace())
			character = getchar();
		else if (character == 35) { // ACCII code 35 = #
			character = getchar();

			inComment = 1;
		} else if (character == 47) { // ASCII code 47 = /
			character = getchar();

			if (character == 47) { // ASCII code 47 = /
				character = getchar();

				inComment = 1;
			} else
				return character;
		} else
			return character;
	}
}
コード例 #2
0
ファイル: scanner.c プロジェクト: tloch/vpcc
// consume input until next character is found. ignores whitespace, comments
// and preprocessor directives. return value of -1 indicates
// error condition (such as end of file) - treat as clean end of input
// condition even if it is an actual error. return value >0 indicates ASCII
// character code also stored in variable "character".
int findNextCharacter() {
	int inComment; // are we scanning a comment?
	inComment = 0;

	while (1) {
		if (inComment) {
			*character = scanner_getchar();

			if (*character == 10) // ASCII code 10 = linefeed
				inComment = 0;
			else if (*character == 13) // ASCII code 13 = carriage return
				inComment = 0;
			else if (*character == -1) // end of file is represented by -1
				return *character;
		} else if (isCharacterWhitespace())
			*character = scanner_getchar();
		else if (*character == 35) { // ACCII code 35 = #
			*character = scanner_getchar();

			inComment = 1;
		} else if (*character == 47) { // ASCII code 47 = /
			if(scanner_lookahead == 47) { // ASCII code 47 = /
				// current char and lookahead char are slashes: consume both and assume we are inside a comment block
				*character = scanner_getchar();
				*character = scanner_getchar();
				inComment = 1;
			} else
				return *character;
		} else
			return *character;
	}
}