fork download
  1. %{
  2. #include <stdio.h>
  3. int line_count = 0, space_count = 0, tab_count = 0, char_count = 0;
  4. %}
  5. %%
  6. \n { line_count++; }
  7. [ \t] { if (yytext[0] == ' ') space_count++; else if (yytext[0] == '\t') tab_count++; }
  8. . { char_count++; }
  9. %%
  10. int main() {
  11. printf("Enter the input text (Press Ctrl+D to end input on Linux/Mac, Ctrl+Z on Windows):\n");
  12. yylex(); printf("\nStatistics:\n");
  13. printf("Number of Lines: %d\n", line_count); printf("Number of Spaces: %d\n", space_count); printf("Number of Tabs: %d\n", tab_count);
  14.  
  15. printf("Number of Other Characters: %d\n", char_count); return 0;
  16. }
  17. int yywrap() { return 1;
  18. }
  19.  
Success #stdin #stdout #stderr 0.02s 6844KB
stdin
gaurav
stdout
Standard output is empty
stderr
ERROR: /home/SP1666/prog:2:1: Syntax error: Operator expected
ERROR: /home/SP1666/prog:18:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit