fork download
  1. %{
  2. /*To check if a given string is a word or a digit*/
  3. #undef yywrap
  4. #define yywrap() 1
  5. void display(char[],int);
  6. int flag;
  7.  
  8. %}
  9.  
  10. %%
  11.  
  12. [a-zA-Z]+ {
  13.  
  14. int flag=1;
  15. display(yytext,flag);
  16. return;
  17. }
  18.  
  19. [0-9]+ {
  20. int flag=0;
  21. display(yytext,flag);
  22.  
  23. }
  24.  
  25. .+ {
  26. int flag=-1;
  27. display(yytext,flag);
  28. }
  29.  
  30. %%
  31.  
  32. void display(char a[],int flag)
  33. {
  34. if(flag==1)
  35. printf("The given string = %s is a word ",a);
  36. if(flag==0)
  37. printf("The given string = %s is a number ",a);
  38. if(flag==-1)
  39. printf("The given string = %s is evereything ",a);
  40.  
  41. }
  42.  
  43. main()
  44. {
  45. printf("Enter a string");
  46. yylex();
  47. }
Success #stdin #stdout #stderr 0.03s 6936KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/4g7dNe/prog:47:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit