progs/re-sulzmann.scala
author cu
Tue, 10 Oct 2017 18:53:30 +0100
changeset 516 ff643cbb7142
parent 95 dbe49327b6c5
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
import scala.language.implicitConversions
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
import scala.language.reflectiveCalls
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
abstract class Rexp
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
case object NULL extends Rexp
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
case object EMPTY extends Rexp
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
case class CHAR(c: Char) extends Rexp
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
case class ALT(r1: Rexp, r2: Rexp) extends Rexp 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
case class SEQ(r1: Rexp, r2: Rexp) extends Rexp 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
case class STAR(r: Rexp) extends Rexp 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
abstract class Pat
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
case class VAR(x: String, w: String, r: Rexp) extends Pat
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
case class GRP(x: String, w: String, p: Pat) extends Pat
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
case class PSEQ(p1: Pat, p2: Pat) extends Pat
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
case class PALT(p1: Pat, p2: Pat) extends Pat
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
case class PSTAR(p: Pat) extends Pat
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
object VAR { def apply(x: String, r: Rexp) : VAR = VAR(x, "", r) }
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
object GRP { def apply(x: String, p: Pat) : GRP = GRP(x, "", p) }
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
def nullable (r: Rexp) : Boolean = r match {
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  case NULL => false
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  case EMPTY => true
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  case CHAR(_) => false
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
  case ALT(r1, r2) => nullable(r1) || nullable(r2)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
  case SEQ(r1, r2) => nullable(r1) && nullable(r2)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  case STAR(_) => true
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
// derivative of a regular expression w.r.t. a character
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
def der (c: Char, r: Rexp) : Rexp = r match {
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  case NULL => NULL
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  case EMPTY => NULL
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  case CHAR(d) => if (c == d) EMPTY else NULL
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  case ALT(r1, r2) => ALT(der(c, r1), der(c, r2))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  case SEQ(r1, r2) => 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
    if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
    else SEQ(der(c, r1), r2)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  case STAR(r) => SEQ(der(c, r), STAR(r))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    46
def down (p: Pat) : Rexp = p match {
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
  case VAR(x: String, w: String, r: Rexp) => r
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
  case GRP(x: String, w: String, p: Pat) => down(p)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
  case PSEQ(p1: Pat, p2: Pat) => SEQ(down(p1), down(p2))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  case PALT(p1: Pat, p2: Pat) => ALT(down(p1), down(p2))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
  case PSTAR(p: Pat) => STAR(down(p))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    54
def empty (p: Pat) : Pat = p match {
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  case VAR(x: String, w: String, r: Rexp) => 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
    if (nullable(r)) VAR(x, w, EMPTY) 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
    else VAR(x, w, NULL)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  case GRP(x: String, w: String, p: Pat) => GRP(x, w, empty(p))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
  case PSEQ(p1: Pat, p2: Pat) => PSEQ(empty(p1), empty(p2))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
  case PALT(p1: Pat, p2: Pat) => PALT(empty(p1), empty(p2))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
  case PSTAR(p: Pat) => PSTAR(empty(p))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    64
def patder (c: Char, p: Pat) : Pat = p match {
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
  case VAR(x: String, w: String, r: Rexp) => VAR(x, w + c, der(c, r))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
  case GRP(x: String, w: String, p: Pat) => GRP(x, w + c, patder(c, p))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  case PSEQ(p1: Pat, p2: Pat) => 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
    if (nullable(down(p1))) PALT(PSEQ(patder(c, p1), p2), PSEQ(empty(p1), patder(c, p2)))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
    else PSEQ(patder(c, p1), p2)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
  case PALT(p1: Pat, p2: Pat) => PALT(patder(c, p1), patder(c, p2))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
  case PSTAR(p: Pat) => PSEQ(patder(c, p), PSTAR(p))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
def patders (s: List[Char], p: Pat) : Pat = s match {
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
  case Nil => p
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
  case c::s => patders(s, patder(c, p))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
type Env = Set[List[(String, String)]]
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    81
def special (p: Pat, env: Env) : Env = 
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
  if (env == Set() && nullable(down(p))) Set(Nil) else env
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    84
def env (p: Pat) : Env = p match {
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
  case VAR(x: String, w: String, r: Rexp) => 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
    if (nullable(r)) Set(List((x, w))) else Set()
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
  case GRP(x: String, w: String, p1: Pat) => 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
    special(p, for (e <- env(p1)) yield List((x, w)) ++ e)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
  case PSEQ(p1: Pat, p2: Pat) => 
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
    special(p, for (e1 <- env(p1); e2 <- env(p2)) yield (e1 ++ e2))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
  case PALT(p1: Pat, p2: Pat) => special(p, env(p1) ++ env(p2))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
  case PSTAR(p1: Pat) => special(p, env(p1))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    95
def matcher (p: Pat, s: String) = env(empty(patders(s.toList, p)))
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
// some convenience for typing in regular expressions
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    99
def charlist2rexp (s : List[Char]) : Rexp = s match {
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
  case Nil => EMPTY
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
  case c::Nil => CHAR(c)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
  case c::s => SEQ(CHAR(c), charlist2rexp(s))
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
}
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   104
implicit def string2rexp (s : String) : Rexp = charlist2rexp(s.toList)
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   106
implicit def RexpOps (r: Rexp) = new {
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
  def | (s: Rexp) = ALT(r, s)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
  def % = STAR(r)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
  def ~ (s: Rexp) = SEQ(r, s)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   112
implicit def stringOps (s: String) = new {
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
  def | (r: Rexp) = ALT(s, r)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
  def | (r: String) = ALT(s, r)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
  def % = STAR(s)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
  def ~ (r: Rexp) = SEQ(s, r)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
  def ~ (r: String) = SEQ(s, r)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   120
implicit def PatOps (p: Pat) = new {
94
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
  def | (q: Pat) = PALT(p, q)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
  def % = PSTAR(p)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
  def ~ (q: Pat) = PSEQ(p, q)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
}
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
val p0 = VAR("x", "A")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
patders("A".toList, p0)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
matcher(p0, "A")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
val p1 = VAR("x", "A") | VAR("y", "A") | VAR("z", "B")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
patders("A".toList, p1)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
matcher(p1, "A")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
matcher(p1, "B")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
val p2 = VAR("x", "AB")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
matcher(p2, "AB")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
matcher(p2, "AA")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
val p3 = VAR("x", "A" ~ "B")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
matcher(p3, "AB")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
matcher(p3, "AA")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
val p4 = VAR("x", "A") ~ VAR("y", "B")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
matcher(p4, "AB")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
matcher(p4, "AA")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
val p5 = VAR("x", "A".%)
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
matcher(p5, "A")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
matcher(p5, "AA")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
matcher(p5, "")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
matcher(p5, "AAA")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
val p6 = VAR("x", "A").%
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
matcher(p6, "A")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
matcher(p6, "AA")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
matcher(p6, "")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
matcher(p6, "AAA")
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
val p7 = (VAR("x", "A") | VAR("y", "AB") | VAR("z", "B")).%
9ea667baf097 added first part of the Sulzmann paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
matcher(p7, "AB")
95
dbe49327b6c5 added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   164