fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int identifier_count = 0;
  5. %}
  6.  
  7. %%
  8. [a-zA-Z_][a-zA-Z0-9_]* {
  9. identifier_count++;
  10. }
  11. [ \t\n]+ { /* Skip whitespace */ }
  12. . { /* Ignore everything else */ }
  13. %%
  14.  
  15. int main(int argc, char **argv) {
  16. if (argc > 1) {
  17. FILE *file = fopen(argv[1], "r");
  18. if (!file) {
  19. perror("Error opening file");
  20. return 1;
  21. }
  22. yyin = file;
  23. }
  24.  
  25. yylex(); // Start the lexical analysis
  26. printf("Number of identifiers: %d\n", identifier_count);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout #stderr 0.03s 6892KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/v539pa/prog:2:1: Syntax error: Operator expected
ERROR: /home/v539pa/prog:28:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit