395
|
1 |
// package zre
|
|
2 |
//Zre5: eliminated mems table
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
import scala.collection.mutable.{Map => MMap}
|
|
7 |
import scala.collection.mutable.{ArrayBuffer => MList}
|
|
8 |
//import pprint._
|
|
9 |
|
|
10 |
import scala.util.Try
|
|
11 |
import pprint._
|
|
12 |
|
|
13 |
|
|
14 |
abstract class Val
|
|
15 |
case object Empty extends Val
|
|
16 |
case class Chr(c: Char) extends Val
|
|
17 |
case class Sequ(v1: Val, v2: Val) extends Val
|
|
18 |
case class Left(v: Val) extends Val
|
|
19 |
case class Right(v: Val) extends Val
|
|
20 |
case class Stars(vs: List[Val]) extends Val
|
|
21 |
case object DummyFilling extends Val
|
|
22 |
|
|
23 |
|
|
24 |
// abstract class Rexp {
|
|
25 |
// def equals(other: Rexp) : Boolean = this.eq(other)
|
|
26 |
// }
|
|
27 |
abstract class Rexp
|
|
28 |
case object ZERO extends Rexp // matches nothing
|
|
29 |
case object ONE extends Rexp // matches an empty string
|
|
30 |
case class CHAR(c: Char) extends Rexp // matches a character c
|
|
31 |
case class ALT(r1: Rexp, r2: Rexp) extends Rexp // alternative
|
|
32 |
case class AL1(r1: Rexp) extends Rexp
|
|
33 |
case class SEQ(r1: Rexp, r2: Rexp) extends Rexp // sequence
|
|
34 |
case class STAR(r: Rexp) extends Rexp
|
|
35 |
case object RTOP extends Rexp
|
|
36 |
|
|
37 |
|
|
38 |
//Seq a b --> Seq Seqa Seqb
|
|
39 |
//Seq a b --> Sequ chra chrb
|
|
40 |
//ALT r1 r2 --> mALT
|
|
41 |
// AltC L AltC R
|
|
42 |
var cyclicPreventionList : Set[Int]= Set()
|
|
43 |
abstract class Ctx(var starIters: Int = 0){
|
|
44 |
//starIters = 0
|
|
45 |
}
|
|
46 |
case object RootC extends Ctx
|
|
47 |
case class SeqC( mForMyself: Mem, processedSibling: List[Val], unpSibling: List[Rexp]) extends Ctx
|
|
48 |
case class AltC( mForMyself: Mem, wrapper: Val => Val) extends Ctx
|
|
49 |
case class StarC(mForMyself: Mem, vs: List[Val], inside: Rexp) extends Ctx
|
|
50 |
|
|
51 |
case class Mem(var parents: MList[Ctx], var result : MList[(Int, Val)])
|
|
52 |
|
|
53 |
//AltC(Mem(RootC::Nil, Map()))
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
type Zipper = (Val, Mem)
|
|
58 |
|
|
59 |
var mems : MMap[(Int, Rexp), Mem] = MMap()
|
|
60 |
//start pos, original regex --> result entry
|
|
61 |
|
|
62 |
|
|
63 |
var pos : Int = 0
|
|
64 |
|
403
|
65 |
//size: of a Aregx for testing purposes
|
|
66 |
def size(r: Rexp) : Int = r match {
|
|
67 |
case ZERO => 1
|
|
68 |
case ONE => 1
|
|
69 |
case CHAR(_) => 1
|
|
70 |
case SEQ(r1, r2) => 1 + size(r1) + size(r2)
|
|
71 |
case ALT(r1, r2) => 1 + List(r1, r2).map(size).sum
|
|
72 |
case STAR(r) => 1 + size(r)
|
|
73 |
}
|
|
74 |
|
395
|
75 |
|
|
76 |
|
|
77 |
//input ..................
|
|
78 |
// ^ ^
|
|
79 |
// p q
|
|
80 |
// r
|
|
81 |
|
|
82 |
//parse r[p...q] --> v
|
|
83 |
|
|
84 |
//(a+aa)*
|
|
85 |
//aaa
|
|
86 |
//[R(Sequ(a, a)), vs]
|
|
87 |
//[L(a), L(a), vs]
|
|
88 |
def check_before_down(c: Ctx, r: Rexp, starIters: Int = 0) : List[Zipper] = {
|
|
89 |
c.starIters = starIters
|
|
90 |
mems.get((pos, r)) match {
|
|
91 |
case Some(m) =>
|
|
92 |
// c match {
|
|
93 |
// case StarC(m, vs, inside) => vs.length
|
|
94 |
// }
|
403
|
95 |
val idx = m.parents.lastIndexWhere(c0 => c0.starIters <= c.starIters)
|
|
96 |
// if(m.parents.size == 1){
|
|
97 |
// println("third parent added")
|
|
98 |
// println(simpleCtxDisplay(c))
|
|
99 |
// println("the other parents")
|
|
100 |
// m.parents.foreach(c00 => println(c00.starIters))
|
|
101 |
// println(idx + 1)
|
|
102 |
// println("c's star iters: "+ c.starIters)
|
|
103 |
// println(s"the others' star iters: ${m.parents(0).starIters}")
|
|
104 |
// }
|
395
|
105 |
m.parents.insert(idx + 1, c)
|
|
106 |
//m.parents = m.parents:::List(c)
|
|
107 |
m.result.find(endPos_value => endPos_value._1 == pos) match {
|
|
108 |
// case Some((i, v)) =>
|
|
109 |
// original_up(v, c, starIters)
|
|
110 |
case None =>
|
|
111 |
List()
|
|
112 |
}
|
|
113 |
case None =>
|
|
114 |
val m = Mem(MList(c), MList.empty[(Int, Val)])
|
|
115 |
mems = mems + ((pos, r) -> m)
|
|
116 |
original_down(r, m, starIters)
|
|
117 |
}
|
|
118 |
// val m = Mem(c::Nil, MList.empty[(Int, Val)])
|
|
119 |
// original_down(r, m, d)
|
|
120 |
}
|
|
121 |
|
|
122 |
//mems pstart r --> m parents [(pend, vres), ...]
|
|
123 |
//aaa
|
|
124 |
//012
|
|
125 |
//seq a a
|
|
126 |
//0 a~a --> m ... [(2, Sequ a a)]
|
|
127 |
// c match {
|
|
128 |
// case StarC(mst, vst, rst) => print(s"StarC $vst\t")
|
|
129 |
// case SeqC(mse, pr, unp) => print(s"SeqC $unp\t")
|
|
130 |
// case AltC(mal, w) => print(s"AltC ${w(Empty)}\t")
|
|
131 |
// case RootC => print("Root")
|
|
132 |
// }
|
|
133 |
def reorderCtx(cs: List[Ctx]): List[Ctx] = {
|
|
134 |
Nil
|
|
135 |
}
|
|
136 |
|
|
137 |
def mem_up(vres: Val, m: Mem, starIters : Int = 0) : List[Zipper] = {
|
|
138 |
m.result += (pos -> vres)
|
|
139 |
//m.parents = m.parents.reverse
|
|
140 |
|
|
141 |
// if(m.parents.size > 1){//println()
|
|
142 |
// println()
|
|
143 |
// println("each of the contexts")
|
|
144 |
// m.parents.reverse.foreach (c =>
|
|
145 |
// println(simpleCtxDisplay(c))
|
|
146 |
// )
|
|
147 |
// println("after distinctCtx")
|
|
148 |
// distinctCtx(m.parents.reverse).foreach(c =>
|
|
149 |
// println(simpleCtxDisplay(c))
|
|
150 |
// )
|
|
151 |
// //println(s"vs is $vss")
|
|
152 |
|
|
153 |
// }
|
|
154 |
//.distinctBy(zipBackToRegex(_))
|
|
155 |
//TODO: too many arraybuffer->list conversions
|
|
156 |
(m.parents).distinctBy(zipBackToRegex(_)).flatMap((c: Ctx) =>
|
|
157 |
original_up(vres, c, starIters)
|
|
158 |
).toList
|
|
159 |
// m.parents.reverse.flatMap((c: Ctx) =>
|
|
160 |
// original_up(vres, c, rec_depth)
|
|
161 |
// )
|
|
162 |
// original_up(vres, m.parents.last, rec_depth)
|
|
163 |
}
|
|
164 |
|
|
165 |
def original_down(r: Rexp, m: Mem, starIters: Int = 0) : List[Zipper] = (r, m) match {
|
|
166 |
case (CHAR(b), m) => {
|
|
167 |
if (input(pos) == b) {
|
|
168 |
List((Chr(b), m))
|
|
169 |
}
|
|
170 |
else
|
|
171 |
Nil
|
|
172 |
}
|
|
173 |
case (ONE, m) => Nil//mem_up(Empty, m, starIters)
|
|
174 |
case (SEQ(r1, r2), m) =>
|
|
175 |
// if(nullable(r1)){
|
|
176 |
// val mprime = Mem(AltC(m, x => x )::Nil, MList.empty[(Int, Val)])
|
|
177 |
// check_before_down(SeqC(mprime, Nil, List(r2)), r1, starIters) :::
|
|
178 |
// check_before_down(SeqC(mprime, mkeps(r1)::Nil, Nil), r2, starIters)
|
|
179 |
// }
|
|
180 |
// else
|
|
181 |
check_before_down(SeqC(m, Nil, List(r2)), r1, starIters)
|
|
182 |
case (ALT(r1, r2), m) =>
|
|
183 |
check_before_down(AltC(m, Left(_)), r1, starIters) :::
|
|
184 |
check_before_down(AltC(m, Right(_)), r2, starIters)
|
|
185 |
case (STAR(r0), m) =>
|
|
186 |
check_before_down(StarC(m, Nil, r0), r0, starIters) :::
|
|
187 |
mem_up(Stars(Nil), m, starIters)
|
|
188 |
case (_, _) => throw new Exception("original down unexpected r or m")
|
|
189 |
}
|
|
190 |
|
|
191 |
def original_up(v: Val, c: Ctx, starIters: Int = 0) : List[Zipper] =
|
|
192 |
{
|
|
193 |
|
|
194 |
(v, c) match {
|
|
195 |
case (v, SeqC(m, v1::Nil, Nil)) =>
|
|
196 |
mem_up(Sequ(v1, v), m, starIters)
|
|
197 |
case (v, SeqC(m, vs, u1::Nil)) =>
|
|
198 |
check_before_down(SeqC(m, v::vs, Nil), u1, starIters)
|
|
199 |
case (v, AltC(m, wrap)) => m.result.find(tup2 => tup2._1 == pos) match {
|
|
200 |
case Some( (i, vPrime) ) =>
|
|
201 |
m.result += (i -> wrap(v))
|
|
202 |
Nil
|
|
203 |
case None =>
|
|
204 |
mem_up(wrap(v), m, starIters)
|
|
205 |
} //mem_up(AL1(v), par)
|
|
206 |
//case (v, StarC(m, vs, r0)) => throw new Exception("why not hit starC")
|
|
207 |
|
|
208 |
case (v, RootC) =>
|
|
209 |
Nil
|
|
210 |
case (v, StarC(m, vs, r0) ) => //mem_up(Stars(v::vs), m, starIters) //:::
|
|
211 |
check_before_down(StarC(m, v::vs, r0), r0, starIters + 1) :::
|
|
212 |
mem_up(Stars((v::vs).reverse), m, starIters)
|
|
213 |
case (_, _) => throw new Exception("hit unexpected context")
|
|
214 |
}
|
|
215 |
|
|
216 |
}
|
|
217 |
|
|
218 |
|
|
219 |
def derive(p: Int, z: Zipper) : List[Zipper] = {
|
|
220 |
pos = p
|
|
221 |
//println(s"z's actual size is ${actualZipperSize(z::Nil)}")
|
|
222 |
|
|
223 |
z match {
|
|
224 |
case (v, m) =>
|
|
225 |
|
|
226 |
mem_up(v, m)
|
|
227 |
case _ => throw new Exception("error")
|
|
228 |
}
|
|
229 |
}
|
|
230 |
//let e' = Seq([]) in
|
|
231 |
//
|
|
232 |
def init_zipper(r: Rexp) : Zipper = {
|
|
233 |
val m_top = Mem(MList(RootC), MList.empty[(Int, Val)])
|
|
234 |
val c_top = SeqC(m_top, Nil, r::Nil)
|
|
235 |
val m_r = Mem(MList(c_top), MList.empty[(Int, Val)])
|
|
236 |
println(s"initial zipper is (Empty, $m_r)")
|
|
237 |
(Empty, m_r)//TODO: which val should we start with? Maybe Empty, maybe doesn't matter
|
|
238 |
// val dummyRexp = ONE
|
|
239 |
// val dummyMem = Mem()
|
|
240 |
|
|
241 |
}
|
|
242 |
|
|
243 |
|
|
244 |
def plug_convert(v: Val, c: Ctx) : List[Val] =
|
|
245 |
{
|
|
246 |
|
|
247 |
c match {
|
|
248 |
case RootC => List(v)
|
|
249 |
//TODO: non-binary Seq requires ps.rev
|
|
250 |
case SeqC(m, ps::Nil, Nil) =>
|
|
251 |
plug_mem(Sequ(ps, v), m)
|
|
252 |
|
|
253 |
//TODO: un not nullable--partial values?
|
|
254 |
case SeqC(m, Nil, un::Nil) =>
|
|
255 |
if(nullable(un))
|
|
256 |
plug_mem(Sequ(v, mkeps(un)), m)
|
|
257 |
else
|
|
258 |
Nil
|
|
259 |
|
|
260 |
//TODO: when multiple results stored in m, which one to choose?
|
|
261 |
case AltC(m, wrap) =>
|
|
262 |
plug_mem(wrap(v), m)
|
|
263 |
case StarC(m, vs, r0) => plug_mem(Stars((v::vs).reverse), m)
|
|
264 |
}
|
|
265 |
|
|
266 |
}
|
|
267 |
|
|
268 |
|
|
269 |
var cnt = 0;
|
|
270 |
def plug_mem(v: Val, m: Mem) : List[Val] = {
|
|
271 |
m.result += (pos -> v)
|
|
272 |
//TODO: eliminate arraybuffer->list conversion
|
|
273 |
m.parents.flatMap({c =>
|
|
274 |
plug_convert(v, c)
|
|
275 |
}
|
|
276 |
).toList
|
|
277 |
}
|
|
278 |
|
|
279 |
def plug_all(zs: List[Zipper]) : List[Val] = {
|
|
280 |
zs.flatMap(z => plug_mem(z._1, z._2))
|
|
281 |
}
|
|
282 |
|
|
283 |
|
|
284 |
def mkeps(r: Rexp) : Val = r match {
|
|
285 |
case ONE => Empty
|
|
286 |
case ALT(r1, r2) =>
|
|
287 |
if (nullable(r1)) Left(mkeps(r1)) else Right(mkeps(r2))
|
|
288 |
case SEQ(r1, r2) => Sequ(mkeps(r1), mkeps(r2))
|
|
289 |
case _ => DummyFilling
|
|
290 |
}
|
|
291 |
|
|
292 |
def nullable(r: Rexp) : Boolean = r match {
|
|
293 |
case ZERO => false
|
|
294 |
case ONE => true
|
|
295 |
case CHAR(_) => false
|
|
296 |
case ALT(r1, r2) => nullable(r1) || nullable(r2)
|
|
297 |
case SEQ(r1, r2) => nullable(r1) && nullable(r2)
|
|
298 |
case _ => false
|
|
299 |
}
|
|
300 |
|
|
301 |
|
|
302 |
val tokList : List[Char] = "aab".toList
|
|
303 |
var input : List[Char] = tokList
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
def lexRecurse(zs: List[Zipper], index: Int) : List[Zipper] = {
|
|
312 |
if(index < input.length )
|
|
313 |
lexRecurse(zs.flatMap(z => derive(index, z) ), index + 1)
|
|
314 |
else
|
|
315 |
zs
|
|
316 |
}
|
|
317 |
|
|
318 |
def lex(r: Rexp, s: String) : List[Zipper] = {
|
|
319 |
input = s.toList
|
|
320 |
|
|
321 |
lexRecurse(init_zipper(r)::Nil, 0)
|
|
322 |
}
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
implicit def charlist2rexp(s: List[Char]): Rexp = s match {
|
|
327 |
case Nil => ONE
|
|
328 |
case c::Nil => CHAR(c)
|
|
329 |
case c::cs => SEQ(CHAR(c), charlist2rexp(cs))
|
|
330 |
}
|
|
331 |
implicit def string2Rexp(s: String) : Rexp = charlist2rexp(s.toList)
|
|
332 |
|
|
333 |
implicit def RexpOps(r: Rexp) = new {
|
|
334 |
def | (s: Rexp) = ALT(r, s)
|
|
335 |
def ~ (s: Rexp) = SEQ(r, s)
|
|
336 |
def % = STAR(r)
|
|
337 |
}
|
|
338 |
|
|
339 |
implicit def stringOps(s: String) = new {
|
|
340 |
def | (r: Rexp) = ALT(s, r)
|
|
341 |
def | (r: String) = ALT(s, r)
|
|
342 |
def ~ (r: Rexp) = SEQ(s, r)
|
|
343 |
def ~ (r: String) = SEQ(s, r)
|
|
344 |
def % = STAR(s)
|
|
345 |
|
|
346 |
}
|
|
347 |
|
|
348 |
//derive(0, init_zipper(re0))
|
|
349 |
|
|
350 |
// println(re1s.length)
|
|
351 |
// mems.foreach(a => println(a))
|
|
352 |
// val re1sPlugged = plug_all(re1s)
|
|
353 |
// re1sPlugged.foreach(zipper => {
|
|
354 |
// println(zipper);
|
|
355 |
// println("delimit")
|
|
356 |
// })
|
|
357 |
|
|
358 |
// mems.clear()
|
|
359 |
// println(mems)
|
|
360 |
// println(re0)
|
|
361 |
// val re2s = lex(re0, "aab")
|
|
362 |
// val re2sPlugged = plug_all(re2s)
|
|
363 |
// re2sPlugged.foreach(v => {
|
|
364 |
// val Sequ(Empty, vp) = v
|
|
365 |
// println(vp)
|
|
366 |
// }
|
|
367 |
// )
|
|
368 |
// val re0 = SEQ(ALT(CHAR('a'), SEQ(CHAR('a'),CHAR('a'))),
|
|
369 |
// ALT(SEQ(CHAR('a'), CHAR('b')), SEQ(CHAR('b'), CHAR('c')) )
|
|
370 |
// )
|
|
371 |
|
|
372 |
// val (rgraph, re0root) = makeGraphFromObject(re0)
|
|
373 |
// val asciir = GraphLayout.renderGraph(rgraph)
|
|
374 |
// println("printing out re0")
|
|
375 |
// println(asciir)
|
|
376 |
// val re1s = lex(re0, "aabc")
|
|
377 |
|
|
378 |
def actualZipperSize(zs: List[Zipper]) : Int = zs match {
|
|
379 |
case Nil => 0
|
|
380 |
case z::zs1 => countParents(z._2) + actualZipperSize(zs1)
|
|
381 |
}
|
|
382 |
|
|
383 |
def countParents(m: Mem) : Int = {
|
|
384 |
m.parents.map(c => countGrandParents(c)).sum
|
|
385 |
}
|
|
386 |
|
|
387 |
def countGrandParents(c: Ctx) : Int = {
|
|
388 |
c match {
|
|
389 |
case RootC => 1
|
|
390 |
case SeqC(m, pr, unp) => countParents(m)
|
|
391 |
case AltC(m, w) => countParents(m)
|
|
392 |
case StarC(m, _, _) => countParents(m)
|
|
393 |
}
|
|
394 |
}
|
|
395 |
//(a+aa)* \a --> (1 + a)(a+aa)* --> (a+aa)* + (1+a)(a+aa)*
|
|
396 |
|
|
397 |
//a(a+aa)* + 1(a+aa)* + (a+aa)*
|
|
398 |
|
|
399 |
//a~(a + aa)* \a -> 1 ~ (a + aa)*
|
|
400 |
//va <-----> m --> SeqC(m1, pr, "a") --> AltC(m4, Right)--> StarC(m2, vs, "a" + "aa") --> SeqC(m) ---> Root
|
|
401 |
// ^
|
|
402 |
// ---> AltC(m4, Left)
|
|
403 |
def zipBackToRegex(c: Ctx, r: Rexp = ONE) : Rexp = {
|
|
404 |
c match {
|
|
405 |
case RootC => r
|
|
406 |
case SeqC(m, pr, Nil) => zipBackToRegex(m.parents.head, r)
|
|
407 |
case SeqC(m, pr, unp::Nil) => zipBackToRegex(m.parents.head, SEQ(r, unp))
|
|
408 |
case AltC(m, w) => zipBackToRegex(m.parents.head, r)
|
|
409 |
case StarC(m, vs, r0) => zipBackToRegex(m.parents.head, SEQ(r, STAR(r0)))
|
|
410 |
}
|
|
411 |
}
|
|
412 |
|
|
413 |
def zipperSimp(z: Zipper) : Unit = z match {
|
|
414 |
case (v, m) => //m.parents = m.parents.distinctBy(c => zipBackToRegex(c))
|
|
415 |
}
|
|
416 |
|
|
417 |
def distinctCtx(cs: List[Ctx]) : List[Ctx] = cs.distinctBy(c => zipBackToRegex(c))
|
|
418 |
|
|
419 |
|
|
420 |
def simpleCtxDisplay(c: Ctx, indent : Int = 0) : String = c match {
|
|
421 |
case SeqC(m, pr, unp) => "Sc[m:" ++ printMem(m, indent + 1) ++
|
|
422 |
"pr:" ++ pr.map(v => shortValOutput(v)).mkString(", ") ++ " unp:" ++ unp.map(r2 => shortRexpOutput(r2)).mkString(", ") ++ "]"
|
|
423 |
case AltC(m, w) =>
|
|
424 |
w(Empty) match {
|
|
425 |
case Left(_) => s"Ac(m:${printMem(m, indent + 1)}, Left(_))"
|
|
426 |
case Right(_) => s"Ac(m:${printMem(m, indent + 1)}, Right(_))"
|
|
427 |
case Empty => s"Ac(m:${printMem(m, indent + 1)}, id)"
|
|
428 |
}
|
|
429 |
case StarC(m, vs, r0) => s"StarC[m:" ++ printMem(m, indent + 1) ++
|
|
430 |
"vs:" ++ vs.map(v => shortValOutput(v)).mkString(", ") ++ " r0: " ++ shortRexpOutput(r0)
|
|
431 |
case RootC => "Root"
|
|
432 |
//case AL1(r) => s"(+${shortRexpOutput(r)})"
|
|
433 |
//case STAR(r) => "STAR(" ++ shortRexpOutput(r) ++ ")"
|
|
434 |
//case RTOP => "RTOP"
|
|
435 |
}
|
|
436 |
|
|
437 |
def printMem(m: Mem, indent: Int = 0) : String = {
|
|
438 |
"M(par:" ++
|
|
439 |
m.parents.map(c => simpleCtxDisplay(c, indent + 1)).mkString("(",",", ")") ++
|
|
440 |
(", results:") ++
|
|
441 |
(for(iRexp <- m.result)
|
|
442 |
yield iRexp match {case (p: Int, v: Val) => s"$p->${shortValOutput(v)}"}
|
|
443 |
).mkString("(",",", ")") ++
|
|
444 |
")"
|
|
445 |
}
|
|
446 |
|
|
447 |
def shortRexpOutput(r: Rexp) : String = r match {
|
|
448 |
case CHAR(c) => c.toString
|
|
449 |
case ONE => "1"
|
|
450 |
case ZERO => "0"
|
|
451 |
case SEQ(r1, r2) => "[" ++ shortRexpOutput(r1) ++ "~" ++ shortRexpOutput(r2) ++ "]"
|
|
452 |
case ALT(r1, r2) => "(" ++ shortRexpOutput(r1) ++ "+" ++ shortRexpOutput(r2) ++ ")"
|
|
453 |
case STAR(r) => "[" ++ shortRexpOutput(r) ++ "]*"
|
|
454 |
//case STAR(r) => "STAR(" ++ shortRexpOutput(r) ++ ")"
|
|
455 |
case RTOP => "RTOP"
|
|
456 |
}
|
|
457 |
|
|
458 |
def shortValOutput(v: Val) : String = v match {
|
|
459 |
case Left(v) => "L(" ++ shortValOutput(v) ++ ")"
|
|
460 |
case Right(v) => "R(" ++ shortValOutput(v) ++ ")"
|
|
461 |
case Empty => "e"
|
|
462 |
case Sequ(v1, v2) => "[" ++ shortValOutput(v1) ++ "~" ++ shortValOutput(v2) ++ "]"
|
|
463 |
case Chr(a) => a.toString
|
|
464 |
case Stars(vs) => "Stars" ++ vs.map(shortValOutput(_)).mkString("[", ",", "]")
|
|
465 |
case _ => "???"
|
|
466 |
}
|
|
467 |
|
|
468 |
|
|
469 |
//def crystalizeZipper
|
|
470 |
|
|
471 |
for(i <- 1 to 2) {
|
|
472 |
mems.clear()
|
|
473 |
println(s"there are $i number of a's")
|
403
|
474 |
val re1 = ("a" | "ab" ) ~ ("c" | "bc")//(("a" | "b") ~ "c" | ("b" | "e") ~ "c" ) ~ "f"
|
|
475 |
val re1Lexed = lex(re1, "abc")
|
395
|
476 |
|
|
477 |
//drawZippers(re1Lexed)
|
|
478 |
println("size of actual zipper (including memoized contexts")
|
|
479 |
println(actualZipperSize(re1Lexed))
|
|
480 |
//println(re1Lexed)
|
|
481 |
//re1Lexed.foreach(zipperSimp(_))
|
|
482 |
//println(actualZipperSize(re1S))
|
|
483 |
val re1resPlugged = plug_all(re1Lexed)
|
|
484 |
//println(actualZipperSize(re1Lexed))
|
|
485 |
|
|
486 |
println("value extracted")
|
|
487 |
re1resPlugged.foreach(v => {
|
|
488 |
val Sequ(Empty, vp) = v
|
|
489 |
println(vp)
|
|
490 |
}
|
|
491 |
)
|
|
492 |
|
|
493 |
|
|
494 |
}
|
|
495 |
|
|
496 |
mems.clear()
|
|
497 |
val re2 = SEQ(ONE, "a")
|
|
498 |
val re2res = lex(re2, "a")
|
|
499 |
//lex(1~a, "a") --> lexRecurse((1v, m (SeqC(m (RootC, Nil), Nil, [1~a] ) )))
|
|
500 |
|
|
501 |
|
|
502 |
println(re2res)
|
|
503 |
|
|
504 |
val re2resPlugged = plug_all(re2res)
|
|
505 |
re2resPlugged.foreach(v => {
|
|
506 |
val Sequ(Empty, vp) = v
|
|
507 |
println(vp)
|
|
508 |
}
|
|
509 |
)
|
|
510 |
|
|
511 |
// println("remaining regex")
|
|
512 |
// println(re1ss.flatMap(z => zipBackMem(z._2)))
|
|
513 |
|
|
514 |
|
|
515 |
// val re1ssPlugged = plug_all(re1ss)
|
|
516 |
// println("each of the values")
|
|
517 |
// re1ssPlugged.foreach(v => {
|
|
518 |
// //val Sequ(Empty, vp) = v
|
|
519 |
// //println(vp)
|
|
520 |
// println(v)
|
|
521 |
// }
|
|
522 |
// )
|
|
523 |
// println(mems.size)
|
|
524 |
//println(mems)
|
|
525 |
//mems.map({case (ir, m) => if (ir._1 == 1 && ir._2 == CHAR('b')) println(printMem(m)) })
|
|
526 |
// println("Mkeps + inj:")
|
|
527 |
// println(
|
|
528 |
// mems.get((0, re1)) match {
|
|
529 |
// case Some(m) => printMem(m)
|
|
530 |
// case None => ""
|
|
531 |
// }
|
|
532 |
// )
|
|
533 |
|
|
534 |
// println(re1sPlugged)
|
|
535 |
//drawZippers(re1s, plugOrNot = false)
|
|
536 |
// re1s.foreach{
|
|
537 |
// re1 =>
|
|
538 |
// {
|
|
539 |
|
|
540 |
// drawZippers(derive(1, re1), plugOrNot = true)
|
|
541 |
|
|
542 |
// }
|
|
543 |
// }
|
|
544 |
|
|
545 |
|