You've defined id
incorrectly. Flex is looking for a character class named letter|digit
but can't find it. You need to factor your regular expression out of the {
}
pair.
id {letter}({letter}|{digit})*
Pergunta
Hi I am new to lex and have been trying to write a program to extract identifiers. But it shows error on line 9
{id} {printf("%s:IDENTIFIER",yytext);}
"unrecognized rule" Here is the code:
%{
#include<stdio.h>
%}
digit [0-9]
letter [a-zA-Z]
id {letter}{letter|digit}*
%%
{id} {printf("%s:IDENTIFIER",yytext);}
%%
int main()
{
yylex();
return 0;
}
I have seen other questions also but could find the error in this code.Please help.
Solução
You've defined id
incorrectly. Flex is looking for a character class named letter|digit
but can't find it. You need to factor your regular expression out of the {
}
pair.
id {letter}({letter}|{digit})*