fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int line_count = 0;
  5. int char_count = 0;
  6. %}
  7.  
  8. %%
  9.  
  10. \n { line_count++; char_count++; } /* Count newline as character and line */
  11. . { char_count++; } /* Count all other characters */
  12.  
  13. %%
  14.  
  15. int main()
  16. {
  17. printf("Enter text (Ctrl+D to end input):\n");
  18. yylex();
  19.  
  20. printf("\nTotal number of characters: %d\n", char_count);
  21. printf("Total number of lines: %d\n", line_count);
  22.  
  23. return 0;
  24. }
  25.  
  26. int yywrap()
  27. {
  28. return 1;
  29. }
  30.  
Success #stdin #stdout #stderr 0.03s 6912KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/jNiNGr/prog:2:1: Syntax error: Operator expected
ERROR: /home/jNiNGr/prog:29:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit