From 8363ac04fd9f15efbbedece883e442cc02b71dbb Mon Sep 17 00:00:00 2001
From: "lucien.noel" <lucien.noel@etu.hesge.ch>
Date: Wed, 30 Nov 2022 19:03:50 +0100
Subject: [PATCH] git cest de la merde

---
 ArbreAbstrait/Diff.java                   | 26 ++++++++
 ArbreAbstrait/InfEgal.java                | 26 ++++++++
 ArbreAbstrait/Inferieur.java              | 26 ++++++++
 ArbreAbstrait/SupEgal.java                | 26 ++++++++
 ArbreAbstrait/Superieur.java              | 26 ++++++++
 Tests/test_base_with_sementic_issue.input |  3 +-
 Visitors/ASTVisitor.java                  | 10 +--
 Visitors/ByteCodeGenerator.java           | 10 +--
 Visitors/SemanticAnalyzer.java            | 10 +--
 Visitors/SourceCodeGenerator.java         | 74 +++++++++++------------
 hepial.cup                                | 10 +--
 11 files changed, 189 insertions(+), 58 deletions(-)
 create mode 100644 ArbreAbstrait/Diff.java
 create mode 100644 ArbreAbstrait/InfEgal.java
 create mode 100644 ArbreAbstrait/Inferieur.java
 create mode 100644 ArbreAbstrait/SupEgal.java
 create mode 100644 ArbreAbstrait/Superieur.java

diff --git a/ArbreAbstrait/Diff.java b/ArbreAbstrait/Diff.java
new file mode 100644
index 0000000..b7a576f
--- /dev/null
+++ b/ArbreAbstrait/Diff.java
@@ -0,0 +1,26 @@
+/*
+ * Represent an equal comparaison expression node inside the AST.
+ */
+
+public class Diff extends Relation {
+    /**
+     * Constructor
+     */
+    public Diff(Expression operandeGauche, Expression operandeDroite, String fl, int line, int col) {
+        super(operandeGauche, operandeDroite, fl, line, col);
+    }
+
+    /**
+     * Get the binary operator
+     */
+    public String operateur() {
+        return "<>";
+    }
+
+    /**
+     * Accepts a AST visitor
+     */
+    Object accept(ASTVisitor visitor){
+        return visitor.visit(this);
+    }
+}
diff --git a/ArbreAbstrait/InfEgal.java b/ArbreAbstrait/InfEgal.java
new file mode 100644
index 0000000..d3d6719
--- /dev/null
+++ b/ArbreAbstrait/InfEgal.java
@@ -0,0 +1,26 @@
+/*
+ * Represent an equal comparaison expression node inside the AST.
+ */
+
+public class InfEgal extends Relation {
+    /**
+     * Constructor
+     */
+    public InfEgal(Expression operandeGauche, Expression operandeDroite, String fl, int line, int col) {
+        super(operandeGauche, operandeDroite, fl, line, col);
+    }
+
+    /**
+     * Get the binary operator
+     */
+    public String operateur() {
+        return "<=";
+    }
+
+    /**
+     * Accepts a AST visitor
+     */
+    Object accept(ASTVisitor visitor){
+        return visitor.visit(this);
+    }
+}
diff --git a/ArbreAbstrait/Inferieur.java b/ArbreAbstrait/Inferieur.java
new file mode 100644
index 0000000..2148a16
--- /dev/null
+++ b/ArbreAbstrait/Inferieur.java
@@ -0,0 +1,26 @@
+/*
+ * Represent an equal comparaison expression node inside the AST.
+ */
+
+public class Inferieur extends Relation {
+    /**
+     * Constructor
+     */
+    public Inferieur(Expression operandeGauche, Expression operandeDroite, String fl, int line, int col) {
+        super(operandeGauche, operandeDroite, fl, line, col);
+    }
+
+    /**
+     * Get the binary operator
+     */
+    public String operateur() {
+        return "<";
+    }
+
+    /**
+     * Accepts a AST visitor
+     */
+    Object accept(ASTVisitor visitor){
+        return visitor.visit(this);
+    }
+}
diff --git a/ArbreAbstrait/SupEgal.java b/ArbreAbstrait/SupEgal.java
new file mode 100644
index 0000000..9615aef
--- /dev/null
+++ b/ArbreAbstrait/SupEgal.java
@@ -0,0 +1,26 @@
+/*
+ * Represent an equal comparaison expression node inside the AST.
+ */
+
+public class SupEgal extends Relation {
+    /**
+     * Constructor
+     */
+    public SupEgal(Expression operandeGauche, Expression operandeDroite, String fl, int line, int col) {
+        super(operandeGauche, operandeDroite, fl, line, col);
+    }
+
+    /**
+     * Get the binary operator
+     */
+    public String operateur() {
+        return "=<";
+    }
+
+    /**
+     * Accepts a AST visitor
+     */
+    Object accept(ASTVisitor visitor){
+        return visitor.visit(this);
+    }
+}
diff --git a/ArbreAbstrait/Superieur.java b/ArbreAbstrait/Superieur.java
new file mode 100644
index 0000000..8222d91
--- /dev/null
+++ b/ArbreAbstrait/Superieur.java
@@ -0,0 +1,26 @@
+/*
+ * Represent an equal comparaison expression node inside the AST.
+ */
+
+public class Superieur extends Relation {
+    /**
+     * Constructor
+     */
+    public Superieur(Expression operandeGauche, Expression operandeDroite, String fl, int line, int col) {
+        super(operandeGauche, operandeDroite, fl, line, col);
+    }
+
+    /**
+     * Get the binary operator
+     */
+    public String operateur() {
+        return ">";
+    }
+
+    /**
+     * Accepts a AST visitor
+     */
+    Object accept(ASTVisitor visitor){
+        return visitor.visit(this);
+    }
+}
diff --git a/Tests/test_base_with_sementic_issue.input b/Tests/test_base_with_sementic_issue.input
index e8b8ad4..afe9a63 100755
--- a/Tests/test_base_with_sementic_issue.input
+++ b/Tests/test_base_with_sementic_issue.input
@@ -2,5 +2,6 @@ programme Program
 
 debutprg
     c = c * 2;
-    b = faux et vrai;
+    b = 3;
+    d = c <> b;
 finprg
diff --git a/Visitors/ASTVisitor.java b/Visitors/ASTVisitor.java
index 1d4bfa7..0155cbb 100755
--- a/Visitors/ASTVisitor.java
+++ b/Visitors/ASTVisitor.java
@@ -23,7 +23,7 @@ public interface ASTVisitor {
     Object visit(DeclarationProgramme node);
 
     // Object visit(DeclarationVariable node);
-    // Object visit(Diff node);
+    Object visit(Diff node);
     Object visit(Division node);
 
     // Object visit(Ecrire node);
@@ -34,8 +34,8 @@ public interface ASTVisitor {
     Object visit(Faux node);
     Object visit(Idf node);
 
-    // Object visit(InfEgal node);
-    // Object visit(Inferieur node);
+    Object visit(InfEgal node);
+    Object visit(Inferieur node);
     // Object visit(Lire node);
     // Object visit(Moins node);
     Object visit(Nombre node);
@@ -47,8 +47,8 @@ public interface ASTVisitor {
     Object visit(Produit node);
 
     Object visit(Soustraction node);
-    // Object visit(SupEgal node);
-    // Object visit(Superieur node);
+    Object visit(SupEgal node);
+    Object visit(Superieur node);
     // Object visit(Tantque node);
     Object visit(Vrai node);
 }
diff --git a/Visitors/ByteCodeGenerator.java b/Visitors/ByteCodeGenerator.java
index e4bd373..6775412 100755
--- a/Visitors/ByteCodeGenerator.java
+++ b/Visitors/ByteCodeGenerator.java
@@ -34,7 +34,7 @@ public class ByteCodeGenerator implements ASTVisitor {
 
     // public Object visit(DeclarationVariable node) { return null; }
 
-    // public Object visit(Diff node) { return null; }
+    public Object visit(Diff node) { return null; }
 
     public Object visit(Division node) {
         return null;
@@ -56,9 +56,9 @@ public class ByteCodeGenerator implements ASTVisitor {
         return null;
     }
 
-    // public Object visit(InfEgal node) { return null; }
+    public Object visit(InfEgal node) { return null; }
 
-    // public Object visit(Inferieur node) { return null; }
+    public Object visit(Inferieur node) { return null; }
 
     // public Object visit(Lire node) { return null; }
 
@@ -86,9 +86,9 @@ public class ByteCodeGenerator implements ASTVisitor {
         return null;
     }
 
-    // public Object visit(SupEgal node) { return null; }
+    public Object visit(SupEgal node) { return null; }
 
-    // public Object visit(Superieur node) { return null; }
+    public Object visit(Superieur node) { return null; }
 
     // public Object visit(Tantque node) { return null; }
 
diff --git a/Visitors/SemanticAnalyzer.java b/Visitors/SemanticAnalyzer.java
index 8ed56c3..72f1e0d 100755
--- a/Visitors/SemanticAnalyzer.java
+++ b/Visitors/SemanticAnalyzer.java
@@ -36,7 +36,7 @@ public class SemanticAnalyzer implements ASTVisitor {
 
     // public Object visit(DeclarationVariable node) { return null; }
 
-    // public Object visit(Diff node) { return null; }
+    public Object visit(Diff node) { return null; }
 
     public Object visit(Division node) {
         return null;
@@ -58,9 +58,9 @@ public class SemanticAnalyzer implements ASTVisitor {
         return null;
     }
 
-    // public Object visit(InfEgal node) { return null; }
+    public Object visit(InfEgal node) { return null; }
 
-    // public Object visit(Inferieur node) { return null; }
+    public Object visit(Inferieur node) { return null; }
 
     // public Object visit(Lire node) { return null; }
 
@@ -88,9 +88,9 @@ public class SemanticAnalyzer implements ASTVisitor {
         return null;
     }
 
-    // public Object visit(SupEgal node) { return null; }
+    public Object visit(SupEgal node) { return null; }
 
-    // public Object visit(Superieur node) { return null; }
+    public Object visit(Superieur node) { return null; }
 
     // public Object visit(Tantque node) { return null; }
 
diff --git a/Visitors/SourceCodeGenerator.java b/Visitors/SourceCodeGenerator.java
index a6e1dbd..66da141 100755
--- a/Visitors/SourceCodeGenerator.java
+++ b/Visitors/SourceCodeGenerator.java
@@ -117,14 +117,14 @@ public class SourceCodeGenerator implements ASTVisitor {
     // code += ";";
     // return null;
     // }
-    //
-    // public Object visit(Diff node){
-    // node.getGauche().accept(this);
-    // code += " <> ";
-    // node.getDroite().accept(this);
-    // return null;
-    // }
-    //
+    
+    public Object visit(Diff node){
+    node.getGauche().accept(this);
+    code += " <> ";
+    node.getDroite().accept(this);
+    return null;
+    }
+    
     public Object visit(Division node) {
         node.getGauche().accept(this);
         code += " / ";
@@ -163,20 +163,20 @@ public class SourceCodeGenerator implements ASTVisitor {
         return null;
     }
 
-    // public Object visit(InfEgal node){
-    // node.getGauche().accept(this);
-    // code += " <= ";
-    // node.getDroite().accept(this);
-    // return null;
-    // }
-    //
-    // public Object visit(Inferieur node){
-    // node.getGauche().accept(this);
-    // code += " < ";
-    // node.getDroite().accept(this);
-    // return null;
-    // }
-    //
+    public Object visit(InfEgal node){
+    node.getGauche().accept(this);
+    code += " <= ";
+    node.getDroite().accept(this);
+    return null;
+    }
+    
+    public Object visit(Inferieur node){
+    node.getGauche().accept(this);
+    code += " < ";
+    node.getDroite().accept(this);
+    return null;
+    }
+    
     // public Object visit(Lire node){
     // code += "lire ";
     // node.getDestination().accept(this);
@@ -245,21 +245,21 @@ public class SourceCodeGenerator implements ASTVisitor {
         node.getDroite().accept(this);
         return null;
     }
-    //
-    // public Object visit(SupEgal node){
-    // node.getGauche().accept(this);
-    // code += " >= ";
-    // node.getDroite().accept(this);
-    // return null;
-    // }
-    //
-    // public Object visit(Superieur node){
-    // node.getGauche().accept(this);
-    // code += " > ";
-    // node.getDroite().accept(this);
-    // return null;
-    // }
-    //
+    
+    public Object visit(SupEgal node){
+    node.getGauche().accept(this);
+    code += " >= ";
+    node.getDroite().accept(this);
+    return null;
+    }
+    
+    public Object visit(Superieur node){
+    node.getGauche().accept(this);
+    code += " > ";
+    node.getDroite().accept(this);
+    return null;
+    }
+    
     // public Object visit(Tantque node){
     // code += "tantque ";
     // node.getCondition().accept(this);
diff --git a/hepial.cup b/hepial.cup
index adbe72f..a79d455 100755
--- a/hepial.cup
+++ b/hepial.cup
@@ -83,11 +83,11 @@ op_bin            ::= expr:a PLUS expr:b    {: RESULT = new Addition(a, b, "", a
                       | expr:a OR expr:b        {: RESULT = new Ou(a, b, "", aleft, aright);:};
 
 relation          ::= expr:a EQUALS expr:b  {: RESULT = new Egal(a, b, "", aleft, aright); :}
-                      | expr DIFF expr      {: :}
-                      | expr INF expr       {: :}
-                      | expr SUP expr       {: :}
-                      | expr INFEQUAL expr  {: :}
-                      | expr SUPEQUAL expr  {: :};
+                      |expr:a DIFF expr:b   {: RESULT = new Diff(a, b, "", aleft, aright); :}
+                      | expr:a INF expr:b   {: RESULT = new Inferieur(a, b, "", aleft, aright); :}
+                      | expr:a SUP expr:b   {: RESULT = new Superieur(a, b, "", aleft, aright); :}
+                      | expr:a INFEQUAL expr:b  {: RESULT = new InfEgal(a, b, "", aleft, aright); :}
+                      | expr:a SUPEQUAL expr:b  {: RESULT = new SupEgal(a, b, "", aleft, aright); :};
 
 op_una             ::= NOT expr       {: :}
                       | MINUS expr    {: :}
-- 
GitLab