fork download
  1. %{ /*LEX program to count the number of: a) Positive and negative integers
  2. b) Positive and negative fractions */
  3. int zcnt=0, pcnt=0, ncnt=0, pfcnt=0, nfcnt=0;
  4. %}
  5. zero [+]?[0]+|[-][0]+|[+]?[0]\.[0]|[-][0]\.[0]
  6. %%
  7. {zero} { zcnt++; }
  8. [+]?[0]*[1-9][0-9]* { pcnt++; }
  9. [-][0]*[1-9][0-9]* { ncnt++; }
  10. [+]?[0-9]*\.[0-9]+ { pfcnt++; }
  11. [-][0-9]*\.[0-9]+ { nfcnt++; }
  12. \n return;
  13. %%
  14. main()
  15. {
  16. printf("Enter nos separated by space: ");
  17. yylex();
  18. printf("No of zeros=%d\n", zcnt);
  19. printf("No of positive integers=%d\n", pcnt);
  20. printf("No of negative integers=%d\n", ncnt);
  21. printf("No of positive fractions=%d\n", pfcnt);
  22. printf("No of negative fractions=%d\n", nfcnt);
  23. }
Success #stdin #stdout #stderr 0.03s 6924KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/vVstNe/prog:23:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit