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