Skip to content
Snippets Groups Projects
Commit becd94b9 authored by lucien.noel's avatar lucien.noel
Browse files

analyse de == corrigée

parent 211e33f5
Branches
No related tags found
No related merge requests found
......@@ -124,20 +124,33 @@ public class SemanticAnalyzer implements ASTVisitor {
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("classe invalide : "+((Parentheses)node.getDroite()).getExpression().getClass());
// // 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");
// }
Expression gauche = (node.getGauche() instanceof Parentheses)? ((Parentheses)node.getGauche()).getExpression(): node.getGauche();
Expression droite = (node.getDroite() instanceof Parentheses)? ((Parentheses)node.getDroite()).getExpression(): node.getDroite();
boolean isComparaisonOk = false;
if ((gauche instanceof Nombre && droite instanceof Nombre) ||
(gauche instanceof Nombre && (droite instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)droite).getNom())).getType() instanceof Entier)) ||
((gauche instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)gauche).getNom())).getType() instanceof Entier) && droite instanceof Nombre) ||
((gauche instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)gauche).getNom())).getType() instanceof Entier) && (droite instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)droite).getNom())).getType() instanceof Entier))) {
//dans le cas ou on compare 2 nombres
isComparaisonOk = true;
}else if (
(gauche instanceof Vrai || gauche instanceof Faux ||
(gauche instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)gauche).getNom())).getType() instanceof Booleen) ||
gauche instanceof Relation)
&&
(droite instanceof Vrai || droite instanceof Faux ||
(droite instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)droite).getNom())).getType() instanceof Booleen) ||
droite instanceof Relation)
) {
//dans le cas où on compare 2 booleans
isComparaisonOk = true;
}
if(!isComparaisonOk){
throw new RuntimeException("Impossible d'effectuer une comparaison entre 2 valeur qui ne sont pas du même type !");
}
return null;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment