fork download
  1. %{
  2.  
  3. /* Definition section */
  4.  
  5. int postiveno=0;
  6.  
  7. int negtiveno=0;
  8.  
  9. int positivefractions=0;
  10.  
  11. int negativefractions=0;
  12. %}
  13.  
  14.  
  15. /* Rule Section */
  16. DIGIT [0-9]
  17. %%
  18.  
  19.  
  20. \+?{DIGIT}+ postiveno++;
  21. -{DIGIT}+ negtiveno++;
  22.  
  23.  
  24. \+?{DIGIT}*\.{DIGIT}+ positivefractions++;
  25. -{DIGIT}*\.{DIGIT}+ negativefractions++;
  26. . ;
  27. %%
  28.  
  29.  
  30. // driver code
  31.  
  32. int main()
  33. {
  34.  
  35. yylex();
  36.  
  37. printf("\nNo. of positive numbers: %d", postiveno);
  38.  
  39. printf("\nNo. of Negative numbers: %d", negtiveno);
  40.  
  41. printf("\nNo. of Positive numbers in fractions: %d", positivefractions);
  42.  
  43. printf("\nNo. of Negative numbers in fractions: %d\n", negativefractions);
  44.  
  45. return 0;
  46. }
Success #stdin #stdout #stderr 0.02s 6820KB
stdin
1,2,3,4,5,6,7,8,9
stdout
Standard output is empty
stderr
ERROR: /home/XShnKu/prog:5:8: Syntax error: Operator expected
ERROR: /home/XShnKu/prog:46:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit