fork download
  1. %{
  2. #include <stdio.h>
  3. int count_less_than_5 = 0;
  4. int count_greater_than_10 = 0;
  5. %}
  6.  
  7. %%
  8. [a-zA-Z0-9]+ {
  9. int len = yyleng;
  10. if (len < 5)
  11. count_less_than_5++;
  12. else if (len > 10)
  13. count_greater_than_10++;
  14. }
  15. [ \t\n]+ ; // Ignore whitespace
  16. . ; // Ignore any other character
  17. %%
  18.  
  19. int main(int argc, char **argv) {
  20. printf("Enter text (CTRL+D to end input):\n");
  21. yylex();
  22. printf("\nWords with length < 5: %d\n", count_less_than_5);
  23. printf("Words with length > 10: %d\n", count_greater_than_10);
  24. return 0;
  25. }
  26.  
  27. int yywrap() {
  28. return 1;
  29. }
  30.  
Success #stdin #stdout #stderr 0.03s 6992KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/ZqwXlg/prog:2:1: Syntax error: Operator expected
ERROR: /home/ZqwXlg/prog:29:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit