Hello,
my fellows and me implement a c++ tool that is able to divide blank/tab
separated files into <number>, <text>, <c-singlelinecomme nt> and
<multilinecomme nt>. So far it's not working bad, we have just one
problem if I call the a.exe that gcc compiles with the following
textfile (./a.exe < test.txt) he does not match the multiline comments
correctly.
*test.txt contains:
123 456
hello
5674
/* hello hello hellp
something
more */
123
*output of a.exe < test.txt is:
Number
Number
Command
Number
hello hello hellp
something
more Comments
Number
That's bad the hellos should be suppressed, only "comments" should be
returned.
Any idea?
UWe
############### ############### #### fourth.l ##############
%{
#define NUMBER 400
#define COMMENT 401
#define TEXT 402
#define COMMAND 403
#define schlump 405
#define mlcomment 406
/* <COMMENTS>\n {return mlcomment; }
<COMMENTS>.\n {return mlcomment; }
<COMMENTS>"*/"[ \t]*\n { BEGIN 0; return mlcomment;}
<COMMENTS>"*/" { BEGIN 0; return mlcomment;}
*/
%}
%x COMMENTS
%%
[ \t]*"/*".*"*/"[ \t]*\n {return mlcomment; }
[ \t]*"/*" { BEGIN COMMENTS;}
<COMMENTS>.* "*/"[ \t]*\n { BEGIN 0; return mlcomment;}
<COMMENTS>.*" */" { BEGIN 0; return mlcomment;}
[+-]?(([0-9]+)|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?) {return NUMBER;}
(\/\/)+[^\n]* {return COMMENT;}
\"[^\"\n]*\" {return TEXT;}
[0-9]+[a-zA-Z]+ {return schlump;}
[a-zA-Z][a-zA-Z0-9]+ {return COMMAND;}
.. ;
..*\n ;
%%
#include <stdio.h>
int yywrap(){return 1;}
main (argc,argv)
int argc;
char *argv[];
{
int val;
//
while (val = yylex()) {
switch (val)
{
case 400 :
{printf ("Number\n");br eak;}
case 401 :
{printf ("Comment\n");b reak;}
case 402 :
{printf ("Text\n");brea k;}
case 403 :
{printf ("Command\n");b reak;}
case 405 :
{printf ("Schlumpf\n"); break;}
case 406 :
{printf ("Comments\n"); break;}
default :
printf("etwas anderes\n");
}
}
}