lex program to determine identifiers
lex program to determine valid identifiers.Users can enter an identifier and the program will display whether it is valid or not.
********************************************************************************
/*lex code to determine whether input is an identifier or not*/
%option noyywrap
%%
^[a-zA-Z_][a-zA-Z0-9_]* printf("Valid Identifier");
^[^a-zA-Z _] printf("Invalid Identifier");
.* printf("Invalid Indentifier");
%%
main()
{
yylex();
}
Execution
$ flex id3.lex
$ gcc lex.yy.c
$ ./a.out
2ghdd
Invalid Indentifier
46shs
Invalid Indentifier
dre45
Valid Identifier
dhd_dgd
Valid Identifier
_dghd
Valid Identifier
252
Invalid Indentifier
dgd$
Invalid Indentifier
_dhd
Valid Identifier
eye-hd
Invalid Indentifier
Comments
Post a Comment