in Compiler Design retagged by
21,093 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$
in Compiler Design retagged by
by
21.1k views

4 Comments

No, it is not. T1 contains all strings ending with a.
3
3
edited by

It is not any new terminology devised for this question. ? is a standard symbol used for the same purpose, according to Hopcroft.

5
5

@LRU

Thanks for correcting.

Yup last a we have to take. I don’t know why i misread as a*.

2
2

7 Answers

54 votes
54 votes
Best answer

Option D is the correct answer.

You can think $T_3$ as $\left ( \varepsilon + c \right )\left ( b+a \right )^{*}c$

Given string is $bbaacabc$

The longest matching prefix $\text{bbaac}$ { from regex $T3$ you can easily derive $\text{bbaac}$ }

Now the remaining  $\text{abc}$ { This can also be derived from $T3$ }

Hence $T3T3$ is the answer.

edited by

4 Comments

Here, T1 : (b+c)* a + a(b+c)* a

          T2 : (a+c)* b + b(a+c)* b

          T3 : (b+a)* c + c(b+a)* c

So,if we take T3 then if we want to generate "bbaac" i.e the longest prefix then if we take first option of T3 i.e. (b+a)* c then c will compulsory will be in the prefix. But in the longest prefix there is "c" coming at last . Even if we take any option of T3 then "c" will get generated at starting of the prefix of string compulsorily { MY NEW VOCABULARY :)}

Can somebody explain ? 

0
0
  •  T1 : (b+c)* a + a(b+c)* a

  •  T2 : (a+c)* b + b(a+c)* b

  •  T3 : (b+a)* c + c(b+a)* c

So this is the three expression given 

we have given the string     “bbaacabc”

First, we take T1 and generate: bb

Then T2 and generated:  aac

Then T3 and generated: abc

How this approach is wrong?


 

0
0

@princeit07 using T1 you can never generate bb because ‘a’ will always come after ‘bb’. 

The question has asked about longest common subsequcnce that’s why we are considering T3T3 as the correct answer.

2
2
40 votes
40 votes
Option A
T1   T2    T3
bba  acab    bc

Option B
T1 T1 T3
bba aca bc

option C
T2 T1 T3
bb    aa  cabc

option D
T3         T3
bbaac      abc

all options can generate the string.

here option D has the longest prefix hence it is the answer.

1 comment

needs correction in option A
0
0
10 votes
10 votes

option D is correct

bbaac -> this can be generated by T3 by taking c zero time, bbaa can be generated by (b+a)* and then append c at the end.

abc -> this can be again generated by taking T3

so the answer is T3T3

8 votes
8 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
Also given,
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