Beispiel #1
0
void rcomment(int c) {
    int d;

    if (c=='/') {
        if ((d=getchar())=='*')
            in_comment();
        else if (d=='/')  {
            putchar(c);
            rcomment(d);
        } else {
            putchar(c);
            putchar(d);
        }
    } else if (c=='\'' || c=='"')
        echo_quote(c);
    else
        putchar(c);
}
Beispiel #2
0
/*rcomment: czytaj każdy znak, usuń komentarze*/
void rcomment(int c)
{
	int d;

	if (c == '/')
		if ((d = getchar()) == '*')
			in_comment();	/*początek komentarza*/
		else if (d == '/') {
			putchar(c);	/*drugi znak / */
			rcomment(d);
		} else {
			putchar(c);	/*to nie jest komentarz ;)*/	
			putchar(d);
		}
	else if (c == '\'' || c == '"')
		echo_quote(c);		/*to początek stałej*/
	else
		putchar(c);		/*to nie jest komentarz*/
}
Beispiel #3
0
/* rcomment: read each character, remove the comments */
void rcomment(int c)
{
    int d;

    if (c == '/')
        if ((d = getchar()) == '*')
            in_comment();           /* beginning comment */
        else if (d == '/') {        /* another slash */
            putchar(c);
            rcomment(d);
        } else {
            putchar(c);             /* not a comment */
            putchar(d);
        }
    else if (c == '\'' || c == '"')
        echo_quote(c);              /* quote begins */
    else
        putchar(c);                 /* not a comment */
}
Beispiel #4
0
/* 阅读每个字节,移除注释 */
void rcomment(int c)
{
    int d;

    if (c == '/')
        if ((d = getchar()) == '*')
            in_comment();       /* 开始注释 */
        else if (d == '/') {
            putchar(c);             /* 另一个斜杠 */
            rcomment(d);
        } else {
            putchar(c);             /* 不是注释 */
            putchar(d);
        }
    else if (c == '\'' || c == '"')     /* 引号中的内容原样输出 */
        echo_quote(c);      /* 引用开始 */
    else
        putchar(c);     /* 不是注释 */
}
Beispiel #5
0
/*rcomment:处理读入的每个字符,删除注释,首先是搜索起始标志*/
void rcomment(int c)
{
	int d;																	/*用来储存c后面读入的一个字符*/
	if(c=='/')															/*当遇到一个/时,需要进行后续的判断*/
	{
		if((d=getchar())=='*')								/*  再读入一个字符,如果是*号,d已经读入,后续不需读入,而且必须输出  */
			in_comment();												/*  说明进入注释,调用in_comment()函数寻找结束标志,删除注释 */
		else if (d=='/') 										 /*   如果又出现一个/   */
		{
			putchar(c); 										   /*则c一定不是属于注释,把c原样输出*/
			rcomment(d);											/*****递归调用rcomment函数,继续对d进行检测,而实际上只是c==‘/’的情况******/
		}
		else   														 /* 第一个/出现后,之后读入的一个字符,不是/也不是*    */
		{
			putchar(c);   /*c,d均不属于注释,c,d均原样输出*/
			putchar(d);	
		}
	}
	else if(c=='\''||c=='"') /*出现单引号或双引号*/
		echo_quote(c);/*调用echo_quote函数处理*/
	else /*其他情况表示即不是/也不是引号*/
		putchar(c);/*原样输出*/
}
Beispiel #6
0
int findclose(int c) {
	int d;

	while((d = getchar())!=EOF) {
		if(d == '{') {
			findclose('}');
		}
		else if(d == '[') {
			findclose(']');
		}
		else if(d == '(') {
			findclose(')');
		}
		else if(d == '/') {
			if ((d = getchar()) == '*')
				in_comment();
		}
		else if(d == '\'' || d == '"') {
			echo_quote(d);
		}
		else if(c == d) {
			return 0;
		}
		else if(d == '}' || d == ']' || d == ')') {
			printf("find %c, unexpected %c\nexit.\n", c, d);
			_exit(-1);
		}
	}

	if(c != 255) {
		printf("not match, %c\n", c);
		_exit(-1);
	}
	printf("ok\n");
	return 0;
}