fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int word_count = 0;
  6. int punct_count = 0;
  7. %}
  8.  
  9. %%
  10. [ \t\n]+ ; /* ignore whitespace */
  11.  
  12. "(" { printf("LPAREN : %s\n", yytext); punct_count++; }
  13. ")" { printf("RPAREN : %s\n", yytext); punct_count++; }
  14. "?" { printf("QUESTION : %s\n", yytext); punct_count++; }
  15. "." { printf("PERIOD : %s\n", yytext); punct_count++; }
  16.  
  17. [0-9]+ { printf("NUMBER : %s\n", yytext); }
  18.  
  19. [[:alpha:]]+ {
  20. printf("WORD : %s\n", yytext);
  21. word_count++;
  22. }
  23.  
  24. /* Anything else */
  25. . ;
  26. %%
  27.  
  28. int main(void) {
  29. yylex();
  30. printf("Total words: %d\n", word_count);
  31. printf("Total punctuation: %d\n", punct_count);
  32. return 0;
  33. }
  34.  
Success #stdin #stdout #stderr 0.03s 6920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/UioOFz/prog:2:1: Syntax error: Operator expected
ERROR: /home/UioOFz/prog:33:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit