progs/lexer/lexer.sc
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 21 Oct 2023 09:09:09 +0100
changeset 943 5365ef60707e
parent 936 0b5f06539a84
child 944 f5d2453c5640
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
// A simple lexer inspired by work of Sulzmann & Lu
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
//==================================================
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
//
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
// Call the test cases with 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
//
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
//   amm lexer.sc small
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
//   amm lexer.sc fib
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
//   amm lexer.sc loops
793
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
     9
//   amm lexer.sc email
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
//
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
//   amm lexer.sc all
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    14
// regular expressions including records
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
abstract class Rexp 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
case object ZERO extends Rexp
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    17
case object ONE extends Rexp
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    18
case class CHAR(c: Char) extends Rexp
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    19
case class ALT(r1: Rexp, r2: Rexp) extends Rexp 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    20
case class SEQ(r1: Rexp, r2: Rexp) extends Rexp 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    21
case class STAR(r: Rexp) extends Rexp 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    22
case class RECD(x: String, r: Rexp) extends Rexp  
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    23
                // records for extracting strings or tokens
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    24
  
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    25
// values  
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    26
abstract class Val
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    27
case object Empty extends Val
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    28
case class Chr(c: Char) extends Val
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    29
case class Sequ(v1: Val, v2: Val) extends Val
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    30
case class Left(v: Val) extends Val
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    31
case class Right(v: Val) extends Val
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    32
case class Stars(vs: List[Val]) extends Val
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    33
case class Rec(x: String, v: Val) extends Val
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    34
   
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    35
// some convenience for typing in regular expressions
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    36
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    37
def charlist2rexp(s : List[Char]): Rexp = s match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
  case Nil => ONE
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
  case c::Nil => CHAR(c)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    40
  case c::s => SEQ(CHAR(c), charlist2rexp(s))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    41
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
implicit def string2rexp(s : String) : Rexp = 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
  charlist2rexp(s.toList)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    44
936
0b5f06539a84 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 846
diff changeset
    45
extension (s: String) {
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    46
  def | (r: Rexp) = ALT(s, r)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    47
  def | (r: String) = ALT(s, r)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    48
  def % = STAR(s)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    49
  def ~ (r: Rexp) = SEQ(s, r)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    50
  def ~ (r: String) = SEQ(s, r)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    51
  def $ (r: Rexp) = RECD(s, r)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    52
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    53
943
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    54
extension (r: Rexp) {
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    55
  def | (s: Rexp) = ALT(r, s)
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    56
  def % = STAR(r)
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    57
  def ~ (s: Rexp) = SEQ(r, s)
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    58
}
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    59
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    60
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    61
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    62
val r : Rexp = ("a" | "b").% 
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    63
println(r) 
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    64
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    65
def nullable(r: Rexp) : Boolean = r match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    66
  case ZERO => false
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    67
  case ONE => true
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    68
  case CHAR(_) => false
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    69
  case ALT(r1, r2) => nullable(r1) || nullable(r2)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    70
  case SEQ(r1, r2) => nullable(r1) && nullable(r2)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    71
  case STAR(_) => true
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    72
  case RECD(_, r1) => nullable(r1)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    73
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    74
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    75
def der(c: Char, r: Rexp) : Rexp = r match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    76
  case ZERO => ZERO
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    77
  case ONE => ZERO
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    78
  case CHAR(d) => if (c == d) ONE else ZERO
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    79
  case ALT(r1, r2) => ALT(der(c, r1), der(c, r2))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    80
  case SEQ(r1, r2) => 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    81
    if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    82
    else SEQ(der(c, r1), r2)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    83
  case STAR(r) => SEQ(der(c, r), STAR(r))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    84
  case RECD(_, r1) => der(c, r1)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    85
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    86
943
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
    87
println(der('a', ALT(STAR("a"), "b")))
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    88
742
b5b5583a3a08 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 725
diff changeset
    89
// extracts a string from a value
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    90
def flatten(v: Val) : String = v match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    91
  case Empty => ""
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    92
  case Chr(c) => c.toString
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    93
  case Left(v) => flatten(v)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    94
  case Right(v) => flatten(v)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    95
  case Sequ(v1, v2) => flatten(v1) ++ flatten(v2)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    96
  case Stars(vs) => vs.map(flatten).mkString
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    97
  case Rec(_, v) => flatten(v)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    98
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    99
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   100
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   101
// extracts an environment from a value;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   102
// used for tokenising a string
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   103
def env(v: Val) : List[(String, String)] = v match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   104
  case Empty => Nil
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   105
  case Chr(c) => Nil
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   106
  case Left(v) => env(v)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   107
  case Right(v) => env(v)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   108
  case Sequ(v1, v2) => env(v1) ::: env(v2)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   109
  case Stars(vs) => vs.flatMap(env)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   110
  case Rec(x, v) => (x, flatten(v))::env(v)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   111
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   112
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   113
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   114
// The injection and mkeps part of the lexer
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   115
//===========================================
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   116
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   117
def mkeps(r: Rexp) : Val = r match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   118
  case ONE => Empty
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   119
  case ALT(r1, r2) => 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   120
    if (nullable(r1)) Left(mkeps(r1)) else Right(mkeps(r2))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   121
  case SEQ(r1, r2) => Sequ(mkeps(r1), mkeps(r2))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   122
  case STAR(r) => Stars(Nil)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   123
  case RECD(x, r) => Rec(x, mkeps(r))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   124
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   125
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   126
def inj(r: Rexp, c: Char, v: Val) : Val = (r, v) match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   127
  case (STAR(r), Sequ(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   128
  case (SEQ(r1, r2), Sequ(v1, v2)) => Sequ(inj(r1, c, v1), v2)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   129
  case (SEQ(r1, r2), Left(Sequ(v1, v2))) => Sequ(inj(r1, c, v1), v2)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   130
  case (SEQ(r1, r2), Right(v2)) => Sequ(mkeps(r1), inj(r2, c, v2))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   131
  case (ALT(r1, r2), Left(v1)) => Left(inj(r1, c, v1))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   132
  case (ALT(r1, r2), Right(v2)) => Right(inj(r2, c, v2))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   133
  case (CHAR(d), Empty) => Chr(c) 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   134
  case (RECD(x, r1), _) => Rec(x, inj(r1, c, v))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   135
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   136
943
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
   137
5365ef60707e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 936
diff changeset
   138
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   139
// some "rectification" functions for simplification
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   140
def F_ID(v: Val): Val = v
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   141
def F_RIGHT(f: Val => Val) = (v:Val) => Right(f(v))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   142
def F_LEFT(f: Val => Val) = (v:Val) => Left(f(v))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   143
def F_ALT(f1: Val => Val, f2: Val => Val) = (v:Val) => v match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   144
  case Right(v) => Right(f2(v))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   145
  case Left(v) => Left(f1(v))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   146
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   147
def F_SEQ(f1: Val => Val, f2: Val => Val) = (v:Val) => v match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   148
  case Sequ(v1, v2) => Sequ(f1(v1), f2(v2))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   149
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   150
def F_SEQ_Empty1(f1: Val => Val, f2: Val => Val) = 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   151
  (v:Val) => Sequ(f1(Empty), f2(v))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   152
def F_SEQ_Empty2(f1: Val => Val, f2: Val => Val) = 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   153
  (v:Val) => Sequ(f1(v), f2(Empty))
826
b0352633bf48 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 800
diff changeset
   154
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   155
def F_ERROR(v: Val): Val = throw new Exception("error")
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   156
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   157
// simplification
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   158
def simp(r: Rexp): (Rexp, Val => Val) = r match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   159
  case ALT(r1, r2) => {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   160
    val (r1s, f1s) = simp(r1)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   161
    val (r2s, f2s) = simp(r2)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   162
    (r1s, r2s) match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   163
      case (ZERO, _) => (r2s, F_RIGHT(f2s))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   164
      case (_, ZERO) => (r1s, F_LEFT(f1s))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   165
      case _ => if (r1s == r2s) (r1s, F_LEFT(f1s))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   166
                else (ALT (r1s, r2s), F_ALT(f1s, f2s)) 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   167
    }
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   168
  }
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   169
  case SEQ(r1, r2) => {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   170
    val (r1s, f1s) = simp(r1)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   171
    val (r2s, f2s) = simp(r2)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   172
    (r1s, r2s) match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   173
      case (ZERO, _) => (ZERO, F_ERROR)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   174
      case (_, ZERO) => (ZERO, F_ERROR)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   175
      case (ONE, _) => (r2s, F_SEQ_Empty1(f1s, f2s))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   176
      case (_, ONE) => (r1s, F_SEQ_Empty2(f1s, f2s))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   177
      case _ => (SEQ(r1s,r2s), F_SEQ(f1s, f2s))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   178
    }
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   179
  }
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   180
  case r => (r, F_ID)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   181
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   182
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   183
// lexing functions including simplification
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   184
def lex_simp(r: Rexp, s: List[Char]) : Val = s match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   185
  case Nil => if (nullable(r)) mkeps(r) else 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   186
    { throw new Exception("lexing error") } 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   187
  case c::cs => {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   188
    val (r_simp, f_simp) = simp(der(c, r))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   189
    inj(r, c, f_simp(lex_simp(r_simp, cs)))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   190
  }
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   191
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   192
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   193
def lexing_simp(r: Rexp, s: String) = 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   194
  env(lex_simp(r, s.toList))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   195
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   196
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   197
// The Lexing Rules for the WHILE Language
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   198
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   199
def PLUS(r: Rexp) = r ~ r.%
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   200
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   201
def Range(s : List[Char]) : Rexp = s match {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   202
  case Nil => ZERO
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   203
  case c::Nil => CHAR(c)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   204
  case c::s => ALT(CHAR(c), Range(s))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   205
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   206
def RANGE(s: String) = Range(s.toList)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   207
800
9eea6a801e10 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 793
diff changeset
   208
val SYM = RANGE("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_")
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   209
val DIGIT = RANGE("0123456789")
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   210
val ID = SYM ~ (SYM | DIGIT).% 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   211
val NUM = PLUS(DIGIT)
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   212
val KEYWORD : Rexp = "skip" | "while" | "do" | "if" | "then" | "else" | "read" | "write" 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   213
val SEMI: Rexp = ";"
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   214
val OP: Rexp = ":=" | "=" | "-" | "+" | "*" | "!=" | "<" | ">"
846
3a535de22816 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 827
diff changeset
   215
val WHITESPACE = PLUS(" " | "\n" | "\t" | "\r")
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   216
val RPAREN: Rexp = "{"
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   217
val LPAREN: Rexp = "}"
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   218
val STRING: Rexp = "\"" ~ SYM.% ~ "\""
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   219
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   220
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   221
val WHILE_REGS = (("k" $ KEYWORD) | 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   222
                  ("i" $ ID) | 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   223
                  ("o" $ OP) | 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   224
                  ("n" $ NUM) | 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   225
                  ("s" $ SEMI) | 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   226
                  ("str" $ STRING) |
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   227
                  ("p" $ (LPAREN | RPAREN)) | 
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   228
                  ("w" $ WHITESPACE)).%
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   229
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   230
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   231
// Two Simple While Tests
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   232
//========================
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   233
827
67c8a6e6a305 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 826
diff changeset
   234
@arg(doc = "small tests")
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   235
@main
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   236
def small() = {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   237
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   238
  val prog0 = """read n"""
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   239
  println(s"test: $prog0")
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   240
  println(lexing_simp(WHILE_REGS, prog0))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   241
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   242
  val prog1 = """read  n; write n"""  
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   243
  println(s"test: $prog1")
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   244
  println(lexing_simp(WHILE_REGS, prog1))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   245
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   246
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   247
// Bigger Tests
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   248
//==============
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   249
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   250
// escapes strings and prints them out as "", "\n" and so on
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   251
def esc(raw: String): String = {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   252
  import scala.reflect.runtime.universe._
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   253
  Literal(Constant(raw)).toString
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   254
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   255
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   256
def escape(tks: List[(String, String)]) =
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   257
  tks.map{ case (s1, s2) => (s1, esc(s2))}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   258
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   259
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   260
val prog2 = """
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   261
write "Fib";
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   262
read n;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   263
minus1 := 0;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   264
minus2 := 1;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   265
while n > 0 do {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   266
  temp := minus2;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   267
  minus2 := minus1 + minus2;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   268
  minus1 := temp;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   269
  n := n - 1
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   270
};
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   271
write "Result";
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   272
write minus2
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   273
"""
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   274
827
67c8a6e6a305 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 826
diff changeset
   275
@arg(doc = "Fibonacci test")
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   276
@main
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   277
def fib() = {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   278
  println("lexing fib program")
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   279
  println(escape(lexing_simp(WHILE_REGS, prog2)).mkString("\n"))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   280
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   281
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   282
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   283
val prog3 = """
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   284
start := 1000;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   285
x := start;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   286
y := start;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   287
z := start;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   288
while 0 < x do {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   289
 while 0 < y do {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   290
  while 0 < z do {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   291
    z := z - 1
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   292
  };
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   293
  z := start;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   294
  y := y - 1
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   295
 };     
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   296
 y := start;
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   297
 x := x - 1
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   298
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   299
"""
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   300
827
67c8a6e6a305 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 826
diff changeset
   301
@arg(doc = "Loops test")
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   302
@main
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   303
def loops() = {
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   304
  println("lexing Loops")
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   305
  println(escape(lexing_simp(WHILE_REGS, prog3)).mkString("\n"))
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   306
}
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   307
827
67c8a6e6a305 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 826
diff changeset
   308
@arg(doc = "Email Test")
793
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   309
@main
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   310
def email() = {
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   311
  val lower = "abcdefghijklmnopqrstuvwxyz"
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   312
793
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   313
  val NAME = RECD("name", PLUS(RANGE(lower ++ "_.-")))
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   314
  val DOMAIN = RECD("domain", PLUS(RANGE(lower ++ "-")))
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   315
  val RE = RANGE(lower ++ ".")
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   316
  val TOPLEVEL = RECD("top", (RE ~ RE) |
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   317
                             (RE ~ RE ~ RE) | 
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   318
                             (RE ~ RE ~ RE ~ RE) | 
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   319
                             (RE ~ RE ~ RE ~ RE ~ RE) |
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   320
                             (RE ~ RE ~ RE ~ RE ~ RE ~ RE))
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   321
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   322
  val EMAIL = NAME ~ "@" ~ DOMAIN ~ "." ~ TOPLEVEL
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   323
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   324
  println(lexing_simp(EMAIL, "christian.urban@kcl.ac.uk"))
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   325
}
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   326
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   327
827
67c8a6e6a305 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 826
diff changeset
   328
@arg(doc = "All tests.")
725
f345e89895f5 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   329
@main
793
46cc69622a56 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 792
diff changeset
   330
def all() = { small(); fib() ; loops() ; email() } 
792
34132a854d03 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 757
diff changeset
   331
34132a854d03 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 757
diff changeset
   332
34132a854d03 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 757
diff changeset
   333
34132a854d03 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 757
diff changeset
   334
827
67c8a6e6a305 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 826
diff changeset
   335
// runs with amm2 and amm3
67c8a6e6a305 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 826
diff changeset
   336
67c8a6e6a305 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 826
diff changeset
   337
67c8a6e6a305 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 826
diff changeset
   338