Reputation: 597
%{
%}
%%
'*' {return 0;}
'(' {return 1;}
')' {return 2;}
%%
int yywrap(){}
An example code like above. It gives the error message as:
zort.l:7: unrecognized rule
zort.l:8: unrecognized rule
zort.l:8: unrecognized rule
zort.l:8: unrecognized rule
It only gives the error for paranthesis characters. Doesn't give any error for other characters. What is the reason? Are paranthesis' exceptions? How to solve it?
Upvotes: 1
Views: 151
Reputation: 19615
For flex
patterns, single and double quotes are not the same. Currently, your first rule says that you want to match a single quote ('
), zero or more times (*
), followed by another single quote '
. The other rules don't have a meaning.
Assuming you want to instead match literal asterisks and parentheses, try double quotes instead:
%%
"*" {return 0;}
"(" {return 1;}
")" {return 2;}
%%
The manual has more information about what can be specified as a pattern (it's an extended form of regular expressions).
Upvotes: 1