fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int lines = 0;
  5. int spaces = 0;
  6. int tabs = 0;
  7. int others = 0;
  8. %}
  9.  
  10. %%
  11.  
  12. \n { lines++; } // Count a new line
  13. " " { spaces++; } // Count a space
  14. "\t" { tabs++; } // Count a tab
  15. . { others++; } // Count all other characters
  16.  
  17. %%
  18.  
  19. int main() {
  20. yylex(); // Call the Lex scanner to process the input
  21. // Output the results
  22. printf("The number of lines are: %d\n", lines);
  23. printf("The number of spaces are: %d\n", spaces);
  24. printf("The number of tab-meta characters are: %d\n", tabs);
  25. printf("The rest of the characters are: %d\n", others);
  26. return 0;
  27. }
  28.  
Success #stdin #stdout #stderr 0.04s 6960KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/1895jd/prog:2:1: Syntax error: Operator expected
ERROR: /home/1895jd/prog:27:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit