lex program to eliminate single and multiline comments

 

 

 

%{
#include<stdio.h>
%}
%%
“//”([a-z]|[0-9]|[A-Z]|” “)*    {}
“/*”([a-z]|[0-9]|[A-Z]|” “\””\n”)+”*/”    {}
%%
main()
{
yylex();
return 0;
}
int yywrap()
{
}

Sample output

single line comment //testing
single line comment
test line /*multi*/
test line

Leave a Reply

Your email address will not be published. Required fields are marked *