retagged by
21,504 views
51 votes
51 votes

A lexical analyzer uses the following patterns to recognize three tokens $T_1, T_2$, and $T_3$ over the alphabet $\{a, b, c\}$.

  • $T_1: a?(b \mid c)^\ast a$
  • $T_2: b?(a \mid c)^\ast b$
  • $T_3: c?(b \mid a)^\ast c$

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 $bbaacabc$ is processed by the analyzer, which one of the following is the sequence of tokens it outputs?

  1. $T_1T_2T_3$
  2. $T_1T_1T_3$
  3. $T_2T_1T_3$
  4. $T_3T_3$
retagged by

7 Answers

3 votes
3 votes

The answer is T3Tas the question specifically mentioned that it will prefer the relational algebra which generates the longest subsequence.

With  T3 you get a subsequence of 5, whereas with T2 you get a subsequence of only 3.

Hence, T3 preferred over T2.

So option D is the correct answer.

2 votes
2 votes

Answer D T3T3

Answer can also be B,C if this line is not given.

Note also that the analyzer outputs the token that matches the longest possible prefix.

B T1T1T3

Which generates bba aca bc 

C T2T1T3.

bb aa cabc 

D T3T3

bbaac abc 

here longest prefix length is 5

 

0 votes
0 votes

a? means either 0 or 1 occurrence of “a”, so we can write T1, T2 and T3 as:
T1 : (b+c)*a + a(b+c)*a
T2 : (a+c)*b + b(a+c)*b
T3 : (b+a)*c + c(b+a)*c
Now the string is: bbaacabc
Please NOTE:
Token that matches the longest possible prefix
We can observe that the longest possible prefix in string is : bbaac which can be generated by T3.
After prefix we left with “abc” which is again generated by T3 (as longest possible prefix).
So, answer is T3T3.

Answer:

Related questions

19 votes
19 votes
4 answers
1
gatecse asked Feb 14, 2018
9,472 views
Consider the following parse tree for the expression a#b$\$$c$\$$d#e#f, involving two binary operators $\$$ and #.Which one of the following is correct for the given par...