in Compiler Design retagged by
21,161 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.2k 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

11 Comments

Option d is correct..see Note in question.
0
0
what is the meaning of the line

 

T1: a?(b∣c)∗a
1
1
it  regular expression is like this (ε+a)(b+c)∗a  we have zero or one a followed any b or c and end with a
3
3

can we discuss why remaining options are wrongs, I understand the concepts for above question, My doubt in options 3, T2 T1T3. Is this reg expression also capable to generate bbaacab???

can I wrote like this, T2 can generate bb, T1 can generate aa and from T3 cabc

this option is wrong just because in question asking for longest possible prefixes or something else reason???

 

 

2
2
bbaacabc

Can someone please check what are lexemes here

b(T1), bb(T2) , bba(T1) , bbaa(X) , bbaac(T3)

abc(T3)
0
0

this option is wrong just because in question asking for longest possible prefixes

yes.

 

b(T1), bb(T2) , bba(T1) , bbaa(X) , bbaac(T3)

we get b by T2 but not by T1 .

0
0
because question is asking token that matches the longest possible prefix, thats why answer is T3T3 as first T3 is generating "bbaac" substring of length 5 which is longest prefix among all the possibilities from the option, thats why answer is (D)
0
0

I feel that from option c we can't generate string bbaacabc because in the ques it is said that "x?" means 0 or 1 occurrence of symbol x. So if we start with T2 then we can generate only a single b, from T1 we can generate only ba, from T3 we can generate only ac.. So from T2T1T3 we can generate only bbaac which is not the required string. So option c is wrong. Please check @Hira Thakur

0
0

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