From 259e17dc5052af57a5f3faf9049bd11f1efd0e04 Mon Sep 17 00:00:00 2001
From: "lucien.noel" <lucien.noel@etu.hesge.ch>
Date: Mon, 16 Jan 2023 14:52:28 +0100
Subject: [PATCH] =?UTF-8?q?analyse=20de=20la=20division,=20soustraction=20?=
 =?UTF-8?q?et=20multiplication=20termin=C3=A9e?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Visitors/SemanticAnalyzer.java | 39 ++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/Visitors/SemanticAnalyzer.java b/Visitors/SemanticAnalyzer.java
index 58243ac..683cd6a 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;
     }
 
-- 
GitLab