Flex program to check use of echo and reject statements

Flex program to check use of echo and reject statements

This flex program is to check use of echo and reject statements. If we find a string containing only lowercase letters then the first pattern with regular expression [a-z] (matches lowercase letters) matches else if any lowercase or uppercase letters is found then the second pattern[a-zA-Z] matches else anything other then the above is found then the third action with regular expression(.) matches.

ECHO statement copies the token matched to the output.

Whenever REJECT statement is executed, the last letter will be treated with the matched token and will continue with the prefixed input for the next action or rule.

Program

%{

/*USE OF REJECT STATEMENT*/
#undef yywrap
#define yywrap() 1

%}

%%

[a-z]+ {
	printf("\ncontains only lowercase letters = ");
	ECHO;
	
	}

[a-zA-Z]+ {
	printf("\ncontains both uppercase and lowercase letters = ");
	ECHO;
	REJECT;
	
	}

. {
	printf("\ncontains mixed letters = ");
	ECHO;
	
	}

%%


main()
{
	yylex();
}

Output

Share Me!