progs/lexer/lex.sc
changeset 1019 f71399fe3fdc
parent 1010 adc61c55e165
child 1020 36799f7b9702
equal deleted inserted replaced
1018:fd6a64c53f0e 1019:f71399fe3fdc
    97   case Chr(c) => Nil
    97   case Chr(c) => Nil
    98   case Left(v) => env(v)
    98   case Left(v) => env(v)
    99   case Right(v) => env(v)
    99   case Right(v) => env(v)
   100   case Sequ(v1, v2) => env(v1) ::: env(v2)
   100   case Sequ(v1, v2) => env(v1) ::: env(v2)
   101   case Stars(vs) => vs.flatMap(env)
   101   case Stars(vs) => vs.flatMap(env)
   102   case Rec[A](x, v) => (x, flatten(v))::env(v)  
   102   case Rec(x: A, v) => (x, flatten(v))::env(v)  
   103 }
   103 }
   104 
   104 
   105 
   105 
   106 // The injection and mkeps part of the lexer
   106 // The injection and mkeps part of the lexer
   107 //===========================================
   107 //===========================================
   175 }
   175 }
   176 import TAGS._
   176 import TAGS._
   177 
   177 
   178 
   178 
   179 extension (t: TAGS) {
   179 extension (t: TAGS) {
   180   def $ (r: Rexp) = RECD[TAGS](t, r)
   180   def & (r: Rexp) = RECD[TAGS](t, r)
   181 }
   181 }
   182 
   182 
   183 def lexing(r: Rexp, s: String) = 
   183 def lexing(r: Rexp, s: String) = 
   184   env[TAGS](lex(r, s.toList))
   184   env[TAGS](lex(r, s.toList))
   185 
   185 
   186 val WHILE_REGS = ((Key $ KEYWORD) | 
   186 val WHILE_REGS = ((Key & KEYWORD) | 
   187                   (Id $ ID) | 
   187                   (Id & ID) | 
   188                   (Op $ OP) | 
   188                   (Op & OP) | 
   189                   (Num $ NUM) | 
   189                   (Num & NUM) | 
   190                   (Semi $ SEMI) | 
   190                   (Semi & SEMI) | 
   191                   (Str $ STRING) |
   191                   (Str & STRING) |
   192                   (Paren $ (LPAREN | RPAREN)) | 
   192                   (Paren & (LPAREN | RPAREN)) | 
   193                   (Wht $ WHITESPACE)).%
   193                   (Wht & WHITESPACE)).%
   194 
   194 
   195 
   195 
   196 // Two Simple While Tests
   196 // Two Simple While Tests
   197 //========================
   197 //========================
   198  
   198