author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Mon, 22 Feb 2016 22:09:31 +0000 | |
changeset 397 | cf3ca219c727 |
parent 392 | 2d0a59127694 |
permissions | -rw-r--r-- |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
1 |
import scala.language.implicitConversions |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
import scala.language.reflectiveCalls |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
3 |
import scala.annotation.tailrec |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
5 |
abstract class Rexp |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
case object NULL extends Rexp |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
case object EMPTY extends Rexp |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
case class CHAR(c: Char) extends Rexp |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
9 |
case class ALT(r1: Rexp, r2: Rexp) extends Rexp |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
10 |
case class SEQ(r1: Rexp, r2: Rexp) extends Rexp |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
11 |
case class STAR(r: Rexp) extends Rexp |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
12 |
case class RECD(x: String, r: Rexp) extends Rexp |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
13 |
case class CRANGE(cs: String) extends Rexp |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
14 |
case class PLUS(r: Rexp) extends Rexp |
368
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
367
diff
changeset
|
15 |
case class OPT(r: Rexp) extends Rexp |
385
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
16 |
case class NTIMES(r: Rexp, n: Int) extends Rexp |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
18 |
abstract class Val |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
19 |
case object Empty extends Val |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
20 |
case class Chr(c: Char) extends Val |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
21 |
case class Seq(v1: Val, v2: Val) extends Val |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
22 |
case class Left(v: Val) extends Val |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
23 |
case class Right(v: Val) extends Val |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
24 |
case class Stars(vs: List[Val]) extends Val |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
25 |
case class Rec(x: String, v: Val) extends Val |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
26 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
27 |
// some convenience for typing in regular expressions |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
28 |
def charlist2rexp(s : List[Char]): Rexp = s match { |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
case Nil => EMPTY |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
case c::Nil => CHAR(c) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
case c::s => SEQ(CHAR(c), charlist2rexp(s)) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
} |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
implicit def string2rexp(s : String) : Rexp = charlist2rexp(s.toList) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
|
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
implicit def RexpOps(r: Rexp) = new { |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
def | (s: Rexp) = ALT(r, s) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
def % = STAR(r) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
def ~ (s: Rexp) = SEQ(r, s) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
} |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
|
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
implicit def stringOps(s: String) = new { |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
def | (r: Rexp) = ALT(s, r) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
def | (r: String) = ALT(s, r) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
def % = STAR(s) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
def ~ (r: Rexp) = SEQ(s, r) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
def ~ (r: String) = SEQ(s, r) |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
47 |
def $ (r: Rexp) = RECD(s, r) |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
} |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
50 |
// nullable function: tests whether the regular |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
51 |
// expression can recognise the empty string |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
def nullable (r: Rexp) : Boolean = r match { |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
case NULL => false |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
case EMPTY => true |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
case CHAR(_) => false |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
56 |
case ALT(r1, r2) => nullable(r1) || nullable(r2) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
case SEQ(r1, r2) => nullable(r1) && nullable(r2) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
case STAR(_) => true |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
59 |
case RECD(_, r) => nullable(r) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
60 |
case CRANGE(_) => false |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
61 |
case PLUS(r) => nullable(r) |
368
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
367
diff
changeset
|
62 |
case OPT(_) => true |
385
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
63 |
case NTIMES(r, n) => if (n == 0) true else nullable(r) |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
} |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
66 |
// derivative of a regular expression w.r.t. a character |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
def der (c: Char, r: Rexp) : Rexp = r match { |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
case NULL => NULL |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
69 |
case EMPTY => NULL |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
case CHAR(d) => if (c == d) EMPTY else NULL |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
case ALT(r1, r2) => ALT(der(c, r1), der(c, r2)) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
case SEQ(r1, r2) => |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
if (nullable(r1)) ALT(SEQ(der(c, r1), r2), der(c, r2)) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
74 |
else SEQ(der(c, r1), r2) |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
case STAR(r) => SEQ(der(c, r), STAR(r)) |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
76 |
case RECD(_, r1) => der(c, r1) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
77 |
case CRANGE(cs) => if (cs.contains(c)) EMPTY else NULL |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
78 |
case PLUS(r) => SEQ(der(c, r), STAR(r)) |
368
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
367
diff
changeset
|
79 |
case OPT(r) => ALT(der(c, r), NULL) |
385
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
80 |
case NTIMES(r, n) => if (n == 0) NULL else der(c, SEQ(r, NTIMES(r, n - 1))) |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
81 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
82 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
83 |
// derivative w.r.t. a string (iterates der) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
84 |
def ders (s: List[Char], r: Rexp) : Rexp = s match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
85 |
case Nil => r |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
86 |
case c::s => ders(s, der(c, r)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
87 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
88 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
89 |
// extracts a string from value |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
90 |
def flatten(v: Val) : String = v match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
91 |
case Empty => "" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
92 |
case Chr(c) => c.toString |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
93 |
case Left(v) => flatten(v) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
94 |
case Right(v) => flatten(v) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
95 |
case Seq(v1, v2) => flatten(v1) + flatten(v2) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
96 |
case Stars(vs) => vs.map(flatten).mkString |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
97 |
case Rec(_, v) => flatten(v) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
98 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
99 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
100 |
// extracts an environment from a value |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
101 |
def env(v: Val) : List[(String, String)] = v match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
102 |
case Empty => Nil |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
103 |
case Chr(c) => Nil |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
104 |
case Left(v) => env(v) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
105 |
case Right(v) => env(v) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
106 |
case Seq(v1, v2) => env(v1) ::: env(v2) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
107 |
case Stars(vs) => vs.flatMap(env) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
108 |
case Rec(x, v) => (x, flatten(v))::env(v) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
109 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
110 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
111 |
// injection part |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
112 |
def mkeps(r: Rexp) : Val = r match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
113 |
case EMPTY => Empty |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
114 |
case ALT(r1, r2) => |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
115 |
if (nullable(r1)) Left(mkeps(r1)) else Right(mkeps(r2)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
116 |
case SEQ(r1, r2) => Seq(mkeps(r1), mkeps(r2)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
117 |
case STAR(r) => Stars(Nil) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
118 |
case RECD(x, r) => Rec(x, mkeps(r)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
119 |
case PLUS(r) => Stars(List(mkeps(r))) |
368
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
367
diff
changeset
|
120 |
case OPT(_) => Right(Empty) |
385
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
121 |
case NTIMES(r, n) => if (n == 0) Stars(Nil) else Stars(Nil.padTo(n, mkeps(r))) |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
122 |
case _ => { println ("r : " + r.toString); |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
123 |
throw new Exception("mkeps error")} |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
} |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
|
165
66b699c80479
tuned progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
164
diff
changeset
|
126 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
127 |
def inj(r: Rexp, c: Char, v: Val) : Val = (r, v) match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
128 |
case (STAR(r), Seq(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
129 |
case (SEQ(r1, r2), Seq(v1, v2)) => Seq(inj(r1, c, v1), v2) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
130 |
case (SEQ(r1, r2), Left(Seq(v1, v2))) => Seq(inj(r1, c, v1), v2) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
131 |
case (SEQ(r1, r2), Right(v2)) => Seq(mkeps(r1), inj(r2, c, v2)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
132 |
case (ALT(r1, r2), Left(v1)) => Left(inj(r1, c, v1)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
133 |
case (ALT(r1, r2), Right(v2)) => Right(inj(r2, c, v2)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
134 |
case (CHAR(_), Empty) => Chr(c) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
135 |
case (CRANGE(_), Empty) => Chr(c) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
136 |
case (RECD(x, r1), _) => Rec(x, inj(r1, c, v)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
137 |
case (PLUS(r), Seq(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs) |
368
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
367
diff
changeset
|
138 |
case (OPT(r), Left(v1)) => Left(inj(r, c, v1)) |
385
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
139 |
case (NTIMES(r, n), Seq(v1, Stars(vs))) => Stars(inj(r, c, v1)::vs) |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
140 |
case (NTIMES(r, n), Left(Seq(v1, Stars(vs)))) => Stars(inj(r, c, v1)::vs) |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
141 |
case (NTIMES(r, n), Right(Stars(v::vs))) => Stars(mkeps(r)::inj(r, c, v)::vs) |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
142 |
case _ => { println ("r : " + r.toString + " v: " + v.toString); |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
143 |
throw new Exception("inj error")} |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
144 |
} |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
145 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
146 |
// main lexing function (produces a value) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
147 |
def lex(r: Rexp, s: List[Char]) : Val = s match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
148 |
case Nil => if (nullable(r)) mkeps(r) else throw new Exception("Not matched") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
149 |
case c::cs => inj(r, c, lex(der(c, r), cs)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
150 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
151 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
152 |
def lexing(r: Rexp, s: String) : Val = lex(r, s.toList) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
153 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
154 |
lexing(("ab" | "ab") ~ ("b" | EMPTY), "ab") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
155 |
|
368
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
367
diff
changeset
|
156 |
lexing(OPT("ab"), "ab") |
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
367
diff
changeset
|
157 |
|
388
66f66f1710ed
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
385
diff
changeset
|
158 |
lexing(NTIMES("1", 3), "111") |
66f66f1710ed
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
385
diff
changeset
|
159 |
lexing(NTIMES("1" | EMPTY, 3), "11") |
66f66f1710ed
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
385
diff
changeset
|
160 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
161 |
// some "rectification" functions for simplification |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
162 |
def F_ID(v: Val): Val = v |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
163 |
def F_RIGHT(f: Val => Val) = (v:Val) => Right(f(v)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
164 |
def F_LEFT(f: Val => Val) = (v:Val) => Left(f(v)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
165 |
def F_ALT(f1: Val => Val, f2: Val => Val) = (v:Val) => v match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
166 |
case Right(v) => Right(f2(v)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
167 |
case Left(v) => Left(f1(v)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
168 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
169 |
def F_SEQ(f1: Val => Val, f2: Val => Val) = (v:Val) => v match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
170 |
case Seq(v1, v2) => Seq(f1(v1), f2(v2)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
171 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
172 |
def F_SEQ_Empty1(f1: Val => Val, f2: Val => Val) = |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
173 |
(v:Val) => Seq(f1(Empty), f2(v)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
174 |
def F_SEQ_Empty2(f1: Val => Val, f2: Val => Val) = |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
175 |
(v:Val) => Seq(f1(v), f2(Empty)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
176 |
def F_RECD(f: Val => Val) = (v:Val) => v match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
177 |
case Rec(x, v) => Rec(x, f(v)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
178 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
179 |
def F_ERROR(v: Val): Val = throw new Exception("error") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
180 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
181 |
// simplification of regular expressions returning also an |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
182 |
// rectification function; no simplification under STAR |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
183 |
def simp(r: Rexp): (Rexp, Val => Val) = r match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
184 |
case ALT(r1, r2) => { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
185 |
val (r1s, f1s) = simp(r1) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
186 |
val (r2s, f2s) = simp(r2) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
187 |
(r1s, r2s) match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
188 |
case (NULL, _) => (r2s, F_RIGHT(f2s)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
189 |
case (_, NULL) => (r1s, F_LEFT(f1s)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
190 |
case _ => if (r1s == r2s) (r1s, F_LEFT(f1s)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
191 |
else (ALT (r1s, r2s), F_ALT(f1s, f2s)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
192 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
193 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
194 |
case SEQ(r1, r2) => { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
195 |
val (r1s, f1s) = simp(r1) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
196 |
val (r2s, f2s) = simp(r2) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
197 |
(r1s, r2s) match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
198 |
case (NULL, _) => (NULL, F_ERROR) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
199 |
case (_, NULL) => (NULL, F_ERROR) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
200 |
case (EMPTY, _) => (r2s, F_SEQ_Empty1(f1s, f2s)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
201 |
case (_, EMPTY) => (r1s, F_SEQ_Empty2(f1s, f2s)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
202 |
case _ => (SEQ(r1s,r2s), F_SEQ(f1s, f2s)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
203 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
204 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
205 |
case RECD(x, r1) => { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
206 |
val (r1s, f1s) = simp(r1) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
207 |
(RECD(x, r1s), F_RECD(f1s)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
208 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
209 |
case r => (r, F_ID) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
210 |
} |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
211 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
212 |
def lex_simp(r: Rexp, s: List[Char]) : Val = s match { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
213 |
case Nil => if (nullable(r)) mkeps(r) else throw new Exception("Not matched") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
214 |
case c::cs => { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
215 |
val (r_simp, f_simp) = simp(der(c, r)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
216 |
inj(r, c, f_simp(lex_simp(r_simp, cs))) |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
217 |
} |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
218 |
} |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
219 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
220 |
def lexing_simp(r: Rexp, s: String) : Val = lex_simp(r, s.toList) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
221 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
222 |
lexing_simp(("a" | "ab") ~ ("b" | ""), "ab") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
223 |
|
368
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
367
diff
changeset
|
224 |
lexing_simp(OPT("ab"), "ab") |
a9911966c0df
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
367
diff
changeset
|
225 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
226 |
// Lexing Rules for a Small While Language |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
227 |
|
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
228 |
val SYM = CRANGE("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
229 |
val DIGIT = CRANGE("0123456789") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
230 |
val ID = SYM ~ (SYM | DIGIT).% |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
231 |
val NUM = PLUS(DIGIT) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
232 |
val KEYWORD : Rexp = "skip" | "while" | "do" | "if" | "then" | "else" | "read" | "write" | "true" | "false" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
233 |
val SEMI: Rexp = ";" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
234 |
val OP: Rexp = ":=" | "==" | "-" | "+" | "*" | "!=" | "<" | ">" | "<=" | ">=" | "%" | "/" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
235 |
val WHITESPACE = PLUS(" " | "\n" | "\t") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
236 |
val RPAREN: Rexp = ")" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
237 |
val LPAREN: Rexp = "(" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
238 |
val BEGIN: Rexp = "{" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
239 |
val END: Rexp = "}" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
240 |
val STRING: Rexp = "\"" ~ SYM.% ~ "\"" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
241 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
242 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
243 |
val WHILE_REGS = (("k" $ KEYWORD) | |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
244 |
("i" $ ID) | |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
245 |
("o" $ OP) | |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
246 |
("n" $ NUM) | |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
247 |
("s" $ SEMI) | |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
248 |
("str" $ STRING) | |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
249 |
("p" $ (LPAREN | RPAREN)) | |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
250 |
("b" $ (BEGIN | END)) | |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
251 |
("w" $ WHITESPACE)).% |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
252 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
253 |
// filters out all white spaces |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
254 |
def tokenise(r: Rexp, s: String) = |
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
255 |
env(lexing_simp(r, s)).filterNot { (s) => s._1 == "w"} |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
256 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
257 |
// Testing |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
258 |
//============ |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
259 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
260 |
def time[T](code: => T) = { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
261 |
val start = System.nanoTime() |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
262 |
val result = code |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
263 |
val end = System.nanoTime() |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
264 |
println((end - start)/1.0e9) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
265 |
result |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
266 |
} |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
267 |
|
385
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
268 |
println(lexing_simp(OPT("1"), "1")) |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
269 |
println(lexing_simp(OPT("1"), "")) |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
270 |
println(ders("111".toList, NTIMES("1",3))) |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
271 |
println(lexing_simp(NTIMES("1",3), "111")) |
7f8516ff408d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
368
diff
changeset
|
272 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
273 |
val r1 = ("a" | "ab") ~ ("bcd" | "c") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
274 |
println(lexing(r1, "abcd")) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
275 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
276 |
val r2 = ("" | "a") ~ ("ab" | "b") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
277 |
println(lexing(r2, "ab")) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
278 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
279 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
280 |
// Two Simple While Tests |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
281 |
//======================== |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
282 |
println("prog0 test") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
283 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
284 |
val prog0 = """read n""" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
285 |
println(env(lexing_simp(WHILE_REGS, prog0))) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
286 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
287 |
println("prog1 test") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
288 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
289 |
val prog1 = """read n; write (n)""" |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
290 |
println(env(lexing_simp(WHILE_REGS, prog1))) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
291 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
292 |
|
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
293 |
// Big Test |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
294 |
//========== |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
295 |
|
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
296 |
def escape(raw: String): String = { |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
297 |
import scala.reflect.runtime.universe._ |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
298 |
Literal(Constant(raw)).toString |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
299 |
} |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
300 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
301 |
val prog2 = """ |
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
302 |
write "Fib"; |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
303 |
read n; |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
304 |
minus1 := 0; |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
305 |
minus2 := 1; |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
306 |
while n > 0 do { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
307 |
temp := minus2; |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
308 |
minus2 := minus1 + minus2; |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
309 |
minus1 := temp; |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
310 |
n := n - 1 |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
311 |
}; |
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
312 |
write "Result"; |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
313 |
write minus2 |
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
314 |
""" |
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
315 |
|
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
316 |
val prog3 = """ |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
317 |
start := 1000; |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
318 |
x := start; |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
319 |
y := start; |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
320 |
z := start; |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
321 |
while 0 < x do { |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
322 |
while 0 < y do { |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
323 |
while 0 < z do { |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
324 |
z := z - 1 |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
325 |
}; |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
326 |
z := start; |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
327 |
y := y - 1 |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
328 |
}; |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
329 |
y := start; |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
330 |
x := x - 1 |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
331 |
} |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
332 |
""" |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
333 |
|
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
334 |
|
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
335 |
println("Tokens") |
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
336 |
println(tokenise(WHILE_REGS, prog2).mkString("\n")) |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
337 |
|
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
338 |
val fib_tokens = tokenise(WHILE_REGS, prog2) |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
339 |
fib_tokens.map{case (s1, s2) => (escape(s1), escape(s2))}.mkString(",\n") |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
340 |
|
164
6c1d214c39ef
added progs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
341 |
|
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
342 |
val test_tokens = tokenise(WHILE_REGS, prog3) |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
343 |
test_tokens.map{case (s1, s2) => (escape(s1), escape(s2))}.mkString(",\n") |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
344 |
|
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
345 |
|
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
346 |
/* |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
347 |
for (i <- 1 to 120 by 10) { |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
348 |
print(i.toString + ": ") |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
349 |
time(lexing_simp(WHILE_REGS, prog2 * i)) |
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
350 |
} |
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
351 |
*/ |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
352 |
|
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
353 |
val toks_fib = |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
354 |
List(("k","write"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
355 |
("str","Fib"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
356 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
357 |
("k","read"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
358 |
("i","n"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
359 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
360 |
("i","minus1"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
361 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
362 |
("n","0"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
363 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
364 |
("i","minus2"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
365 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
366 |
("n","1"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
367 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
368 |
("k","while"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
369 |
("i","n"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
370 |
("o",">"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
371 |
("n","0"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
372 |
("k","do"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
373 |
("b","{"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
374 |
("i","temp"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
375 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
376 |
("i","minus2"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
377 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
378 |
("i","minus2"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
379 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
380 |
("i","minus1"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
381 |
("o","+"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
382 |
("i","minus2"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
383 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
384 |
("i","minus1"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
385 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
386 |
("i","temp"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
387 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
388 |
("i","n"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
389 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
390 |
("i","n"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
391 |
("o","-"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
392 |
("n","1"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
393 |
("b","}"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
394 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
395 |
("k","write"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
396 |
("str","Result"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
397 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
398 |
("k","write"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
399 |
("i","minus2")) |
367
04127a5aad23
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
165
diff
changeset
|
400 |
|
392
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
401 |
val toks_test = |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
402 |
List(("i","start"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
403 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
404 |
("n","1000"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
405 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
406 |
("i","x"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
407 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
408 |
("i","start"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
409 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
410 |
("i","y"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
411 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
412 |
("i","start"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
413 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
414 |
("i","z"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
415 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
416 |
("i","start"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
417 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
418 |
("k","while"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
419 |
("n","0"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
420 |
("o","<"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
421 |
("i","x"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
422 |
("k","do"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
423 |
("b","{"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
424 |
("k","while"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
425 |
("n","0"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
426 |
("o","<"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
427 |
("i","y"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
428 |
("k","do"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
429 |
("b","{"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
430 |
("k","while"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
431 |
("n","0"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
432 |
("o","<"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
433 |
("i","z"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
434 |
("k","do"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
435 |
("b","{"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
436 |
("i","z"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
437 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
438 |
("i","z"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
439 |
("o","-"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
440 |
("n","1"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
441 |
("b","}"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
442 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
443 |
("i","z"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
444 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
445 |
("i","start"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
446 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
447 |
("i","y"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
448 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
449 |
("i","y"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
450 |
("o","-"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
451 |
("n","1"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
452 |
("b","}"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
453 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
454 |
("i","y"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
455 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
456 |
("i","start"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
457 |
("s",";"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
458 |
("i","x"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
459 |
("o",":="), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
460 |
("i","x"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
461 |
("o","-"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
462 |
("n","1"), |
2d0a59127694
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
388
diff
changeset
|
463 |
("b","}")) |