diff -r 698ed1c96cd0 -r 4ce07c4abdb4 progs/fun.scala --- a/progs/fun.scala Thu Apr 09 07:42:23 2015 +0100 +++ b/progs/fun.scala Fri Apr 10 18:02:04 2015 +0100 @@ -115,8 +115,8 @@ // regular expressions for the While language -val SYM = RANGE("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_") -val DIGIT = RANGE("0123456789") +val SYM = RANGE("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_".toList) +val DIGIT = RANGE("0123456789".toList) val ID = SYM ~ (SYM | DIGIT).% val NUM = PLUS(DIGIT) val KEYWORD : Rexp = "if" | "then" | "else" | "write" | "def" @@ -445,13 +445,15 @@ def compile(class_name: String, input: String) : String = { val tks = tokenizer(input) - //println(Prog.parse(tks)) + println(Prog.parse_single(tks).mkString("\n")) val ast = Prog.parse_single(tks) val instructions = ast.flatMap(compile_decl).mkString (library + instructions).replaceAllLiterally("XXX", class_name) } + + def compile_file(file_name: String) = { val class_name = file_name.split('.')(0) val output = compile(class_name, fromFile(file_name)) @@ -476,5 +478,6 @@ //examples -compile_run("defs.rec") +compile_file("fact.rec") +//compile_run("defs.rec") //compile_run("fact.rec")