progs/re1.scala
changeset 343 539b2e88f5b9
parent 261 24531cfaa36a
child 363 0d6deecdb2eb
equal deleted inserted replaced
342:c235e0aeb8df 343:539b2e88f5b9
    37 
    37 
    38 // main matcher function
    38 // main matcher function
    39 def matches(r: Rexp, s: String) : Boolean = nullable(ders(s.toList, r))
    39 def matches(r: Rexp, s: String) : Boolean = nullable(ders(s.toList, r))
    40 
    40 
    41 //example from the homework
    41 //example from the homework
    42 //val r = STAR(ALT(SEQ(CHAR('a'), CHAR('b')), CHAR('b')))
    42 val r = STAR(ALT(SEQ(CHAR('a'), CHAR('b')), CHAR('b')))
    43 //der('a', r)
    43 der('a', r)
    44 //der('b', r)
    44 der('b', r)
    45 //der('c', r)
    45 der('c', r)
    46 
    46 
    47 //optional: one or zero times
    47 //optional: one or zero times
    48 def OPT(r: Rexp) = ALT(r, EMPTY)
    48 def OPT(r: Rexp) = ALT(r, EMPTY)
    49 
    49 
    50 //n-times
    50 //n-times