fork download
  1. %{
  2. #include <stdio.h>
  3.  
  4. int pi = 0, ni = 0, pf = 0, nf = 0;
  5. %}
  6.  
  7. %%
  8.  
  9. [-][0-9]+ { ni++; } // negative integers
  10. [+]?[0-9]+ { pi++; } // positive integers
  11. [-][0-9]*\.[0-9]+ { nf++; } // negative fractions
  12. [+]?[0-9]*\.[0-9]+ { pf++; } // positive fractions
  13.  
  14. . ; // ignore everything else
  15.  
  16. %%
  17.  
  18. int yywrap() { return 1; }
  19.  
  20. int main(int argc, char *argv[])
  21. {
  22. if (argc != 2)
  23. {
  24. printf("Usage: ./a.out input.txt\n");
  25. return 0;
  26. }
  27.  
  28. yyin = fopen(argv[1], "r");
  29. yylex();
  30.  
  31. printf("Number of positive integers: %d\n", pi);
  32. printf("Number of negative integers: %d\n", ni);
  33. printf("Number of positive fractions: %d\n", pf);
  34. printf("Number of negative fractions: %d\n", nf);
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout #stderr 0.02s 6812KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/d8j6Js/prog:2:1: Syntax error: Operator expected
ERROR: /home/d8j6Js/prog:37:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit