fork download
  1. %{
  2. #include<stdio.h>
  3. #include<string.h>
  4. int i = 0; // Counter for the number of words
  5. %}
  6.  
  7. /* Rules Section */
  8. %%
  9.  
  10. [a-zA-Z0-9]+ { i++; } /* Rule for counting words composed of alphanumeric characters */
  11. [\n] { printf("Number of words: %d\n", i); i = 0; } /* Print count when a newline is encountered */
  12. [ \t]+ { /* Ignore spaces and tabs */ }
  13.  
  14. %%
  15.  
  16. int yywrap(void) {
  17. return 1; // Return 1 to indicate the end of the input
  18. }
  19.  
  20. int main() {
  21. // The function that starts the lexical analysis
  22. printf("Enter words, and press Enter to get the word count:\n");
  23. yylex(); // Start lexical analysis
  24. return 0;
  25. }
  26.  
Success #stdin #stdout #stderr 0.02s 6972KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/GzfIaK/prog:25:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit