Reputation: 2484
I am trying to write a flex rule like this:
%%
[0-9]+ yylval=atoi(yytext); return NUMBER;
[<] return LANGLE;
[/>] return CLOSERANGLE;
[>] return RANGLE;
[/] return SLASH;
[ a-zA-Z0-9] yylval=strdup(yytext); return ANYTHING;
\n /* ignore end of line */;
[ \t]+ /* ignore whitespace */;
%%
When i run a flex program against the file, it says:
example4.l:19: warning, rule cannot be matched
example4.l:20: warning, rule cannot be matched
I guess this is because in the rule [/>]
it matches either /
or >
. But the question is how do i write that rule so that it matches /
and >
together?
I tried the documentation: It says that:
‘rs’
the regular expression ‘r’ followed by the regular expression ‘s’; called concatenation
Am I not doing the same? What's wrong? And how to cope with this?
Upvotes: 0
Views: 164
Reputation: 241671
I guess this is because in the rule [/>] it matches either / or > .
Exactly.
But the question is how do i write that rule so that it matches / and > together?
"/>"
Am I not doing the same?
No. [/]
matches / and [>]
matches >. So [/][>]
would work. But the quoted form is more normal.
Upvotes: 1