From d36e246b082a532933079255ff763667f48c8709 Mon Sep 17 00:00:00 2001
From: Yingjian Wang <yingjian.wang@mailbox.tu-dresden.de>
Date: Wed, 19 Jan 2022 00:26:33 +0100
Subject: [PATCH] Upload New File

---
 src/main/jastadd/hanoi/Term.jrag | 105 +++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
 create mode 100644 src/main/jastadd/hanoi/Term.jrag

diff --git a/src/main/jastadd/hanoi/Term.jrag b/src/main/jastadd/hanoi/Term.jrag
new file mode 100644
index 0000000..9571b0b
--- /dev/null
+++ b/src/main/jastadd/hanoi/Term.jrag
@@ -0,0 +1,105 @@
+import java.util.*;
+aspect Connectives{
+    uncache Term.eval();
+    syn int Term.eval();
+    eq Plus.eval(){
+        return this.getLeft().eval() + this.getRight().eval();
+    }
+    eq Minus.eval(){
+        return this.getLeft().eval() - this.getRight().eval();
+    }
+    eq Multi.eval(){
+        return this.getLeft().eval() * this.getRight().eval();
+    }
+    eq Divide.eval(){
+        return this.getLeft().eval() / this.getRight().eval();
+    }
+    eq Mod.eval(){
+        return this.getLeft().eval() % this.getRight().eval();
+    }
+    eq IfThenElse.eval(){
+        if(this.getIf().Satisfied()){
+           return this.getThen().eval();
+        }
+        return this.getElse().eval();
+    }
+    eq CompareFunction.eval(){
+        if(this.getLeft().eval() < this.getRight().eval()){
+            return 1;
+        }
+        return 0;
+    }
+    eq EqualFunction.eval(){
+        if(this.getLeft().eval() == this.getRight().eval()){
+            return 1;
+        }
+        return 0;
+    }
+    eq SubsetofFunction.eval(){
+        Set left=new HashSet<>(); 
+        for(String element : this.getLeft().Set()){ 
+            left.add(element);
+        }
+        Set right=new HashSet<>(); 
+        for(String element : this.getRight().Set()){ 
+            right.add(element);
+        }
+        if(right.containsAll(left)){
+            return 1;
+        }
+        return 0;
+    }
+    eq ConstantNum.eval(){
+        return this.getNum();
+    }
+    eq PillarID.eval(){
+        return this.getRel().ID();
+    }
+    eq TotalDiskAmount.eval(){
+        return this.getRel().AmountD();
+    }
+    eq DisksOnPillar.eval(){
+        return this.getRel().getNumDisk();
+    }
+    eq TopDiskSize.eval(){
+        return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize();
+    }
+//customerized terms
+    eq Term1.eval(){//return the size of top disk
+        if(this.getRel().getNumDisk()>0){
+            //if the pillar is not empty, check if the top disk has size 1
+                return  this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize();
+            }else{
+                return -1;//no disk, the number is invalid, return -1
+            }
+    }
+    eq Term2.eval(){
+        return this.getRel().moveSeq();
+    }
+    eq Term3.eval(){
+        return this.getRel().ID();
+    }
+    uncache Condition.Satisfied();
+    syn boolean Condition.Satisfied();
+    eq CompareFunction.Satisfied(){
+        return this.getLeft().eval() < this.getRight().eval();
+    }
+    eq EqualFunction.Satisfied(){
+        return this.getLeft().eval() == this.getRight().eval();
+    }
+    eq SubsetofFunction.Satisfied(){
+        Set left=new HashSet<>(); 
+        for(String element : this.getLeft().Set()){ 
+            left.add(element);
+        }
+        Set right=new HashSet<>(); 
+        for(String element : this.getRight().Set()){ 
+            right.add(element);
+        }
+        return right.containsAll(left);
+    }
+    public String[] Term.Set(){
+        String[] str=new String[]{};
+        return str;
+    }
+}
\ No newline at end of file
-- 
GitLab