%{
#include <stdio.h>
#include <stdlib.h>
%}
%token A B
%%
S : A B { printf("Valid string: a^n b^n\n"); }
| A S B { /* Recursive rule to match a^n b^n */ }
| { /* epsilon rule */ }
;
%%
int main(void) {
printf("Enter string of a's and b's: ");
yyparse();
return 0;
}
int yyerror(char *s) {
printf("Error: %s\n", s);
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KJX0KCiV0b2tlbiBBIEIKCiUlCgpTICAgOiBBIEIgICAgICAgICAgeyBwcmludGYoIlZhbGlkIHN0cmluZzogYV5uIGJeblxuIik7IH0KICAgIHwgQSBTIEIgICAgICAgIHsgLyogUmVjdXJzaXZlIHJ1bGUgdG8gbWF0Y2ggYV5uIGJebiAqLyB9CiAgICB8ICAgICAgICAgICAgICAgeyAvKiBlcHNpbG9uIHJ1bGUgKi8gfQogICAgOwoKJSUKCmludCBtYWluKHZvaWQpIHsKICAgIHByaW50ZigiRW50ZXIgc3RyaW5nIG9mIGEncyBhbmQgYidzOiAiKTsKICAgIHl5cGFyc2UoKTsKICAgIHJldHVybiAwOwp9CgppbnQgeXllcnJvcihjaGFyICpzKSB7CiAgICBwcmludGYoIkVycm9yOiAlc1xuIiwgcyk7CiAgICByZXR1cm4gMDsKfQo=