diff --git a/Visitors/SemanticAnalyzer.java b/Visitors/SemanticAnalyzer.java index 58243ac46d3460e009bb9902ccbdb824bc821f19..683cd6ab8f0ba2113d0bcd0bf2a98da538f11a66 100755 --- a/Visitors/SemanticAnalyzer.java +++ b/Visitors/SemanticAnalyzer.java @@ -87,6 +87,19 @@ public class SemanticAnalyzer implements ASTVisitor { public Object visit(Division node) { node.getGauche().accept(this); node.getDroite().accept(this); + + //test si la partie de gauche est un nombre ou un Idf qui pointe vers un entier + if (!(node.getGauche() instanceof Nombre || + (node.getGauche() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getGauche()).getNom())).getType() instanceof Entier)) + ) { + throw new RuntimeException("Impossible d'effectuer la divions car la valeur de gauche n'est pas un nombre !"); + } + //test si la partie de droite est un nombre ou un Idf qui pointe vers un 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 la division car la valeur de droite n'est pas un nombre !"); + } return null; } @@ -169,6 +182,19 @@ public class SemanticAnalyzer implements ASTVisitor { public Object visit(Produit node) { node.getGauche().accept(this); node.getDroite().accept(this); + + //test si la partie de gauche est un nombre ou un Idf qui pointe vers un entier + if (!(node.getGauche() instanceof Nombre || + (node.getGauche() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getGauche()).getNom())).getType() instanceof Entier)) + ) { + throw new RuntimeException("Impossible d'effectuer la multiplication car la valeur de gauche n'est pas un nombre !"); + } + //test si la partie de droite est un nombre ou un Idf qui pointe vers un 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 la multiplication car la valeur de droite n'est pas un nombre !"); + } return null; } @@ -179,6 +205,19 @@ public class SemanticAnalyzer implements ASTVisitor { public Object visit(Soustraction node) { node.getGauche().accept(this); node.getDroite().accept(this); + + //test si la partie de gauche est un nombre ou un Idf qui pointe vers un entier + if (!(node.getGauche() instanceof Nombre || + (node.getGauche() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getGauche()).getNom())).getType() instanceof Entier)) + ) { + throw new RuntimeException("Impossible d'effectuer la soustraction car la valeur de gauche n'est pas un nombre !"); + } + //test si la partie de droite est un nombre ou un Idf qui pointe vers un 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 la soustraction car la valeur de droite n'est pas un nombre !"); + } return null; }