fork download
  1. %{
  2. int count = 0; // Initialize the count of capital letters
  3. %}
  4.  
  5. %%
  6.  
  7. [A-Z] { // If the token is a capital letter
  8. printf("%s capital letter\n", yytext);
  9. count++; // Increment the count
  10. }
  11.  
  12. . { // For any other character
  13. printf("%s not a capital letter\n", yytext);
  14. }
  15.  
  16. \n { return 0; } // When newline is encountered, return 0 to stop processing
  17.  
  18. %%
  19.  
  20. int yywrap() {
  21. return 1; // Return 1 to indicate that input is finished
  22. }
  23.  
  24. int main() {
  25. printf("Enter text: ");
  26. yylex(); // Start lexical analysis
  27. printf("\nNumber of Capital letters in the given input - %d\n", count); // Output the result
  28. return 0;
  29. }
  30.  
Success #stdin #stdout #stderr 0.02s 6988KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/P30Kx1/prog:2:4: Syntax error: Operator expected
ERROR: /home/P30Kx1/prog:29:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit