From bd908688c4d58b50b7a0b32b30b1d02275ef77dd Mon Sep 17 00:00:00 2001 From: "lucien.noel" <lucien.noel@etu.hesge.ch> Date: Mon, 16 Jan 2023 15:05:23 +0100 Subject: [PATCH] =?UTF-8?q?analyse=20du=20=3D=3D=20termin=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArbreAbstrait/Booleen.java | 2 -- ArbreAbstrait/Symbole.java | 4 ++++ Visitors/SemanticAnalyzer.java | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ArbreAbstrait/Booleen.java b/ArbreAbstrait/Booleen.java index a15aaba..d19b233 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 ecda4c5..67d4708 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 683cd6a..796b910 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; } -- GitLab