private static boolean assignmentsSound(Node node) { Set<String> toAssign = new HashSet<>(); toAssign.addAll(Util.getIds(node.outputs)); toAssign.addAll(Util.getIds(node.locals)); Set<String> assigned = new HashSet<>(); boolean sound = true; for (Equation eq : node.equations) { for (IdExpr idExpr : eq.lhs) { if (toAssign.contains(idExpr.id)) { toAssign.remove(idExpr.id); assigned.add(idExpr.id); } else if (assigned.contains(idExpr.id)) { System.out.println( "Error at line " + idExpr.location + " variable '" + idExpr.id + "' cannot be reassigned"); sound = false; } else { System.out.println( "Error at line " + idExpr.location + " variable '" + idExpr.id + "' cannot be assigned"); sound = false; } } } if (!toAssign.isEmpty()) { System.out.println("Error in node '" + node.id + "' variables must be assigned: " + toAssign); sound = false; } return sound; }
private static boolean propertiesExist(Program program) { boolean exist = true; for (Node node : program.nodes) { Set<String> variables = new HashSet<>(Util.getIds(Util.getVarDecls(node))); for (String prop : node.properties) { if (!variables.contains(prop)) { System.out.println( "Error: property '" + prop + "' does not exist in node '" + node.id + "'"); exist = false; } } } return exist; }