fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int ctIdentifier = 0;
  6. int ctLine = 0;
  7. int ctBlankLine = 0;
  8. %}
  9.  
  10. /* Regular Expressions */
  11. IDENTIFIER [a-zA-Z_][a-zA-Z0-9_]*
  12. EOL \n
  13. WS [ \t]+
  14. %%
  15. /* Identifier rule */
  16. {IDENTIFIER} { ctIdentifier++; }
  17.  
  18. /* Blank line: consists only of spaces/tabs followed by newline */
  19. ^{WS}*{EOL} { ctBlankLine++; ctLine++; }
  20.  
  21. /* End of line (non-blank) */
  22. {EOL} { ctLine++; }
  23.  
  24. /* Ignore other characters */
  25. . { /* Do nothing */ }
  26. %%
  27.  
  28. int yywrap() {
  29. return 1;
  30. }
  31.  
  32. int main(int argc, char *argv[]) {
  33. if (argc != 2) {
  34. printf("Usage:\n\t./a.out <FILENAME>\n");
  35. exit(0);
  36. }
  37.  
  38. yyin = fopen(argv[1], "r");
  39. if (!yyin) {
  40. perror("Error opening file");
  41. exit(1);
  42. }
  43.  
  44. yylex();
  45.  
  46. printf("Identifier Count: %d\n", ctIdentifier);
  47. printf("Total Lines: %d\n", ctLine);
  48. printf("Blank Lines: %d\n", ctBlankLine);
  49.  
  50. fclose(yyin);
  51. return 0;
  52. }
  53.  
Success #stdin #stdout #stderr 0.04s 6876KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/j4NRRB/prog:2:1: Syntax error: Operator expected
ERROR: /home/j4NRRB/prog:52:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit