fork download
  1. %{
  2. #include <stdio.h>
  3. int line_count = 0;
  4. int word_count = 0;
  5. int char_count = 0;
  6. %}
  7.  
  8. %%
  9. \n {
  10. line_count++;
  11. char_count += strlen(yytext);
  12. }
  13. [a-zA-Z0-9_]+ {
  14. word_count++;
  15. char_count += strlen(yytext);
  16. }
  17. [ \t] {
  18. char_count += strlen(yytext);
  19. }
  20. . {
  21. char_count += strlen(yytext);
  22. }
  23.  
  24. %%
  25.  
  26. int main() {
  27. printf("Enter text (press Ctrl+D when finished):\n");
  28. yylex();
  29.  
  30. printf("\nResults:\n");
  31. printf("Number of lines: %d\n", line_count);
  32. printf("Number of words: %d\n", word_count);
  33. printf("Total characters: %d\n", char_count);
  34.  
  35. return 0;
  36. }
  37.  
  38. int yywrap() {
  39. return 1;
  40. }
Success #stdin #stdout #stderr 0.02s 6892KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/isQfkj/prog:2:1: Syntax error: Operator expected
ERROR: /home/isQfkj/prog:40:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit