fork download
  1. %{
  2. #include <stdio.h>
  3. int wordlen[50]; // Array to count words of different lengths
  4. %}
  5.  
  6. %%
  7. [ \t\n]+ { /* ignore whitespace */ }
  8. [A-Za-z]+ { wordlen[yyleng]++; } // count word length
  9. . { /* ignore other characters */ }
  10. %%
  11.  
  12. int main() {
  13. yylex();
  14. printf("\nHistogram of Word Lengths:\n");
  15. for (int i = 1; i < 50; i++) {
  16. if (wordlen[i] > 0) {
  17. printf("%2d: ", i);
  18. for (int j = 0; j < wordlen[i]; j++)
  19. printf("*");
  20. printf("\n");
  21. }
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout #stderr 0.02s 6828KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/9aH8eU/prog:2:1: Syntax error: Operator expected
ERROR: /home/9aH8eU/prog:24:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit