You are on page 1of 1

//LEX program to count total no.

of small alphabets [a-z] tokens
%{
#include<stdio.h>
int s=0;
%}
%option noyywrap
%%
"("|")"|"{"|"}" {printf("Brackets\n");}
"+"|"-"|"*"|"/"|"%"|"=" {printf("operator\n");}
int|float|char {printf("keyword\n");}
","|";" {printf("seperator\n");}
main {printf("function\n");}
[a-z] {s++;}
[-][0-9]+ {printf("Negative number\n");}
[+]?[0-9]+ {printf("Positive number\n");}
"%d" {printf("String Constant\n");}
"\n" {return 0;}
%%
void main()
{
//[a-z|A-Z]+[0-9]* {printf("Identifier\n");}
yylex();
printf("%d\n",s);
}