|
|
|
@ -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
|
|
|
|
|