main_marking3/re_test2.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 11 Mar 2023 22:01:53 +0000
changeset 463 0315d9983cd0
parent 424 daf561a83ba6
permissions -rw-r--r--
updated

import M3._

assert(der('a', ZERO | ONE) == ALT(ZERO, ZERO))
assert(der('a', (CHAR('a') | ONE) ~ CHAR('a')) == ALTs(List(SEQ(ALT(ONE, ZERO), CHAR('a')), SEQs(List(ONE)))))
assert(der('a', (CHAR('a') | CHAR('a')) ~ CHAR('a')) == (ONE | ONE) ~ CHAR('a'))
assert(der('a', STAR(CHAR('a'))) == (ONE ~ STAR(CHAR('a'))))
assert(der('b', STAR(CHAR('a'))) == (ZERO ~ STAR(CHAR('a'))))


val r0_urban = "a" ~ "b" ~ "c"
assert(der('a', r0_urban) == (ONE ~ "b") ~ "c")
assert(der('b', r0_urban) == (ZERO ~ "b") ~ "c")
assert(der('c', r0_urban) == (ZERO ~ "b") ~ "c")

val r1_urban = (ONE ~ "b") ~ "c"

assert(der('a', r1_urban) == ((ZERO ~ "b") | SEQs(List(ZERO))) ~ "c")
assert(der('b', r1_urban) == ((ZERO ~ "b") | SEQs(List(ONE))) ~ "c")
assert(der('c', r1_urban) == ((ZERO ~ "b") | SEQs(List(ZERO))) ~ "c")

val r2_urban = ((ZERO ~ "b") | ONE) ~ "c"

assert(der('a', r2_urban) == ((((ZERO ~ "b") | ZERO) ~ "c") | SEQs(List(ZERO))))
assert(der('b', r2_urban) == ((((ZERO ~ "b") | ZERO) ~ "c") | SEQs(List(ZERO))))
assert(der('c', r2_urban) == ((((ZERO ~ "b") | ZERO) ~ "c") | SEQs(List(ONE))))