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ย 

Gkseries: Gkseries.com is a premier website to provide complete solution for online preparation of different competitive exams like UPSC, SBI PO, SBI clerical, PCS, IPS, IAS, IBPS PO, IBPS Clerical exam etc. & other graduate and post-graduate exams. Learn more on about us page