fork download
  1. %{
  2. #include <stdio.h>
  3. int charCount = 0, wordCount = 0, spaceCount = 0, lineCount = 0;
  4. %}
  5.  
  6. %%
  7. [ \t] { spaceCount++; charCount++; } /* Count spaces/tabs */
  8. \n { lineCount++; charCount++; } /* Count newlines */
  9. [a-zA-Z]+ { wordCount++; charCount += yyleng; } /* Count words, add their length */
  10. . { charCount++; } /* Count any other character */
  11. %%
  12.  
  13. int main() {
  14. yylex();
  15. printf("Characters: %d\n", charCount);
  16. printf("Words: %d\n", wordCount);
  17. printf("Spaces: %d\n", spaceCount);
  18. printf("Lines: %d\n", lineCount);
  19. return 0;
  20. }
Success #stdin #stdout #stderr 0.04s 6924KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/5NHis7/prog:2:1: Syntax error: Operator expected
ERROR: /home/5NHis7/prog:20:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit