%{
#include <stdio.h>
%}
%%
0 {
if (yytext[0] == '0') {
if (current_state == 0) current_state = 2;
else if (current_state == 1) current_state = 3;
else if (current_state == 2) current_state = 0;
else if (current_state == 3) current_state = 1;
}
}
1 {
if (yytext[0] == '1') {
if (current_state == 0) current_state = 1;
else if (current_state == 1) current_state = 0;
else if (current_state == 2) current_state = 3;
else if (current_state == 3) current_state = 2;
}
}
\n ;
. ;
%%
int current_state = 0;
int main() {
current_state = 0; // Start state: q0
printf("Enter a string of 0s and 1s: ");
yylex(); // Start lexing
if (current_state == 1) {
printf("Accepted\n");
} else {
printf("Not Accepted\n");
}
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CiV9CgolJQowICAgeyAKICAgICAgICBpZiAoeXl0ZXh0WzBdID09ICcwJykgewogICAgICAgICAgICBpZiAoY3VycmVudF9zdGF0ZSA9PSAwKSBjdXJyZW50X3N0YXRlID0gMjsKICAgICAgICAgICAgZWxzZSBpZiAoY3VycmVudF9zdGF0ZSA9PSAxKSBjdXJyZW50X3N0YXRlID0gMzsKICAgICAgICAgICAgZWxzZSBpZiAoY3VycmVudF9zdGF0ZSA9PSAyKSBjdXJyZW50X3N0YXRlID0gMDsKICAgICAgICAgICAgZWxzZSBpZiAoY3VycmVudF9zdGF0ZSA9PSAzKSBjdXJyZW50X3N0YXRlID0gMTsKICAgICAgICB9CiAgICB9CgoxICAgeyAKICAgICAgICBpZiAoeXl0ZXh0WzBdID09ICcxJykgewogICAgICAgICAgICBpZiAoY3VycmVudF9zdGF0ZSA9PSAwKSBjdXJyZW50X3N0YXRlID0gMTsKICAgICAgICAgICAgZWxzZSBpZiAoY3VycmVudF9zdGF0ZSA9PSAxKSBjdXJyZW50X3N0YXRlID0gMDsKICAgICAgICAgICAgZWxzZSBpZiAoY3VycmVudF9zdGF0ZSA9PSAyKSBjdXJyZW50X3N0YXRlID0gMzsKICAgICAgICAgICAgZWxzZSBpZiAoY3VycmVudF9zdGF0ZSA9PSAzKSBjdXJyZW50X3N0YXRlID0gMjsKICAgICAgICB9CiAgICB9CgpcbiAgOwouICAgOwoKJSUKCmludCBjdXJyZW50X3N0YXRlID0gMDsKCmludCBtYWluKCkgewogICAgY3VycmVudF9zdGF0ZSA9IDA7ICAvLyBTdGFydCBzdGF0ZTogcTAKCiAgICBwcmludGYoIkVudGVyIGEgc3RyaW5nIG9mIDBzIGFuZCAxczogIik7CiAgICB5eWxleCgpOyAgLy8gU3RhcnQgbGV4aW5nCgogICAgaWYgKGN1cnJlbnRfc3RhdGUgPT0gMSkgewogICAgICAgIHByaW50ZigiQWNjZXB0ZWRcbiIpOwogICAgfSBlbHNlIHsKICAgICAgICBwcmludGYoIk5vdCBBY2NlcHRlZFxuIik7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K