tags:

views:

66

answers:

1

In the following:

space           ([ \t\f\r])+         
opt_space       ([ \t\f\r])*         
cpp             ^{opt_space}#{opt_space} 
word            [A-Za-z_][A-Za-z_0-9]*
arg_macro       {cpp}define{space}{word}
/*arg_macro       ^{opt_space}#{opt_space}define{space}{word}*/

%%
{arg_macro}     ;
%%

I get an error message

test.l:9: unrecognized rule

If I uncomment the second version of arg_macro and comment the first one, the error message goes away.

Any ideas why?

+1  A: 

If you remove the ^ from the cpp definition, and place it in the arg_macro definition, then it's happy.

space           ([ \t\f\r])+
opt_space       ([ \t\f\r])*
cpp             {opt_space}#{opt_space}
word            [A-Za-z_][A-Za-z_0-9]*
arg_macro       ^{cpp}define{space}{word}
Simeon Pilgrim
OK, thanks; is there some kind of reason for that or did you find it by trial and error?
Kinopiko
I was playing around to find the actual problem sub-part. But I then went reading of the flex man page, etc. There is conflicting notes, on one page I read that you can only ^ at the beginning on the string are interpreted as line-start anchors, otherwise it's just the token. I assume that flex thinks it's invalid to nest a start of line token after the start of line, thus the definition with that anchor inside is not valid for other token expansion. This is based on the wording of the error, it implies the cpp definintion does not exists. Would have to read the code to know more.
Simeon Pilgrim
Ok, reading the gnu flex code: start line rules, seem to get placed in a different list from the other rules, and when resolving the named symbols, it looks up the second list.
Simeon Pilgrim
OK thanks, which section of the manual was that by the way?
Kinopiko
Some of it was at the end of this page: http://flex.sourceforge.net/manual/Patterns.html#Patterns
Simeon Pilgrim
Thanks, that is helpful for me. It seems like a weakness of flex. Thanks again.
Kinopiko