progs/display/thompson1.scala
changeset 488 598741d39d21
parent 487 a697421eaa04
child 491 d5776c6018f0
equal deleted inserted replaced
487:a697421eaa04 488:598741d39d21
    14     new TState(counter - 1)
    14     new TState(counter - 1)
    15   }
    15   }
    16 }
    16 }
    17 
    17 
    18 
    18 
    19 // some types abbreviations
    19 // a type abbreviation
    20 type NFAt = NFA[TState, Char]
    20 type NFAt = NFA[TState, Char]
    21 
    21 
    22 
    22 
    23 // NFA that does not accept any string
    23 // a NFA that does not accept any string
    24 def NFA_ZERO(): NFAt = {
    24 def NFA_ZERO(): NFAt = {
    25   val Q = TState()
    25   val Q = TState()
    26   NFA(Set(Q), { case _ => Set() }, Set())
    26   NFA(Set(Q), { case _ => Set() }, Set())
    27 }
    27 }
    28 
    28 
    29 // NFA that accepts the empty string
    29 // a NFA that accepts the empty string
    30 def NFA_ONE() : NFAt = {
    30 def NFA_ONE() : NFAt = {
    31   val Q = TState()
    31   val Q = TState()
    32   NFA(Set(Q), { case _ => Set() }, Set(Q))
    32   NFA(Set(Q), { case _ => Set() }, Set(Q))
    33 }
    33 }
    34 
    34 
    35 // NFA that accepts the string "c"
    35 // a NFA that accepts the string "c"
    36 def NFA_CHAR(c: Char) : NFAt = {
    36 def NFA_CHAR(c: Char) : NFAt = {
    37   val Q1 = TState()
    37   val Q1 = TState()
    38   val Q2 = TState()
    38   val Q2 = TState()
    39   NFA(Set(Q1), { case (Q1, d) if (c == d) => Set(Q2) }, Set(Q2))
    39   NFA(Set(Q1), { case (Q1, d) if (c == d) => Set(Q2) }, Set(Q2))
    40 }
    40 }