|
|
@ -122,8 +122,8 @@ class SemanticAnalyzer(parser: Parser) extends Reporter {
|
|
|
|
case Prim(op, lop, rop) => // Done
|
|
|
|
case Prim(op, lop, rop) => // Done
|
|
|
|
if(!(isOperator(op) || isBOperator(op)))
|
|
|
|
if(!(isOperator(op) || isBOperator(op)))
|
|
|
|
error("undefined primitive operator")
|
|
|
|
error("undefined primitive operator")
|
|
|
|
analyze(lop)
|
|
|
|
analyze(lop)(env)
|
|
|
|
analyze(rop)
|
|
|
|
analyze(rop)(env)
|
|
|
|
case Let(x, a, b) => // val x = a; b
|
|
|
|
case Let(x, a, b) => // val x = a; b
|
|
|
|
// Done: check variable reuse
|
|
|
|
// Done: check variable reuse
|
|
|
|
if(!env.vars.contains(x))
|
|
|
|
if(!env.vars.contains(x))
|
|
|
@ -137,7 +137,6 @@ 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)(env)
|
|
|
|
|
|
|
|
analyze(l)(env)
|
|
|
|
analyze(l)(env)
|
|
|
|
analyze(r)(env)
|
|
|
|
analyze(r)(env)
|
|
|
|
// Done
|
|
|
|
// Done
|
|
|
@ -152,7 +151,7 @@ class SemanticAnalyzer(parser: Parser) extends Reporter {
|
|
|
|
analyze(body)(env)
|
|
|
|
analyze(body)(env)
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
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)(env)
|
|
|
|
analyze(rhs)(env)
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|