bug fixes
This commit is contained in:
@@ -262,7 +262,7 @@ class StackInterpreter extends Interpreter with BugReporter {
|
||||
case Prim(op, lop, rop) =>
|
||||
eval(lop, sp)(env)
|
||||
eval(rop, sp + 1)(env)
|
||||
evalBin(sp, sp + 1)
|
||||
evalBin(op)(sp, sp + 1)
|
||||
case Let(x, a, b) =>
|
||||
eval(a, sp)(env)
|
||||
eval(b, sp + 1)(env.withVal(x, sp))
|
||||
|
||||
@@ -128,7 +128,7 @@ class Scanner(in: Reader[Char]) extends Reader[Tokens.Token] with Reporter {
|
||||
* TODO: implement the method
|
||||
*/
|
||||
def getNum() = {
|
||||
val buf = new java.lang.StringBuilder
|
||||
val buf = new StringBuilder
|
||||
while (in.hasNext(isDigit)) {
|
||||
buf += in.next()
|
||||
}
|
||||
@@ -596,7 +596,7 @@ class VariableParser(in: Scanner) extends BranchParser(in) {
|
||||
// TODO: remove ??? and complete the implementation.
|
||||
override def parseSimpleExpression = (in.peek, in.peek1) match {
|
||||
case (Ident(x), Delim('=')) =>
|
||||
val pos = in.pos
|
||||
val pos:Position = in.peek.pos
|
||||
VarAssign(x, parseSimpleExpression).withPos(pos)
|
||||
case _ => super.parseExpression
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ class SemanticAnalyzer(parser: Parser) extends Reporter {
|
||||
case Prim(op, lop, rop) => // Done
|
||||
if(!(isOperator(op) || isBOperator(op)))
|
||||
error("undefined primitive operator")
|
||||
analyze(lop)
|
||||
analyze(rop)
|
||||
analyze(lop)(env)
|
||||
analyze(rop)(env)
|
||||
case Let(x, a, b) => // val x = a; b
|
||||
// Done: check variable reuse
|
||||
if(!env.vars.contains(x))
|
||||
@@ -137,7 +137,6 @@ class SemanticAnalyzer(parser: Parser) extends Reporter {
|
||||
case Cond(op, l, r) =>
|
||||
if (!isBOperator(op))
|
||||
error(s"$op is not a boolean operator")
|
||||
analyze(op)(env)
|
||||
analyze(l)(env)
|
||||
analyze(r)(env)
|
||||
// Done
|
||||
@@ -152,7 +151,7 @@ class SemanticAnalyzer(parser: Parser) extends Reporter {
|
||||
analyze(body)(env)
|
||||
// TODO
|
||||
case VarAssign(x, rhs) => // x = rhs
|
||||
if (!(env.vars.contains(x) && env.vars[x]))
|
||||
if (!(env.vars.contains(x) && env.vars(x)))
|
||||
error(s"cannot assign $x: ${if(env.vars.contains(x))"immutable"else"undefined"}")
|
||||
analyze(rhs)(env)
|
||||
// TODO
|
||||
|
||||
Reference in New Issue
Block a user