Q. A lexical analyzer uses the following patterns to recognize three tokens T1, T2, and T3 over the alphabet {a,b,c}.
π1: π? (π|π)βπ
π2: π? (π|π)βπ
π3:Β Β π? (π|π)βπ
Note that βx?β means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the token that matches the longest possible prefix.
If the string ππππππππ is processed by the analyzer, which one of the following is the sequence of tokens it outputs?
(A) π1π2π3Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β (B) π1π1π3Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β (C) π2π1π3Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β (D) π3π3
Ans: π3π3
Sol:
0 or 1 occurrence of the symbol x. T1 : (b+c)* a + a(b+c)* a T2 : (a+c)* b + b(a+c)* b T3 : (b+a)* c + c(b+a)* c Given String : bbaacabc Longest matching prefix is \β bbaac \β (Which can be generated by T3) The remaining part (after Prefix) \βabc\β (Can be generated by T3) So, the answer is T3T3