Re: [Flex-help] match lines starting with "include" and others
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Chris v. <che...@gm...> - 2010-01-09 19:48:17
|
Maybe you could exploit the property that your interesting matches start with "^#"? /* match "#include" lines */ ^"#"[ \t]*include[ \t]*[<\"] {printf("begin IFILE\n");BEGIN IFILE;} /* match any "#" line that doesn't match the above */ ^# { printf("#"); BEGIN(NON_INCLUDE); } <NON_INCLUDE>.+ { printf("%s", yytext); } <NON_INCLUDE>\n { printf("\n"); BEGIN(INITIAL); } /* match the remaining non-"#" lines */ ^[^#].* { printf("%s", yytext); } [\n] { printf("\n"); } -Chris On Sat, Jan 9, 2010 at 10:33 AM, Michael Chen <van...@gm...>wrote: > I am trying to match with longer chunks, instead of one character by > one character. Is there a way? Thanks. > > Michael Chen > > On Sat, Jan 9, 2010 at 12:02 PM, Marcel Laverdet <ma...@la...> > wrote: > > > > > > Whoaaa, there is a severe misunderstanding of the way flex files work > > here. Flex will basically run through all your expressions and match the > > longest one. You should keep that first rule, throw away all the others, > > and then have another one that's like: > > > > .|\n printf("%c", *yytext); > > > > On Sat, 9 Jan 2010 09:20:03 -0600, Michael Chen > > <van...@gm...> wrote: > >> Dear there, > >> > >> I would like to process only the include statement lines, and simply > >> print out the other lines. My solution to match other lines seems > >> reasonable, but don't work. Would you give me a idea why? Thanks. > >> > >> Michael > >> > >> /* To match lines start with: #include <; or #include "; */ > >> ^"#"[ \t]*include[ \t]*[<\"] {printf("begin IFILE\n");BEGIN IFILE;} > >> > >> /* To math any other lines */ > >> ^[^"#"].*\n {fprintf(yyout,"[%4d] %s", yylineno, yytext);} > >> ^"#"[^i].*\n {fprintf(yyout,"[%4d] %s", yylineno, yytext);} > >> ^"#"i[^n].*\n {fprintf(yyout,"[%4d] %s", yylineno, yytext);} > >> ^"#"in[^c].*\n {fprintf(yyout,"[%4d] %s", yylineno, yytext);} > >> ^"#"inc[^l].*\n {fprintf(yyout,"[%4d] %s", yylineno, yytext);} > >> ^"#"incl[^u].*\n {fprintf(yyout,"[%4d] %s", yylineno, yytext);} > >> ^"#"inclu[^d].*\n {fprintf(yyout,"[%4d] %s", yylineno, yytext);} > >> ^"#"includ[^e].*\n {fprintf(yyout,"[%4d] %s", yylineno, yytext);} > >> ^"#"include[ \t]*[^<\"].*\n {fprintf(yyout,"[%4d] %s", yylineno, > >> yytext);} > > > > > > -- > Best regards, > Michael Chen > Google Voice Phone.: 847-448-0647 > > > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and > easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > Flex-help mailing list > Fle...@li... > https://lists.sourceforge.net/lists/listinfo/flex-help > |