fork download
  1. %{
  2. int nc=0;
  3. int nl=0;
  4. int nw=0;
  5. %}
  6. %%
  7. "if"|"else"|"while"|"do"|"auto"|"double"|"int"|"struct"|"break"|"else"|"long"|"switch"|"case"|"enum"|"register"|"typ>
  8. [!@#$^&()_~'";:] {printf("%s is a SPECIAL CHARACTER\n", yytext);}
  9. [+*/=%-] {printf("%s is an OPERATOR\n", yytext);}
  10. [0-9]* {printf("%s is a CONSTANT\n", yytext);}
  11. [a-zA-Z]* {printf("%s is an IDENTIFIER\n", yytext);}
  12. \"([^"})*\" {printf("%s is STRING LITERAL\n", yytext);}
  13. \n {nl++;nc+=yyleng;}
  14. [^\n" "\t]+ {nw++;nc=nc+yyleng;}
  15. . {nc++;}
  16. %%
  17. int yywrap()
  18. {}
  19. int main(int argc,char* argv[])
  20. {
  21.  
  22. yyin=fopen(argv[1],"r");
  23. yylex();
  24. printf("\nNo. of lines is %d\n", nl);
  25. printf("\nNo. of words is %d\n", nw);
  26. printf("\nNo. of characters is %d\n", nc);
  27. return 0;
  28. }
  29.  
  30.  
Success #stdin #stdout #stderr 0.02s 6676KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/F8OPLt/prog:2:4: Syntax error: Operator expected
ERROR: /home/F8OPLt/prog:29:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit