progs/scala/re-ext.scala
author Christian Urban <urbanc@in.tum.de>
Sun, 05 Mar 2017 00:31:04 +0000
changeset 231 02fd56e2019e
parent 229 81c85f2746f5
child 234 18d19d039ac9
permissions -rw-r--r--
updated the re-ext-scala file
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
import scala.language.implicitConversions    
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
import scala.language.reflectiveCalls
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
import scala.annotation.tailrec   
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
import scala.io.Source
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
abstract class Rexp 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
case object ZERO extends Rexp
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
case object ONE extends Rexp
229
81c85f2746f5 updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
     9
case class CHARS(f: Char => Boolean) extends Rexp
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
case class ALT(r1: Rexp, r2: Rexp) extends Rexp 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
case class SEQ(r1: Rexp, r2: Rexp) extends Rexp 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
case class STAR(r: Rexp) extends Rexp 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
case class RECD(x: String, r: Rexp) extends Rexp
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
case class PLUS(r: Rexp) extends Rexp
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
case class OPT(r: Rexp) extends Rexp
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
case class NTIMES(r: Rexp, n: Int) extends Rexp
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
abstract class Val
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
case object Empty extends Val
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
case class Chr(c: Char) extends Val
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
case class Sequ(v1: Val, v2: Val) extends Val
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
case class Left(v: Val) extends Val
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
case class Right(v: Val) extends Val
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
case class Stars(vs: List[Val]) extends Val
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
case class Rec(x: String, v: Val) extends Val
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
   
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
// some convenience for typing in regular expressions
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
def charlist2rexp(s : List[Char]): Rexp = s match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
  case Nil => ONE
229
81c85f2746f5 updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    30
  case c::Nil => CHARS(_ == c)
81c85f2746f5 updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    31
  case c::s => SEQ(CHARS(_ == c), charlist2rexp(s))
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
implicit def string2rexp(s : String) : Rexp = charlist2rexp(s.toList)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
implicit def RexpOps(r: Rexp) = new {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  def | (s: Rexp) = ALT(r, s)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  def % = STAR(r)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  def ~ (s: Rexp) = SEQ(r, s)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
implicit def stringOps(s: String) = new {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  def | (r: Rexp) = ALT(s, r)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  def | (r: String) = ALT(s, r)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
  def % = STAR(s)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  def ~ (r: Rexp) = SEQ(s, r)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  def ~ (r: String) = SEQ(s, r)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
  def $ (r: Rexp) = RECD(s, r)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
def Alts(rs: List[Rexp]) : Rexp = rs match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
  case Nil => ZERO
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
  case r::Nil => r
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  case r::rs => ALT(r, Alts(rs))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
def ALTS(rs: Rexp*) = Alts(rs.toList)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
def Seqs(rs: List[Rexp]) : Rexp = rs match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  case Nil => ONE
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
  case r::Nil => r
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
  case r::rs => SEQ(r, Seqs(rs))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
def SEQS(rs: Rexp*) = Seqs(rs.toList)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
// nullable function: tests whether the regular 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
// expression can recognise the empty string
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
def nullable (r: Rexp) : Boolean = r match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
  case ZERO => false
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
  case ONE => true
229
81c85f2746f5 updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    70
  case CHARS(_) => false
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
  case ALT(r1, r2) => nullable(r1) || nullable(r2)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
  case SEQ(r1, r2) => nullable(r1) && nullable(r2)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
  case STAR(_) => true
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
  case RECD(_, r1) => nullable(r1)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
  case PLUS(r) => nullable(r)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
  case OPT(_) => true
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
  case NTIMES(r, n) => if (n == 0) true else nullable(r)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
// derivative of a regular expression w.r.t. a character
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
def der (c: Char, r: Rexp) : Rexp = r match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
  case ZERO => ZERO
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
  case ONE => ZERO
229
81c85f2746f5 updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    84
  case CHARS(f) => if (f(c)) ONE else ZERO
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
  case ALT(r1, r2) => ALT(der(c, r1), der(c, r2))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
  case SEQ(r1, r2) => 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
    if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
    else SEQ(der(c, r1), r2)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
  case STAR(r) => SEQ(der(c, r), STAR(r))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
  case RECD(_, r1) => der(c, r1)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
  case PLUS(r) => SEQ(der(c, r), STAR(r))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
  case OPT(r) => ALT(der(c, r), ZERO)
229
81c85f2746f5 updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
    93
  case NTIMES(r, n) => if (n == 0) ZERO else SEQ(der(c, r), NTIMES(r, n - 1))
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
// derivative w.r.t. a string (iterates der)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
@tailrec
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
def ders (s: List[Char], r: Rexp) : Rexp = s match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
  case Nil => r
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
  case c::s => ders(s, der(c, r))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
// extracts a string from value
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
def flatten(v: Val) : String = v match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
  case Empty => ""
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
  case Chr(c) => c.toString
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
  case Left(v) => flatten(v)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
  case Right(v) => flatten(v)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
  case Sequ(v1, v2) => flatten(v1) + flatten(v2)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
  case Stars(vs) => vs.map(flatten(_)).mkString
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
  case Rec(_, v) => flatten(v)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
// extracts an environment from a value
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
def env(v: Val) : List[(String, String)] = v match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
  case Empty => Nil
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
  case Chr(c) => Nil
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
  case Left(v) => env(v)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
  case Right(v) => env(v)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
  case Sequ(v1, v2) => env(v1) ::: env(v2)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
  case Stars(vs) => vs.flatMap(env)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
  case Rec(x, v) => (x, flatten(v))::env(v)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
// injection part
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
def mkeps(r: Rexp) : Val = r match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
  case ONE => Empty
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
  case ALT(r1, r2) => 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
    if (nullable(r1)) Left(mkeps(r1)) else Right(mkeps(r2))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
  case SEQ(r1, r2) => Sequ(mkeps(r1), mkeps(r2))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
  case STAR(r) => Stars(Nil)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
  case RECD(x, r) => Rec(x, mkeps(r))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
  case PLUS(r) => Stars(List(mkeps(r)))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
  case OPT(_) => Right(Empty)
229
81c85f2746f5 updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   136
  case NTIMES(r, n) => Stars(List.fill(n)(mkeps(r)))
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
def inj(r: Rexp, c: Char, v: Val) : Val = (r, v) match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
  case (STAR(r), Sequ(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
  case (SEQ(r1, r2), Sequ(v1, v2)) => Sequ(inj(r1, c, v1), v2)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
  case (SEQ(r1, r2), Left(Sequ(v1, v2))) => Sequ(inj(r1, c, v1), v2)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
  case (SEQ(r1, r2), Right(v2)) => Sequ(mkeps(r1), inj(r2, c, v2))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
  case (ALT(r1, r2), Left(v1)) => Left(inj(r1, c, v1))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
  case (ALT(r1, r2), Right(v2)) => Right(inj(r2, c, v2))
229
81c85f2746f5 updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   147
  case (CHARS(_), Empty) => Chr(c) 
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
  case (RECD(x, r1), _) => Rec(x, inj(r1, c, v))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
  case (PLUS(r), Sequ(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
  case (OPT(r), Left(v1)) => Left(inj(r, c, v1))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
  case (NTIMES(r, n), Sequ(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
// main unsimplified lexing function (produces a value)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
def lex(r: Rexp, s: List[Char]) : Val = s match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
  case Nil => if (nullable(r)) mkeps(r) else throw new Exception("Not matched")
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
  case c::cs => inj(r, c, lex(der(c, r), cs))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
def lexing(r: Rexp, s: String) : Val = lex(r, s.toList)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
// some "rectification" functions for simplification
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
def F_ID(v: Val): Val = v
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
def F_RIGHT(f: Val => Val) = (v:Val) => Right(f(v))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
def F_LEFT(f: Val => Val) = (v:Val) => Left(f(v))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
def F_ALT(f1: Val => Val, f2: Val => Val) = (v:Val) => v match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
  case Right(v) => Right(f2(v))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
  case Left(v) => Left(f1(v))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
def F_SEQ(f1: Val => Val, f2: Val => Val) = (v:Val) => v match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
  case Sequ(v1, v2) => Sequ(f1(v1), f2(v2))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
def F_SEQ_Empty1(f1: Val => Val, f2: Val => Val) = (v:Val) => Sequ(f1(Empty), f2(v))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
def F_SEQ_Empty2(f1: Val => Val, f2: Val => Val) = (v:Val) => Sequ(f1(v), f2(Empty))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
def F_RECD(f: Val => Val) = (v:Val) => v match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
  case Rec(x, v) => Rec(x, f(v))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
def F_ERROR(v: Val): Val = throw new Exception("error")
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
// simplification of regular expressions returning also an
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
// rectification function; no simplification under STAR 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
def simp(r: Rexp): (Rexp, Val => Val) = r match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
  case ALT(r1, r2) => {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
    val (r1s, f1s) = simp(r1)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
    val (r2s, f2s) = simp(r2)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
    (r1s, r2s) match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
      case (ZERO, _) => (r2s, F_RIGHT(f2s))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
      case (_, ZERO) => (r1s, F_LEFT(f1s))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
      case _ => if (r1s == r2s) (r1s, F_LEFT(f1s))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
                else (ALT (r1s, r2s), F_ALT(f1s, f2s)) 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
    }
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
  }
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
  case SEQ(r1, r2) => {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
    val (r1s, f1s) = simp(r1)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
    val (r2s, f2s) = simp(r2)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
    (r1s, r2s) match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
      case (ZERO, _) => (ZERO, F_ERROR)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
      case (_, ZERO) => (ZERO, F_ERROR)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
      case (ONE, _) => (r2s, F_SEQ_Empty1(f1s, f2s))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
      case (_, ONE) => (r1s, F_SEQ_Empty2(f1s, f2s))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
      case _ => (SEQ(r1s,r2s), F_SEQ(f1s, f2s))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
    }
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
  }
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
  case RECD(x, r1) => {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
    val (r1s, f1s) = simp(r1)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
    (RECD(x, r1s), F_RECD(f1s))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
  }
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
  case r => (r, F_ID)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
def lex_simp(r: Rexp, s: List[Char]) : Val = s match {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
  case Nil => if (nullable(r)) mkeps(r) else throw new Exception("Not matched")
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
  case c::cs => {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
    val (r_simp, f_simp) = simp(der(c, r))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
    inj(r, c, f_simp(lex_simp(r_simp, cs)))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
  }
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
def lexing_simp(r: Rexp, s: String) : Val = lex_simp(r, s.toList)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
// Some Tests
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
//============
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
def time_needed[T](i: Int, code: => T) = {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
  val start = System.nanoTime()
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
  for (j <- 1 to i) code
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
  val end = System.nanoTime()
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
  (end - start)/(i * 1.0e9)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
val r0 = ("a" | "ab") ~ ("b" | "")
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
println(lexing(r0, "ab"))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
println(lexing_simp(r0, "ab"))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
val r1 = ("a" | "ab") ~ ("bcd" | "cd")
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
println(lexing_simp(r1, "abcd"))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
println(lexing_simp((("" | "a") ~ ("ab" | "b")), "ab"))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
println(lexing_simp((("" | "a") ~ ("b" | "ab")), "ab"))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
println(lexing_simp((("" | "a") ~ ("c" | "ab")), "ab"))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
// Two Simple Tests for the While Language
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
//========================================
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
// Lexing Rules 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
231
02fd56e2019e updated the re-ext-scala file
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   252
val SYM = CHARS ("abcdefghijklmnopqrstuvwxyz" contains _)
02fd56e2019e updated the re-ext-scala file
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   253
val DIGIT = CHARS("0123456789" contains _)
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
val ID = SYM ~ (SYM | DIGIT).% 
231
02fd56e2019e updated the re-ext-scala file
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   255
val NUM = PLUS(DIGIT)
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
val KEYWORD : Rexp = "skip" | "while" | "do" | "if" | "then" | "else" | "read" | "write" | "true" | "false"
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
val SEMI: Rexp = ";"
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
val OP: Rexp = ":=" | "==" | "-" | "+" | "*" | "!=" | "<" | ">" | "<=" | ">=" | "%" | "/"
231
02fd56e2019e updated the re-ext-scala file
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   259
val WHITESPACE = PLUS(" " | "\n" | "\t")
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
val RPAREN: Rexp = ")"
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
val LPAREN: Rexp = "("
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
val BEGIN: Rexp = "{"
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
val END: Rexp = "}"
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
val STRING: Rexp = "\"" ~ SYM.% ~ "\""
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
val WHILE_REGS = (("k" $ KEYWORD) | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
                  ("i" $ ID) | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
                  ("o" $ OP) | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
                  ("n" $ NUM) | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
                  ("s" $ SEMI) | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
                  ("str" $ STRING) |
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
                  ("p" $ (LPAREN | RPAREN)) | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
                  ("b" $ (BEGIN | END)) | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
                  ("w" $ WHITESPACE)).%
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   277
/*
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
val WHILE_REGS = (KEYWORD | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
                  ID | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
                  OP | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
                  NUM | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
                  SEMI | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
                  LPAREN | RPAREN | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
                  BEGIN | END | 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
                  WHITESPACE).%
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
*/
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
println("prog0 test")
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
val prog0 = """read n"""
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
println(env(lexing_simp(WHILE_REGS, prog0)))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
println("prog1 test")
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
val prog1 = """read  n; write (n)"""
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
println(env(lexing_simp(WHILE_REGS, prog1)))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
// Bigger Test
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
//=============
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
val prog2 = """
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
i := 2;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
max := 100;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
while i < max do {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
  isprime := 1;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
  j := 2;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
  while (j * j) <= i + 1  do {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
    if i % j == 0 then isprime := 0  else skip;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
    j := j + 1
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
  };
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
  if isprime == 1 then write i else skip;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
  i := i + 1
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
}"""
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
println("prog2 test - tokens")
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
println(env(lexing_simp(WHILE_REGS, prog2)))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
val prog3 = """
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
write "fib";
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
read n;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
minus1 := 0;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
minus2 := 1;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
while n > 0 do {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
  temp := minus2;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
  minus2 := minus1 + minus2;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
  minus1 := temp;
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
  n := n - 1
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
};
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
write "result";
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
write minus2
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
"""
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
println("prog3 test - tokens")
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
println(env(lexing_simp(WHILE_REGS, prog3)))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
231
02fd56e2019e updated the re-ext-scala file
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   338
println("prog2 replicated test")
02fd56e2019e updated the re-ext-scala file
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   339
02fd56e2019e updated the re-ext-scala file
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   340
for (i <- 1 to 88) {
02fd56e2019e updated the re-ext-scala file
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   341
  println(i + ": " + "%.5f".format(time_needed(2, lexing_simp(WHILE_REGS, prog2 * i))))
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   342
}
231
02fd56e2019e updated the re-ext-scala file
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   343
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   344
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
// Sulzmann's tests
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
//==================
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
val sulzmann = ("a" | "b" | "ab").%
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
println(lexing_simp(sulzmann, "a" * 10))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
for (i <- 1 to 4501 by 500) {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
  println(i + ": " + "%.5f".format(time_needed(1, lexing_simp(sulzmann, "a" * i))))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
for (i <- 1 to 2001 by 500) {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
  println(i + ": " + "%.5f".format(time_needed(1, lexing_simp(sulzmann, "ab" * i))))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
// first benchmark regex 
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   362
//=======================
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   363
229
81c85f2746f5 updated
Christian Urban <urbanc@in.tum.de>
parents: 167
diff changeset
   364
val reWord = CHARS("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" contains _)
167
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   365
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   366
val reWordStar = STAR(reWord)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
val reWordPlus = reWord ~ reWordStar
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
val optionSet1 = "-" | "+" | "."
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
val optionSet2 = "-" | "."
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
val atTheRate = "@"
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
val period = "."
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
val optionSet3 = "," | ";"
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
val whitespace = " "
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
val re01 = reWordPlus
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
val re02 = STAR(optionSet1 ~ reWordPlus)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
val re03 = atTheRate
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
val re04 = reWordPlus
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
val re05 = STAR(optionSet2 ~ reWordPlus)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   380
val re06 = period
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
val re07 = reWordPlus
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
val re08 = re05
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
val re09 = optionSet3
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
val re10 = STAR(whitespace)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
val re11 = reWordPlus
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
val re12 = re02
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
val re13 = atTheRate
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
val re14 = reWordPlus
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
val re15 = re05
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
val re16 = period
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
val re17 = reWordPlus
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
val re18 = re05
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
val re01_08 = SEQS(re01, re02, re03, re04, re05, re06, re07, re08)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   397
val re09_10 = re09 ~ re10
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
val re11_18 = re01_08
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
val re = re01_08 ~ STAR(re09_10 ~ re11_18)
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
def process(s: String, i: Int) : Unit = {
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
  println(i + " " + "%.5f".format(time_needed(1, lexing(re, s))))
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
}
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
val filename = "../tests/emails.txt"
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
val filelines = Source.fromFile(filename).getLines.take(76).zipWithIndex
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
filelines.foreach({ case (s: String, i: Int) => process(s, i) })
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
1b2b9000be88 added an extended version of re-simp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   413