progs/lexer/lex.sc
changeset 800 9eea6a801e10
parent 787 4b2496bc79b2
child 827 67c8a6e6a305
equal deleted inserted replaced
799:85267be9a5ed 800:9eea6a801e10
   143   case c::Nil => CHAR(c)
   143   case c::Nil => CHAR(c)
   144   case c::s => ALT(CHAR(c), Range(s))
   144   case c::s => ALT(CHAR(c), Range(s))
   145 }
   145 }
   146 def RANGE(s: String) = Range(s.toList)
   146 def RANGE(s: String) = Range(s.toList)
   147 
   147 
   148 val SYM = RANGE("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz_")
   148 val SYM = RANGE("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_")
   149 val DIGIT = RANGE("0123456789")
   149 val DIGIT = RANGE("0123456789")
   150 val ID = SYM ~ (SYM | DIGIT).% 
   150 val ID = SYM ~ (SYM | DIGIT).% 
   151 val NUM = PLUS(DIGIT)
   151 val NUM = PLUS(DIGIT)
   152 val KEYWORD : Rexp = "skip" | "while" | "do" | "if" | "then" | "else" | "read" | "write" 
   152 val KEYWORD : Rexp = "skip" | "while" | "do" | "if" | "then" | "else" | "read" | "write" 
   153 val SEMI: Rexp = ";"
   153 val SEMI: Rexp = ";"