fork download
  1. /*lex code to accept a valid integer
  2.   and float value using lex program.*/
  3.  
  4. %{
  5. int valid_int=0, valid_float=0;
  6. %}
  7.  
  8. %%
  9. ^[-+]?[0-9]* valid_int++;
  10. ^[-+]?[0-9]*[.][0-9]+$ valid_float++;
  11. .;
  12. %%
  13.  
  14. int main()
  15. {
  16. yylex();
  17. if(valid_int!=0) printf("Valid Integer number\n");
  18. else if(valid_float!=0) printf("Valid Float number\n");
  19. else printf("Not valid Integer/Float number\n");
  20. return 0;
  21. }
Success #stdin #stdout #stderr 0.03s 6876KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/bJUTBj/prog:21:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit