Home » Compiler Design

LEX Code to identify and print valid Identifier of C/C++ in given Input pattern

In this article, we going to learn how to create LEX program to analysis whether a input is identifier or not?
Submitted by Ashish Varshney, on March 24, 2018

For achieve to this task we create some rules in rule section in the code.


    Input: var
    Output: Identifier
    Input: 123
    Output: Not a Identifier
/*Definition Section*/

/*Rule Section*/

/*put all words in a single line, which are broken in 4 lines*.

/*Check the token, if token is match with 
pattern then it will print identifier.*/
([a-zA-Z][0-9])+|[a-zA-Z]* {printf("Identifier\n");}   

^[0-9]+ {printf("Not a Identifier\n");}


/*call the yywrap function*/
int yywrap()					
return 1;

/*Auxiliary function*/
/*Driver function*/
int main(void)
/*call the yylex function.*/
return 0;

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.