Domanda

Pls see the following DFA http://i.stack.imgur.com/iH3RM.png

created via JFLAP. When I convert to regex, JFLAP gives:

  p+(q+pq)(pq)*(λ+p)

When I paste it in the Scala REPL :

  scala> val regex = "p+(q+pq)(pq)*(+p)".r
  java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 14
  p+(q+pq)(pq)*(+p)
                ^
      at java.util.regex.Pattern.error(Unknown Source)

I have two simple questions.

  1. Is that the right regex ? Why does it include a λ ?

  2. How do I use it in Scala since the λ doesn't show up correctly when I paste in repl ?

È stato utile?

Soluzione

In formal regular expression notation + means "or". The regex you want to use is something like:

p|(q|pq)(pq)*p?
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top