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

Popular posts from this blog

KTU Compiler Lab CSL411 - Dr Binu V P

lexical analyzer for a c program

13.Precedence and conflict resolution in yacc