• edited by
19,379 views
38 38 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)

5 Answers

31 31 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.

2 2 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 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:
Position:
Show:

Related questions

36 36 votes
11 11 answers
28.2k
28.2k views
admin asked Feb 15, 2023
28,197 views
Consider the Deterministic Finite-state Automaton ($\text{DFA}$) $\mathcal{A}$ shown below. The $\text{DFA}$ runs on the alphabet $\{0,1\}$, and has the set of states $\{...
27 27 votes
3 3 answers
18.1k
18.1k views
admin asked Feb 15, 2023
18,069 views
$f(x)$ and $g(y)$ are functions of $x$ and $y$, respectively, and $f(x)=g(y)$ for all values of $x$ and $y$. Which one of the following options is necessarily $\text{TRUE...
17 17 votes
3 3 answers
16.9k
16.9k views
admin asked Feb 15, 2023
16,894 views
Which of the following statements is/are $\text{CORRECT}?$The intersection of two regular languages is regular.The intersection of two context-free languages is context-f...
39 39 votes
8 8 answers
22.8k
22.8k views
admin asked Feb 15, 2023
22,834 views
Consider the context-free grammar $G$ below\[\begin{array}{l}S \rightarrow a S b \mid X \\X \rightarrow a X \mid X b \mid a \mid b,\end{array}\]where $S$ and $X$ are non-...