fork download
  1. %{
  2. int positive_integers = 0;
  3. int negative_integers = 0;
  4. int positive_fractions = 0;
  5. int negative_fractions = 0;
  6. %}
  7.  
  8. %%
  9. [+-]?[0-9]+ { if (atoi(yytext) > 0) positive_integers++;
  10. else if (atoi(yytext) < 0) negative_integers++; }
  11. [+-]?[0-9]+\.[0-9]+ { if (atof(yytext) > 0) positive_fractions++;
  12. else if (atof(yytext) < 0) negative_fractions++; }
  13. .|\n ;
  14.  
  15. %%
  16.  
  17. int main() {
  18. yylex();
  19. printf("Positive Integers: %d\n", positive_integers);
  20. printf("Negative Integers: %d\n", negative_integers);
  21. printf("Positive Fractions: %d\n", positive_fractions);
  22. printf("Negative Fractions: %d\n", negative_fractions);
  23. return 0;
  24. }
  25.  
Success #stdin #stdout #stderr 0.02s 6916KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/3LrbDB/prog:24:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit