fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int lines = 0; // To count the number of lines
  5. int spaces = 0; // To count the number of spaces
  6. int tabs = 0; // To count the number of tab characters
  7. int others = 0; // To count the number of other characters
  8. %}
  9.  
  10. %%
  11. \n { lines++; } // Count a new line
  12. " " { spaces++; } // Count a space
  13. "\t" { tabs++; } // Count a tab
  14. . { others++; } // Count all other characters
  15.  
  16. %%
  17.  
  18. int main() {
  19. yylex(); // Call the Lex scanner
  20. // Print the results
  21. printf("The number of lines are: %d\n", lines);
  22. printf("The number of spaces are: %d\n", spaces);
  23. printf("The number of tab-meta characters are: %d\n", tabs);
  24. printf("The rest of the characters are: %d\n", others);
  25. return 0;
  26. }
  27.  
Success #stdin #stdout #stderr 0.02s 6940KB
stdin
Hello and Welcome to
Compiler Design Lab.
stdout
Standard output is empty
stderr
ERROR: /home/xbcTWB/prog:2:1: Syntax error: Operator expected
ERROR: /home/xbcTWB/prog:26:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? EOF: exit