fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int macro_count = 0;
  5. int header_count = 0;
  6. %}
  7.  
  8. %%
  9.  
  10. ^[ \t]*#define { macro_count++; }
  11. ^[ \t]*#include { header_count++; }
  12.  
  13. .|\n ; /* Ignore all other input */
  14.  
  15. %%
  16.  
  17. int main() {
  18. printf("Enter C program (Press Ctrl+D to end input):\n\n");
  19. yylex();
  20.  
  21. printf("\nNumber of macros defined: %d\n", macro_count);
  22. printf("Number of header files included: %d\n", header_count);
  23.  
  24. return 0;
  25. }
  26.  
  27. int yywrap() {
  28. return 1;
  29. }
Success #stdin #stdout #stderr 0.02s 6908KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/Su6MkR/prog:29:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit