lexInFlex.txt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. %{
  2. #include<stdio.h>
  3. int count = 0, lcount = 0, tcount = 0;
  4. %}
  5. %%
  6. "//"([a-z]|[0-9]|[A-Z]|" ")* {printf("\nSingle line comment : %s\n",yytext);}
  7. "/*"([a-z]|[0-9]|[A-Z]|" "|"\n")+"*/" {printf("\nMulti-line comment : %s\n",yytext);}
  8. [a-zA-Z]*\<[a-zA-Z]*\.\h\> {printf("\nHeaderFile : %s",yytext+7);}
  9. 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);}
  10. [a-zA-Z]*\( {printf("\nFunction : %s",strcat(yytext,")"));}
  11. "&&"|"||"|"!" {printf("\nLogical Operator : %s",yytext);}
  12. "+"|"-"|"*"|"/"|"--"|"%"|"++" {printf("\nArithmatic Operator : %s",yytext);}
  13. "<"|">"|"!="|"=="|">="|"<=" {printf("\nRelational Operator : %s",yytext);}
  14. "&"|"|"|"^"|"<<"|">>"|"~" {printf("\nBitwise Operator : %s",yytext);}
  15. "=" {printf("\nAssignment Operator : %s",yytext);}
  16. "$"|"@" {printf("\nSpecial Symbol : %s",yytext);}
  17. [a-zA-Z]* {printf("\nIdentifier : %s",yytext);}
  18. -?[0-9]* {printf("\nNumber : %s",yytext);}
  19. -?[0-9]*\.[0-9]* {printf("\nFloating Number : %s",yytext);}
  20. ":"|";"|"," {printf("\nDelimiter : %s", yytext);}
  21. " " {count++;}
  22. "\t" {tcount++;}
  23. "\n" {lcount++;}
  24. . {printf("\n");}
  25. %%
  26. main(int argc, char ** argv)
  27. {
  28. FILE *fp;
  29. fp = fopen(argv[1],"r");
  30. yyin = fp;
  31. yylex();
  32. printf("\nNumber of WhiteSpaces : %d\n",count);
  33. printf("\nNumber of Lines : %d\n",(lcount+1));
  34. }
  35. int yywrap()
  36. {
  37. return 1;
  38. }