fork download
  1. %{
  2. // Declare variables to count lines and characters
  3. int line_count = 0;
  4. int char_count = 0;
  5. %}
  6.  
  7. %%
  8. \n { line_count++; char_count++; } // Increment both line and character count for new lines
  9. . { char_count++; } // Increment character count for any character
  10. %%
  11.  
  12. int main() {
  13. // Call the Lex-generated function yylex() to start processing the input
  14. yylex();
  15.  
  16. // After processing, print the results
  17. printf("Number of lines: %d\n", line_count);
  18. printf("Number of characters: %d\n", char_count);
  19.  
  20. return 0;
  21. }
  22.  
  23. int yywrap() {
  24. return 1;
  25. }
  26.  
Success #stdin #stdout #stderr 0.02s 7016KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/ewetvY/prog:2:8: Syntax error: Operator expected
ERROR: /home/ewetvY/prog:25:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit