0
votes

I am writing a lex program. The objective of this problem is that I enter a string (letters and other characters) and it returns the length of this string.

Here is the code:

letter ([a-z]|[A-Z])
carac (•|¤|¶|§|à|î|ì|Ä|Å|É|æ|Æ|ô|ö|ò|û|ù|ÿ|Ö|Ü|ø|£|Ø|×|ƒ|á|í|ó|ú|ñ|Ñ|ª|º|¿|®|¬|½|¼|¡|:|;|.|,|/|?|=|-|!|*|£|µ|^|¨|%)
String {letter}({letter}|{carac})*
%%
{String} printf("[%d] : The number of your String \n",yyleng);
.* printf("You have a problem somewhere !"); 
%%
int yywrap(){return 1;}
main ()
{
    yylex ();
}

And the output:

enter image description here

1
It is likely that Flex doesn't understand the character encoding of your input file. As far as I know, Flex still only understands single-byte characters. - Thomas Padron-McCarthy
To amplify Thomas's comment: try a simpler version of the program, where you define carac as carac (:|;|.|,|/|?|=|-|!|^|%). - David Gorsline
@DavidGorsline Still don't work the some problem - YasBES
You may need to quote special characters: carac (\:|\;|\.|\,|\/|\?|\=|\-|\!|\^|\%) Or use the character class notation: carac [-:;.,/?=!^%] - Thomas Padron-McCarthy

1 Answers

0
votes

(The answers are contained in the comments, which I am including here. See Question with no answers, but issue solved in the comments (or extended in chat) ).

@Thomas Padron-McCarthy and @David Gorsline are correct:

  • It is likely that Flex doesn't understand the character encoding of your input file. As far as I know, Flex still only understands single-byte characters.

  • To amplify Thomas's comment: try a simpler version of the program, where you define carac as carac (:|;|.|,|/|?|=|-|!|^|%).

  • You may need to quote special characters: carac (\:|\;|\.|\,|\/|\?|\=|\-|\!|\^|\%) Or use the character class notation: carac [-:;.,/?=!^%]

To confirm this I applied these edits and ran it through flex. The following does not give flex errors:

carac (\•|\¤|\¶|\§|\à|\î|\ì|\Ä|\Å|\É|\æ|\Æ|\ô|\ö|\ò|\û|\ù|\ÿ|\Ö|\Ü|\ø|\£|\Ø|\×|\ƒ|\á|\í|\ó|\ú|\ñ|\Ñ|\ª|\º|\¿|\®|\¬|\½|\¼|\¡|\:|\;|\.|\,|\/|\?|\=|\-|\!|\*|\£|\µ|\^|\¨|\%)