fork download
  1. /*** Definition Section has one variable
  2. which can be accessed inside yylex()
  3. and main() ***/
  4. %{
  5. int count = 0;
  6. %}
  7.  
  8. /*** Rule Section has three rules, first rule
  9. matches with capital letters, second rule
  10. matches with any character except newline and
  11. third rule does not take input after the enter***/
  12. %%
  13. [A-Z] {printf("%s capital letter\n", yytext);
  14. count++;}
  15. . {printf("%s not a capital letter\n", yytext);}
  16. \n {return 0;}
  17. %%
  18.  
  19. /*** Code Section prints the number of
  20. capital letter present in the given input***/
  21. int yywrap(){}
  22. int main(){
  23.  
  24. // Explanation:
  25. // yywrap() - wraps the above rule section
  26. /* yyin - takes the file pointer
  27.   which contains the input*/
  28. /* yylex() - this is the main flex function
  29.   which runs the Rule Section*/
  30. // yytext is the text in the buffer
  31.  
  32. // Uncomment the lines below
  33. // to take input from file
  34. // FILE *fp;
  35. // char filename[50];
  36. // printf("Enter the filename: \n");
  37. // scanf("%s",filename);
  38. // fp = fopen(filename,"r");
  39. // yyin = fp;
  40.  
  41. yylex();
  42. printf("\nNumber of Captial letters "
  43. "in the given input - %d\n", count);
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout #stderr 0.02s 6980KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/V0jIQM/prog:5:4: Syntax error: Operator expected
ERROR: /home/V0jIQM/prog:46:2: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit