I tried this, but it doesn't work. I think it only needs to be corrected slightly. I think I am not using the priority of the symbols correctly in one line. help?
%{
#include<stdio.h>
#include<stdlib.h>
int nest = 0;
%}
%x COMMENT
%%
"/*" {BEGIN(COMMENT); ++nest;}
"//".*
<COMMENT>[^*)]* {}
<COMMENT>"(*" {++nest;}
<COMMENT>"*)" {if (--nest== 0) BEGIN(INITIAL);}
<COMMENT>[*)] {}
([^/]*([/][^(*])*)* {fprintf(yyout, yytext);}
%%
int main(int argc, char* argv[])
{
yyin = fopen("input.txt","r");
yyout = fopen("output.txt", "w");
yylex();
fclose(yyin);
fclose(yyout);
return 0;
}
And I also need to eliminate { ... } type of comments, if someone could help with this, much appreciation!
For example:
1.a.input: show (* commenting *)show
output: show show
b.input: show { commenting }show
output: show show
2.input: show \\ afqqe
output: show
3.a.input: show (* commenting .. comment..
comment....*) show
output: show show
b.input: show { commenting .. comment..
comment....} show
output: show show
4.a.input: show (* commenting {.. }comment..
comment....*) comment show
output: show comment show
b.input: show { commenting (* .. comment..
comment..*)..} show
output: show show