equal
deleted
inserted
replaced
10 // |
10 // |
11 // or |
11 // or |
12 // |
12 // |
13 // amm re3.sc all |
13 // amm re3.sc all |
14 |
14 |
15 |
15 // regular expressions (as enum in Scala 3) |
16 abstract class Rexp |
16 enum Rexp { |
17 case object ZERO extends Rexp |
17 case ZERO // matches nothing |
18 case object ONE extends Rexp |
18 case ONE // matches an empty string |
19 case class CHAR(c: Char) extends Rexp |
19 case CHAR(c: Char) // matches a character c |
20 case class ALT(r1: Rexp, r2: Rexp) extends Rexp |
20 case ALT(r1: Rexp, r2: Rexp) // alternative |
21 case class SEQ(r1: Rexp, r2: Rexp) extends Rexp |
21 case SEQ(r1: Rexp, r2: Rexp) // sequence |
22 case class STAR(r: Rexp) extends Rexp |
22 case STAR(r: Rexp) // star |
23 case class NTIMES(r: Rexp, n: Int) extends Rexp |
23 case NTIMES(r: Rexp, n: Int) // explicit n-times |
|
24 } |
|
25 import Rexp._ |
|
26 |
24 |
27 |
25 |
28 |
26 // the nullable function: tests whether the regular |
29 // the nullable function: tests whether the regular |
27 // expression can recognise the empty string |
30 // expression can recognise the empty string |
28 def nullable (r: Rexp) : Boolean = r match { |
31 def nullable (r: Rexp) : Boolean = r match { |