progs/matcher/re1.sc
changeset 929 9541e073f2ed
parent 928 2f3c077359c4
child 941 66adcae6c762
equal deleted inserted replaced
928:2f3c077359c4 929:9541e073f2ed
    74 //============
    74 //============
    75 
    75 
    76 // the optional regular expression (one or zero times)
    76 // the optional regular expression (one or zero times)
    77 def OPT(r: Rexp) = ALT(r, ONE)   // r + 1
    77 def OPT(r: Rexp) = ALT(r, ONE)   // r + 1
    78 
    78 
    79 // the n-times regular expression (explicitly expanded)
    79 // the n-times regular expression (explicitly expanded to SEQs)
    80 def NTIMES(r: Rexp, n: Int) : Rexp = n match {
    80 def NTIMES(r: Rexp, n: Int) : Rexp = n match {
    81   case 0 => ONE
    81   case 0 => ONE
    82   case 1 => r
    82   case 1 => r
    83   case n => SEQ(r, NTIMES(r, n - 1))
    83   case n => SEQ(r, NTIMES(r, n - 1))
    84 }
    84 }