|
|
@ -137,9 +137,9 @@ class SemanticAnalyzer(parser: Parser) extends Reporter {
|
|
|
|
case Cond(op, l, r) =>
|
|
|
|
case Cond(op, l, r) =>
|
|
|
|
if (!isBOperator(op))
|
|
|
|
if (!isBOperator(op))
|
|
|
|
error(s"$op is not a boolean operator")
|
|
|
|
error(s"$op is not a boolean operator")
|
|
|
|
analyze(op)
|
|
|
|
analyze(op)(env)
|
|
|
|
analyze(l)
|
|
|
|
analyze(l)(env)
|
|
|
|
analyze(r)
|
|
|
|
analyze(r)(env)
|
|
|
|
// Done
|
|
|
|
// Done
|
|
|
|
case If(cond, tBranch, eBranch) =>
|
|
|
|
case If(cond, tBranch, eBranch) =>
|
|
|
|
analyze(cond)(env)
|
|
|
|
analyze(cond)(env)
|
|
|
@ -154,12 +154,12 @@ class SemanticAnalyzer(parser: Parser) extends Reporter {
|
|
|
|
case VarAssign(x, rhs) => // x = rhs
|
|
|
|
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"}")
|
|
|
|
error(s"cannot assign $x: ${if(env.vars.contains(x))"immutable"else"undefined"}")
|
|
|
|
analyze(rhs)
|
|
|
|
analyze(rhs)(env)
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
case While(cond, lBody, body) =>
|
|
|
|
case While(cond, lBody, body) =>
|
|
|
|
analyze(cond)
|
|
|
|
analyze(cond)(env)
|
|
|
|
analyze(lBody)
|
|
|
|
analyze(lBody)(env)
|
|
|
|
analyze(body)
|
|
|
|
analyze(body)(env)
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
case _ => abort(s"unknown AST node $exp")
|
|
|
|
case _ => abort(s"unknown AST node $exp")
|
|
|
|
}
|
|
|
|
}
|
|
|
|