World's most popular travel blog for travel bloggers.

A DFA for recognizing comments

, , No Comments
Problem Detail: 

The following DFA is a lexical analyzer which is supposed to recognize comments. The lexical analyzer will ignore the comment and goes back to the state one. I'm told that there's something wrong with it but I can't figure it out. What's the problem?

enter image description here

FWIW, those tiny signs are stars which are necessary for C-style comment: "/* comment */"
The loop in the state three is "except *"

Asked By : Gigili

Answered By : Janoma

  • There is no initial state, so there's no automaton. I suppose $1$ is the initial state.
  • From state 4 you can still read several times the symbol $*$ and accept the comment. For example, the coment /*hello*/ is being accepted, but the comment /*hello**/ is not. So you need $\delta(4,*)=4$.
  • Also, you need more transitions for the automaton to be a DFA. Remember that a DFA has a defined transition for all symbols from all states.
    • For example, you need transitions from $4$ with other symbols ($\delta(4,x)=3$ for $x\in\Sigma\smallsetminus\{*,/\}$).
    • The same goes for $1$ and $2$, but I leave that as an exercise ;-)
Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/396

0 comments:

Post a Comment

Let us know your responses and feedback