12345678910111213141516171819202122232425262728293031323334353637383940 |
- %{
- #include<stdio.h>
- int count = 0, lcount = 0, tcount = 0;
- %}
- %%
- "//"([a-z]|[0-9]|[A-Z]|" ")* {printf("\nSingle line comment : %s\n",yytext);}
- "/*"([a-z]|[0-9]|[A-Z]|" "|"\n")+"*/" {printf("\nMulti-line comment : %s\n",yytext);}
- [a-zA-Z]*\<[a-zA-Z]*\.\h\> {printf("\nHeaderFile : %s",yytext+7);}
- void|int|float|char|double|long|for|while|if|else|case|break|continue|do|extern|enum|return|register|short|signed|sizeof|static|switch|struct|unsigned {printf("\nKeyword : %s",yytext);}
- [a-zA-Z]*\( {printf("\nFunction : %s",strcat(yytext,")"));}
- "&&"|"||"|"!" {printf("\nLogical Operator : %s",yytext);}
- "+"|"-"|"*"|"/"|"--"|"%"|"++" {printf("\nArithmatic Operator : %s",yytext);}
- "<"|">"|"!="|"=="|">="|"<=" {printf("\nRelational Operator : %s",yytext);}
- "&"|"|"|"^"|"<<"|">>"|"~" {printf("\nBitwise Operator : %s",yytext);}
- "=" {printf("\nAssignment Operator : %s",yytext);}
- "$"|"@" {printf("\nSpecial Symbol : %s",yytext);}
- [a-zA-Z]* {printf("\nIdentifier : %s",yytext);}
- -?[0-9]* {printf("\nNumber : %s",yytext);}
- -?[0-9]*\.[0-9]* {printf("\nFloating Number : %s",yytext);}
- ":"|";"|"," {printf("\nDelimiter : %s", yytext);}
- " " {count++;}
- "\t" {tcount++;}
- "\n" {lcount++;}
- . {printf("\n");}
- %%
- main(int argc, char ** argv)
- {
- FILE *fp;
- fp = fopen(argv[1],"r");
- yyin = fp;
- yylex();
- printf("\nNumber of WhiteSpaces : %d\n",count);
- printf("\nNumber of Lines : %d\n",(lcount+1));
- }
- int yywrap()
- {
- return 1;
- }
|