Re: [Flex-help] Unsuccessfully trying to use {NAME}
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Chris v. <che...@gm...> - 2013-10-29 19:47:52
|
I think this is a superset of your later question about comments messing up named patterns, yes? -Chris On Sun, Oct 27, 2013 at 4:43 PM, Arthur Schwarz <asc...@at...>wrote: > Sorry to be a pest (well, not really). I'm trying to use a neat feature > that you have in flex, the ability to define a named regular expression in > the definitions section and use it in the rules. Alas, all is lost. I've > tried to follow the direction in Section 5.1 of the flex manual to no > success. The code below shows an example of what I'm trying to do. It seems > dead simple and I'm doing something dead wrong. > > >From Section 5.1 the expansion of {WHITESPACE} is "[ \a\b\f\r\t\v]" and > {TRUE} is "([tT][rR][uU][eE])". Using the named expressions don't work. > Substituting the regular expression is as a pattern the code works (except > for executing the statements associated with '\n'). > > > Could you explain what is wrong with the code so that I can use named > regular expressions? > > art > > %option main > > %{ > #include <stdio.h> > %} > > WHITESPACE [ \a\b\f\r\t\v] /* white space */ > TRUE [tT][rR][uU][eE] /* true */ > > %% > /* > * rule 1: flex complains "unrecognized rule" > * rule 2: flex complains "unrecognized rule" > * rule 3: No complaint and pattern is not recognized on input > * rule '[ \a\b\f\r\t\v]+' works > * rule '[tT][rR][uU][eE]' works > * rule '\n' no output but seems to work > * rule '.' works > */ > > /* rule 1 {WHITESPACE}+ { printf("%35s %s\n", > "{WHITESPACE}+", yytext); } */ > /* rule 2 {TRUE} { printf("%35s %s\n", > "{TRUE}", yytext); } */ > /* rule 3 [{TRUE}] { printf("%35s %s\n", > "{TRUE}", yytext); } */ > ([ \a\b\f\r\t\v]+) { printf("%35s %s\n", "[ > \\a\\b\\f\\r\\t\\v]+", yytext); } > ([tT][rR][uU][eE]) { printf("%35s %s\n", "[tT][rR][uU][eE]", > yytext); } > <<EOF>> { printf("%35s %s", "\n", "<<EOF>>" ); > return 1; } > \n { printf("%35s %s", "\n", "" ); } > . { printf("%35s %s\n", ".", yytext); } > > > ------------------------------------------------------------------------------ > October Webinars: Code for Performance > Free Intel webinars can help you accelerate application performance. > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most > from > the latest Intel processors and coprocessors. See abstracts and register > > http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk > _______________________________________________ > Flex-help mailing list > Fle...@li... > https://lists.sourceforge.net/lists/listinfo/flex-help > |