BITCH

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import scala.util.matching.Regex
class Lexer(val programText : String) {
val ident = "[A-Z]'|[A-Z]"
val text = "\"(.*?)\""
val lparen = "\\("
val rparen = "\\)"
val star = "\\*"
val space = "[ \t\n]*"
val pattern = new Regex("("+ident+")|("+lparen+")|("+rparen+")|("+text+")|("+star+")", "ident", "lparen", "rparen", "text", "star")
def analyze() = {
pattern.findFirstMatchIn(programText)
}
def findLexem(text : String): List[String] = pattern.findFirstMatchIn(text) match {
case None => Nil
case x => x :: findLexem(x.after())
}
}