Reputation: 727
i've searched quite a lot and the best i created till now to match multiline c comments is:
\/\*(.|\n)*\*\/
but for a text like this:
1. Not a comment
2.
3.Ooops Not a comment /**** A multiline comment **/ Ooops Not a comment
4. Ooops Not a comment /**** A multiline comment **\/
5. ****** Ooops Not a comment
6. ***/
7.// A another comment
8.Another not a comment
9.
10. "/*Again not a comment*/"
11.// A line comment at the end of file
The outcome looks like this:
1. Not a comment
2.
3.Ooops Not a comment "
11.// A line comment at the end of file
Can someone explain my mistake and give me the correct one? thank you!
Full code: [spoiler]
%option noyywrap
%{
#include <stdio.h>
#include <stdlib.h>
FILE *fout;
%}
%%
\/\*(.|\n)*?\*\/
%%
void main( int argc, char ** argv)
{
if ( argc < 3 )
{
printf("\nError!!! Missing Command line arguments");
printf("\nUsage exe <inputfile> <outputfile>");
exit(1);
}
else
{
fout = fopen(argv[2],"w");
yyout = fout;
yyin = fopen(argv[1],"r");
yylex();
}
system("pause");
}
[/spoiler]
Upvotes: 0
Views: 646
Reputation: 3446
Try adding a ?
to make it non-greedy: \/\*(.|\n)*?\*\/
.
Matches:
/**** A multiline comment **/
/**** A multiline comment **\/ 5. ****** Ooops Not a comment 6. ***/
/*Again not a comment*/
If these matches are not correct please explain better what exactly should be matched.
Upvotes: 1