diff --git a/ArbreAbstrait/Booleen.java b/ArbreAbstrait/Booleen.java index a15aaba85e375edb550600db3506e2421bd5276b..d19b233c779840cea2409b1754c0aff05eb43429 100644 --- a/ArbreAbstrait/Booleen.java +++ b/ArbreAbstrait/Booleen.java @@ -2,6 +2,4 @@ public class Booleen extends Ttype{ public Booleen() { super("booleen"); } - - } diff --git a/ArbreAbstrait/Symbole.java b/ArbreAbstrait/Symbole.java index ecda4c57497c5275b6b238eed0dc61fcc4ff8485..67d470893a4b79d682d4fb213ec51348f13ae9ba 100755 --- a/ArbreAbstrait/Symbole.java +++ b/ArbreAbstrait/Symbole.java @@ -13,6 +13,10 @@ public class Symbole{ } + public Ttype getType(){ + return this.type; + } + @Override public String toString() { // TODO Auto-generated method stub diff --git a/Visitors/SemanticAnalyzer.java b/Visitors/SemanticAnalyzer.java index 683cd6ab8f0ba2113d0bcd0bf2a98da538f11a66..796b9106103ba27a178fb113baff84108fd40258 100755 --- a/Visitors/SemanticAnalyzer.java +++ b/Visitors/SemanticAnalyzer.java @@ -111,6 +111,19 @@ public class SemanticAnalyzer implements ASTVisitor { public Object visit(Egal node) { node.getGauche().accept(this); node.getDroite().accept(this); + + //test si la valeur à gauche et à droite du == sont du même type + if(node.getGauche() instanceof Vrai || node.getGauche() instanceof Faux || (node.getGauche() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getGauche()).getNom())).getType() instanceof Booleen)){ + if(!(node.getDroite() instanceof Vrai || node.getDroite() instanceof Faux || (node.getDroite() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getDroite()).getNom())).getType() instanceof Booleen))){ + throw new RuntimeException("Impossible d'effectuer une comparaison entre 2 valeur qui ne sont pas du même type !"); + } + }else if(node.getGauche() instanceof Nombre || (node.getGauche() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getGauche()).getNom())).getType() instanceof Entier)){ + if(!(node.getDroite() instanceof Nombre || (node.getDroite() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getDroite()).getNom())).getType() instanceof Entier))){ + throw new RuntimeException("Impossible d'effectuer une comparaison entre 2 valeur qui ne sont pas du même type !"); + } + }else{ + throw new RuntimeException("Normalement cette exception ne devrait jamais apparaitre mais on ne sait jamais"); + } return null; }