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