fork download
  1.  
  2.  
  3. %{
  4. #include <stdio.h>
  5. int a_count = 0, b_count = 0;
  6. %}
  7.  
  8. %%
  9.  
  10. a { a_count++; }
  11. b { b_count++; }
  12. [^ab\n] { printf("Invalid character: %s\n", yytext); }
  13. \n {
  14. if (a_count % 2 == 1 && b_count % 2 == 0) {
  15. printf(" Accepted: Odd number of a's and Even number of b's\n");
  16. } else {
  17. printf(" Rejected: a = %d, b = %d\n", a_count, b_count);
  18. }
  19. a_count = 0;
  20. b_count = 0;
  21. }
  22.  
  23. %%
  24.  
  25. int yywrap() {
  26. return 1;
  27. }
  28.  
  29. int main() {
  30. printf("Enter strings (a/b only). Press Ctrl+D (Linux/Mac) or Ctrl+Z (Windows) to stop:\n");
  31. yylex();
  32. return 0;
  33. }
Success #stdin #stdout #stderr 0.04s 6836KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/2YIrfk/prog:33:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit