syntaxError(errorMessage(UNKNOWN_VARIABLE), context, expr);
return null;
}
} else if (expr instanceof Expr.BinOp) {
Expr.BinOp bop = (Expr.BinOp) expr;
Constant lhs = resolveAsConstant(bop.lhs, context, visited);
Constant rhs = resolveAsConstant(bop.rhs, context, visited);
return evaluate(bop, lhs, rhs, context);
} else if (expr instanceof Expr.UnOp) {
Expr.UnOp uop = (Expr.UnOp) expr;
Constant lhs = resolveAsConstant(uop.mhs, context, visited);
return evaluate(uop, lhs, context);
} else if (expr instanceof Expr.Set) {
Expr.Set nop = (Expr.Set) expr;
ArrayList<Constant> values = new ArrayList<Constant>();
for (Expr arg : nop.arguments) {
values.add(resolveAsConstant(arg, context, visited));
}
return Constant.V_SET(values);
} else if (expr instanceof Expr.List) {
Expr.List nop = (Expr.List) expr;
ArrayList<Constant> values = new ArrayList<Constant>();
for (Expr arg : nop.arguments) {
values.add(resolveAsConstant(arg, context, visited));
}
return Constant.V_LIST(values);
} else if (expr instanceof Expr.Record) {
Expr.Record rg = (Expr.Record) expr;
HashMap<String, Constant> values = new HashMap<String, Constant>();
for (Map.Entry<String, Expr> e : rg.fields.entrySet()) {
Constant v = resolveAsConstant(e.getValue(), context,
visited);
if (v == null) {
return null;
}
values.put(e.getKey(), v);
}
return Constant.V_RECORD(values);
} else if (expr instanceof Expr.Tuple) {
Expr.Tuple rg = (Expr.Tuple) expr;
ArrayList<Constant> values = new ArrayList<Constant>();
for (Expr e : rg.fields) {
Constant v = resolveAsConstant(e, context, visited);
if (v == null) {
return null;
}
values.add(v);
}
return Constant.V_TUPLE(values);
} else if (expr instanceof Expr.Map) {
Expr.Map rg = (Expr.Map) expr;
HashSet<Pair<Constant, Constant>> values = new HashSet<Pair<Constant, Constant>>();
for (Pair<Expr, Expr> e : rg.pairs) {
Constant key = resolveAsConstant(e.first(), context,
visited);
Constant value = resolveAsConstant(e.second(), context,
visited);
if (key == null || value == null) {
return null;
}
values.add(new Pair<Constant, Constant>(key, value));