--- a/progs/lexer/lexer.sc Fri Oct 13 23:49:34 2023 +0100
+++ b/progs/lexer/lexer.sc Sat Oct 21 09:09:09 2023 +0100
@@ -42,12 +42,6 @@
implicit def string2rexp(s : String) : Rexp =
charlist2rexp(s.toList)
-extension (r: Rexp) {
- def | (s: Rexp) = ALT(r, s)
- def % = STAR(r)
- def ~ (s: Rexp) = SEQ(r, s)
-}
-
extension (s: String) {
def | (r: Rexp) = ALT(s, r)
def | (r: String) = ALT(s, r)
@@ -57,6 +51,17 @@
def $ (r: Rexp) = RECD(s, r)
}
+extension (r: Rexp) {
+ def | (s: Rexp) = ALT(r, s)
+ def % = STAR(r)
+ def ~ (s: Rexp) = SEQ(r, s)
+}
+
+
+
+val r : Rexp = ("a" | "b").%
+println(r)
+
def nullable(r: Rexp) : Boolean = r match {
case ZERO => false
case ONE => true
@@ -79,6 +84,7 @@
case RECD(_, r1) => der(c, r1)
}
+println(der('a', ALT(STAR("a"), "b")))
// extracts a string from a value
def flatten(v: Val) : String = v match {
@@ -128,6 +134,8 @@
case (RECD(x, r1), _) => Rec(x, inj(r1, c, v))
}
+
+
// some "rectification" functions for simplification
def F_ID(v: Val): Val = v
def F_RIGHT(f: Val => Val) = (v:Val) => Right(f(v))