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