Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flex/Lex unrecognized rule for paranthesis'

%{

%}

%%
'*'     {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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading