1. 用C或C++语言编写一个简单的词法分析程序,能够删除C/C++源程序中的所有注释,并输出处理后的结果。
例如,下面的C/C++源程序中的绿色部分都表示注释。#include<iostream>usingnamespacestd;voidmain(){//thisisasin...
例如,下面的C/C++源程序中的绿色部分都表示注释。
#include<iostream>
usingnamespace std;
void main()
{
//this is a single line comment
/*
this is amultiline comment
*/
cout<<"hello world"<<endl;
/*
this is amultiline comment
/*
this is amultiline comment
*/
cout<<"this is not a comment"<<endl;
*/
cout<<"/*this is not a comment*/"<<endl;
//*
cout<<"this is not a comment"<<endl;
*/
}
要求输出:
#include<iostream>
usingnamespace std;
void main()
{
cout<<"hello world"<<endl;
cout<<"this is not a comment"<<endl;
*/
cout<<"/*this is not a comment*/"<<endl;
cout<<"this is not a comment"<<endl;
*/
} 展开
#include<iostream>
usingnamespace std;
void main()
{
//this is a single line comment
/*
this is amultiline comment
*/
cout<<"hello world"<<endl;
/*
this is amultiline comment
/*
this is amultiline comment
*/
cout<<"this is not a comment"<<endl;
*/
cout<<"/*this is not a comment*/"<<endl;
//*
cout<<"this is not a comment"<<endl;
*/
}
要求输出:
#include<iostream>
usingnamespace std;
void main()
{
cout<<"hello world"<<endl;
cout<<"this is not a comment"<<endl;
*/
cout<<"/*this is not a comment*/"<<endl;
cout<<"this is not a comment"<<endl;
*/
} 展开
7个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询