fork download
  1. /* Lex program for counting words, lines, and characters */
  2. %{
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. int charCount = 0;
  7. int wordCount = 0;
  8. int lineCount = 0;
  9. int digCount = 0;
  10. %}
  11.  
  12. /* Regular expression definitions */
  13. word [^ \t\n]+
  14. Dig [0-9]+
  15.  
  16. %%
  17. {Dig} {digCount++;}
  18. "340" {digCount = digCount+10;}
  19. {word} { wordCount++; charCount += strlen(yytext); }
  20. \n { charCount++; lineCount++; }
  21. . { charCount++; }
  22. %%
  23.  
  24. int main(void) {
  25. yylex();
  26. printf("Characters: %d, Words: %d, Lines: %d, Dig: %d\n",
  27. charCount, wordCount, lineCount, digCount);
  28. return 0;
  29. }
  30. int yywrap(void) {
  31. return 1;
  32. }
Success #stdin #stdout #stderr 0.02s 6940KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/x1bhqb/prog:3:1: Syntax error: Operator expected
ERROR: /home/x1bhqb/prog:32:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit