testing4/re.scala
author Christian Urban <urbanc@in.tum.de>
Thu, 06 Dec 2018 21:49:43 +0000
changeset 236 e461b5325b5e
parent 229 5549016ab10f
child 249 1997cfcd6334
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
// Part 1 about Regular Expression Matching
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
//==========================================
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
     4
// Regular Expressions
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
abstract class Rexp
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
case object ZERO extends Rexp
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
case object ONE extends Rexp
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
case class CHAR(c: Char) extends Rexp
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
     9
case class ALT(r1: Rexp, r2: Rexp) extends Rexp   // alternative 
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    10
case class SEQ(r1: Rexp, r2: Rexp) extends Rexp   // sequence
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    11
case class STAR(r: Rexp) extends Rexp             // star
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    13
 
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    14
// some convenience for typing regular expressions
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    16
import scala.language.implicitConversions    
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    17
import scala.language.reflectiveCalls 
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    18
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
def charlist2rexp(s: List[Char]): Rexp = s match {
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  case Nil => ONE
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  case c::Nil => CHAR(c)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  case c::s => SEQ(CHAR(c), charlist2rexp(s))
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
implicit def string2rexp(s: String): Rexp = charlist2rexp(s.toList)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
implicit def RexpOps (r: Rexp) = new {
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  def | (s: Rexp) = ALT(r, s)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  def % = STAR(r)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  def ~ (s: Rexp) = SEQ(r, s)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
implicit def stringOps (s: String) = new {
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  def | (r: Rexp) = ALT(s, r)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  def | (r: String) = ALT(s, r)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
  def % = STAR(s)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  def ~ (r: Rexp) = SEQ(s, r)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  def ~ (r: String) = SEQ(s, r)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    40
// (1) Complete the function nullable according to
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    41
// the definition given in the coursework; this 
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
// function checks whether a regular expression
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    43
// can match the empty string and Returns a boolean
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    44
// accordingly.
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    46
def nullable (r: Rexp) : Boolean = r match {
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    47
    case ZERO => false
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    48
    case ONE => true
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    49
    case CHAR(_) => false
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    50
    case ALT(r1, r2) => nullable(r1) | nullable(r2)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    51
    case SEQ(r1, r2) => nullable(r1) & nullable(r2)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    52
    case STAR(_) => true
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    55
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    56
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    57
// (2) Complete the function der according to
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
// the definition given in the coursework; this
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    59
// function calculates the derivative of a 
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    60
// regular expression w.r.t. a character.
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    62
//TODO: debug
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    63
//TODO: understand this more. 
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    64
// first test runs
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    65
// test 2 fails
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    66
// test 3 runs
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    67
// test 4 runs
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    68
def der (c: Char, r: Rexp) : Rexp = r match {
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    69
    //TODO: debug
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    70
    case ZERO => ZERO
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    71
    case ONE => ZERO
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    72
    case CHAR(r1) => if (c == r1) ONE else ZERO
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    73
    case ALT(r1, r2) => ALT(der(c, r1), der(c, r2))
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    74
    case SEQ(r1, r2) => if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2)) else SEQ(der(c, r1), r2)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    75
    case STAR(r1) => SEQ(der(c, r1), STAR(r1))
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    78
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    79
// (3) Complete the simp function according to
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
// the specification given in the coursework; this
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    81
// function simplifies a regular expression from
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    82
// the inside out, like you would simplify arithmetic 
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    83
// expressions; however it does not simplify inside 
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
    84
// STAR-regular expressions.
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
    86
def simp(r: Rexp) : Rexp = r match {
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    87
    case STAR(_) => r
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    88
    case SEQ(r1, r2) => (simp(r1), simp(r2)) match { // potential failure
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    89
        case (_, ZERO) => ZERO
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    90
        case (ZERO, _) => ZERO
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    91
        case (r1, ONE) => simp(r1)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    92
        case (ONE, r2) => simp(r2)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    93
        case (r1, r2) => SEQ(r1, r2)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    94
    }
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    95
    case ALT(r1, r2) => (simp(r1), simp(r2)) match {
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    96
        case (r1, ZERO) => simp(r1)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    97
        case (ZERO, r1) => simp(r1)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    98
        case (r1, r2) if r1 == r2 => simp(r1)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
    99
        case (r1, r2) => ALT(r1, r2)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   100
    }
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   101
    case r => r
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   104
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   105
// (4) Complete the two functions below; the first 
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
// calculates the derivative w.r.t. a string; the second
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
// is the regular expression matcher taking a regular
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
// expression and a string and checks whether the
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   109
// string matches the regular expression
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   111
def ders (s: List[Char], r: Rexp) : Rexp = s match {
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   112
    case Nil => r
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   113
    case c::cs => ders(cs, simp(der(c, r)))
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   116
def matcher(r: Rexp, s: String): Boolean = {
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   117
    nullable(ders(s.toList, r))
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   118
}
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   119
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   121
// (5) Complete the size function for regular
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   122
// expressions according to the specification 
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
// given in the coursework.
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   125
def size(r: Rexp): Int = r match {
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   126
    case ZERO => 1
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   127
    case ONE => 1
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   128
    case CHAR(_) => 1
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   129
    case SEQ(r1, r2) => 1 + size(r1) + size(r2)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   130
    case ALT(r1, r2) => 1 + size(r1) + size(r2)
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   131
    case STAR(r1) => 1 + size(r1)
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
228
33c2655be47d updated
Christian Urban <urbanc@in.tum.de>
parents: 221
diff changeset
   134
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   135
// some testing data
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   137
//matcher(("a" ~ "b") ~ "c", "abc")  // => true
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   138
//matcher(("a" ~ "b") ~ "c", "ab")   // => false
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   139
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   140
// the supposedly 'evil' regular expression (a*)* b
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   141
val EVIL = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   142
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   143
//matcher(EVIL, "a" * 1000 ++ "b")   // => true
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   144
//matcher(EVIL, "a" * 1000)          // => false
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
// size without simplifications
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   147
//size(der('a', der('a', EVIL)))             // => 28
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   148
//size(der('a', der('a', der('a', EVIL))))   // => 58
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   149
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   150
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
// size with simplification
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   153
//size(simp(der('a', der('a', EVIL))))           // => 8
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   154
//size(simp(der('a', der('a', der('a', EVIL))))) // => 8
228
33c2655be47d updated
Christian Urban <urbanc@in.tum.de>
parents: 221
diff changeset
   155
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   156
// Python needs around 30 seconds for matching 28 a's with EVIL. 
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   157
// Java 9 and later increase this to an "astonishing" 40000 a's in
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   158
// 30 seconds.
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
//
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   160
// Lets see how long it really takes to match strings with 
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   161
// 5 Million a's...it should be in the range of a couple
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   162
// of seconds.
153
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
def time_needed[T](i: Int, code: => T) = {
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
  val start = System.nanoTime()
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  for (j <- 1 to i) code
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
  val end = System.nanoTime()
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
  (end - start)/(i * 1.0e9)
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
}
4383809c176a updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   171
//for (i <- 0 to 5000000 by 500000) {
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   172
//  println(i + " " + "%.5f".format(time_needed(2, matcher(EVIL, "a" * i))))
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   173
//}
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   174
229
5549016ab10f updated
Christian Urban <urbanc@in.tum.de>
parents: 228
diff changeset
   175
// another "power" test case 
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   176
println(simp(Iterator.iterate(ONE:Rexp)(r => ALT(r, r)).drop(40).next))
221
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   177
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   178
// the Iterator produces the rexp
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   179
//
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   180
//      SEQ(SEQ(SEQ(..., ONE | ONE) , ONE | ONE), ONE | ONE)
9e7897f25e13 updated
Christian Urban <urbanc@in.tum.de>
parents: 215
diff changeset
   181
//
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   182
//    where SEQ is nested 50 times.
228
33c2655be47d updated
Christian Urban <urbanc@in.tum.de>
parents: 221
diff changeset
   183
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 229
diff changeset
   184