edited by
8,625 views
8 votes
8 votes

Consider the following definition of a lexical token $\textbf{id}$ for an identifier in a programming language, using extended regular expressions:
\[
\begin{array}{ll}
\textbf{ letter } & \rightarrow[\mathrm{A}-\mathrm{Za}-\mathrm{z}] \\
\textbf{ digit } & \rightarrow[0-9] \\
\textbf{ id } & \rightarrow \textbf{ letter }(\textbf{ letter } \mid \textbf{ digit })^{*}
\end{array}
\]
Which one of the following Non-deterministic Finite-state Automata with $\epsilon$-transitions accepts the set of valid identifiers? (A double-circle denotes a final state)

edited by

4 Answers

8 votes
8 votes

The regular expression is given as $\text{letter(letter+digit)*}$.

This regular expression accepts the strings of one occurrence of a letter followed by any occurrence of letter and digits, such as $\text{(letter,letter.letter,letter.digit,letter.digit.digit..$\infty$)}$

Option (A) This is wrong because it also accepts empty string that is  $\epsilon$.

 

Option (B): 

This is wrong because it accepts strings like $\text{(letter), (letter.letter) ...(letter.digit) ,(letter.digit.digit)}$, but it will not accepts the strings like $\text{(letter.digit.letter)}$. 

Option (C): It is the correct option. it will accepts all the strings of $\text{letter(letter+digit)*}$.

Option (D):

it is wrong. it RE is $\text{(letter(letter. digit)*)}$

and it will accept strings like ${(letter),(letter.letter.digit).(letter.letter.digit.letter.digit)...\infty}$.

 it will not accepts strings like $(letter. letter),(letter. digit)$ etc.

1 votes
1 votes

The regular expression is given as $\text{letter(letter+digit)*}$.

This regular expression accepts the strings of one occurrence of a letter followed by any occurrence of letter and digits, such as $\text{(letter,letter.letter,letter.digit,letter.digit.digit..$\infty$)}$

Option (A):

This is wrong because it accepts strings like $\text{(letter), (letter.letter) ...(letter.digit) ,(letter.digit.digit)}$, but it will not accepts the strings like $\text{(letter.digit.letter)}$. 

Option (B): It is correct.

Option (C):

it is wrong. it RE is $\text{(letter(letter. digit)*)}$ and it will accept strings like ${(letter),(letter.letter.digit),(letter.letter.digit.letter.digit)...\infty}$.

 it will not accepts strings like $(letter. letter),(letter. digit)$ etc.

0 votes
0 votes
A is wrong bcoz it is accepting null.

B is wrong bcoz what if letter digit letter comes.

D is wrong bcoz letter digit is not accepted.

C is correct.
Answer:

Related questions

14 votes
14 votes
3 answers
4
admin asked Feb 15, 2023
6,702 views
Which one of the following sequences when stored in an array at locations $A , \ldots, A[10]$ forms a max-heap?$23,17,10,6,13,14,1,5,7,12$$23,17,14,7,13,10,1,5,6,12$$23,1...