Separating Expression & statement

This commit is contained in:
2017-03-29 10:50:29 +02:00
parent cd186e292d
commit b8b3cedd28
7 changed files with 84 additions and 85 deletions

17
src/Main.java Normal file
View File

@@ -0,0 +1,17 @@
import expression.Expression;
import expression.Tree;
/**
* Created by xawirses on 29/03/17.
*/
public class Main {
public static void main(String[] args) {
Expression e = new Expression();
e.negExpressionPrefixe();
System.out.println(e.getExpressionPrefixe());
System.out.println();
Tree treeExpression = new Tree(e.getExpressionPrefixe());
treeExpression.display();
}
}

View File

@@ -1,61 +0,0 @@
/**
* Created by azael on 20/03/17.
*/
public class Node {
private char node;
private Node father;
private Node leftChild;
private Node rigthChild;
private int lvl;
private int pos = 0;
Node(Node father, Node leftChild, Node rightChild, char name, int lvl){
this.node = name;
this.father = father;
this.leftChild = leftChild;
this.rigthChild = rightChild;
this.lvl = lvl;
}
public void setLeftChild(Node leftChild) { this.leftChild = leftChild; }
public void setRigthChild(Node rigthChild) { this.rigthChild = rigthChild; }
public void setFather(Node father) {
this.father = father;
}
public void display() {
System.out.println(node);
}
public int getLvl() {
return lvl;
}
public Node getLeftChild() {
return leftChild;
}
public Node getRigthChild() {
return rigthChild;
}
public char getNode() {
return node;
}
public Node getFather() {
return father;
}
public int getPos() {
return pos;
}
public void setPos(int pos) {
this.pos = pos;
}
}

View File

@@ -1,3 +1,5 @@
package expression;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -102,10 +104,6 @@ public class Expression {
expressionPrefixe = reverseExpression(reversePrefix);
}
public String getExpression() {
return expression;
}
public String getExpressionPrefixe() {
return expressionPrefixe;
}
@@ -113,14 +111,4 @@ public class Expression {
public void negExpressionPrefixe (){
expressionPrefixe = "!" + expressionPrefixe;
}
public static void main(String[] args) {
Expression e = new Expression();
e.negExpressionPrefixe();
System.out.println(e.getExpressionPrefixe());
System.out.println();
Tree t = new Tree(e.getExpressionPrefixe());
t.display();
}
}

36
src/expression/Node.java Normal file
View File

@@ -0,0 +1,36 @@
package expression;
/**
* Created by azael on 20/03/17.
*/
public class Node {
private char node;
private Node leftChild;
private Node rigthChild;
private int lvl;
Node(Node leftChild, Node rightChild, char name, int lvl){
this.node = name;
this.leftChild = leftChild;
this.rigthChild = rightChild;
this.lvl = lvl;
}
public void display() {
System.out.println(node);
}
public int getLvl() {
return lvl;
}
public Node getLeftChild() {
return leftChild;
}
public Node getRigthChild() {
return rigthChild;
}
}

View File

@@ -1,3 +1,5 @@
package expression;
/**
* Created by xawirses on 28/02/17.
*/

View File

@@ -1,3 +1,7 @@
package expression;
import expression.Expression;
/**
* Created by azael on 20/03/17.
*/
@@ -6,7 +10,7 @@ public class Tree {
private Node root;
private String exp;
Tree (String exp){
public Tree(String exp){
this.exp = exp;
root = tree(0);
}
@@ -17,22 +21,16 @@ public class Tree {
if(Expression.isOperator(item)) {
if (item == '!'){
Node fils = tree(pos+1);
Node f = new Node(null, fils, null, item, 1+fils.getLvl());
fils.setPos(1);
fils.setFather(f);
Node f = new Node(fils, null, item, 1+fils.getLvl());
return f;
} else {
Node filsG = tree(pos+1);
Node filsD = tree(pos+filsG.getLvl()+1);
Node f = new Node(null, filsG, filsD, item, filsG.getLvl() + filsD.getLvl()+1);
filsG.setPos(1);
filsD.setPos(2);
filsG.setFather(f);
filsD.setFather(f);
Node f = new Node(filsG, filsD, item, filsG.getLvl() + filsD.getLvl()+1);
return f;
}
} else {
return new Node(null, null, null, item, 1);
return new Node(null, null, item, 1);
}
}

19
src/statement/World.java Normal file
View File

@@ -0,0 +1,19 @@
package statement;
import expression.Node;
import java.util.ArrayList;
import java.util.Collection;
/**
* Created by xawirses on 29/03/17.
*/
public class World {
private String name;
private Collection<Node> expressions = new ArrayList<>();
private Collection<World> involved = new ArrayList<>();
public World(String name) {
this.name = name;
}
}