fork download
  1. %{
  2. #include <stdio.h>
  3. // Variables to keep track of frequencies
  4. int count_if = 0;
  5. int count_else = 0;
  6. int count_while = 0;
  7. int total_keywords = 0;
  8. %}
  9.  
  10. %option noyywrap
  11.  
  12. %%
  13. "if" { count_if++; total_keywords++; }
  14. "else" { count_else++; total_keywords++; }
  15. "while" { count_while++; total_keywords++; }
  16.  
  17. [a-zA-Z]+ { /* Ignore other words. */ }
  18. .|\n { /* Ignore spaces, punctuation, and new lines */ }
  19. %%
  20.  
  21. int main() {
  22. printf("Enter your text (Press Ctrl+Z and Enter on a new line to finish):\n");
  23.  
  24. // yylex() starts the scanning process
  25. yylex();
  26.  
  27. printf("\n--- Keyword Frequency Results ---\n");
  28. printf("'if' count : %d\n", count_if);
  29. printf("'else' count : %d\n", count_else);
  30. printf("'while' count : %d\n", count_while);
  31. printf("Total keywords: %d\n", total_keywords);
  32.  
  33. return 0;
  34. }
Success #stdin #stdout #stderr 0.02s 6796KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/ZDCYCG/prog:34:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit