A lexical analyzer uses the following patterns to recognize three tokens T1, T2, and T3 over the alphabet {a,b,c}.

A lexical analyzer uses the following patterns to recognize three tokens T1, T2, and T3 over the alphabet {a,b,c}.

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 

Scroll to Top