diff -r 0cb2464e5d0e -r 485f38b530ab parser.scala --- a/parser.scala Wed Oct 31 08:56:08 2012 +0000 +++ b/parser.scala Wed Oct 31 21:46:27 2012 +0000 @@ -139,7 +139,8 @@ // grammar for arithmetic expressions val grammar = - List ("E" -> List(T_NUM), + List ("F" -> List(T_NUM), + "E" -> List(T_NUM), "E" -> List(NT("E"), T_OP("+"), NT("E")), "E" -> List(NT("E"), T_OP("-"), NT("E")), "E" -> List(NT("E"), T_OP("*"), NT("E")), @@ -165,7 +166,7 @@ } def parse(g: Grammar, ts: List[Token]) : Boolean = { - //println(ts) + println(ts) if (ts == List(NT("E"))) true else { val tss = for ((lhs, rhs) <- g) yield replace(ts, rhs, List(NT(lhs))) @@ -180,7 +181,7 @@ -parser(grammar, lexing_rules, "2 + 3 * 4 + 1") +parser(grammar, lexing_rules, "2 + 3 * 4 + 1") parser(grammar, lexing_rules, "(2 + 3) * (4 + 1)") parser(grammar, lexing_rules, "(2 + 3) * 4 (4 + 1)")