fork download
  1. %{
  2. #include <stdio.h>
  3. int macros = 0;
  4. int headers = 0;
  5. %}
  6.  
  7. %%
  8. ^[ \t]*"#include"[ \t]*[<"].*[>"] { headers++; }
  9. ^[ \t]*"#define"[ \t]+[a-zA-Z_][a-zA-Z0-9_]* { macros++; }
  10. .|\n { /* Ignore all other characters so they don't echo to the screen */ }
  11. %%
  12.  
  13. int yywrap() {
  14. return 1;
  15. }
  16.  
  17. int main() {
  18. printf("Enter the C program input (press Ctrl+D to end):\n");
  19. yylex();
  20. printf("\nTotal number of macros defined: %d\n", macros);
  21. printf("Total number of header files included: %d\n", headers);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout #stderr 0.02s 6756KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/lyYp8z/prog:23:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit