Separating Expression & statement
This commit is contained in:
17
src/Main.java
Normal file
17
src/Main.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
package expression;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -102,10 +104,6 @@ public class Expression {
|
|||||||
expressionPrefixe = reverseExpression(reversePrefix);
|
expressionPrefixe = reverseExpression(reversePrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExpression() {
|
|
||||||
return expression;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getExpressionPrefixe() {
|
public String getExpressionPrefixe() {
|
||||||
return expressionPrefixe;
|
return expressionPrefixe;
|
||||||
}
|
}
|
||||||
@@ -113,14 +111,4 @@ public class Expression {
|
|||||||
public void negExpressionPrefixe (){
|
public void negExpressionPrefixe (){
|
||||||
expressionPrefixe = "!" + expressionPrefixe;
|
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
36
src/expression/Node.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
package expression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by xawirses on 28/02/17.
|
* Created by xawirses on 28/02/17.
|
||||||
*/
|
*/
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
package expression;
|
||||||
|
|
||||||
|
import expression.Expression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by azael on 20/03/17.
|
* Created by azael on 20/03/17.
|
||||||
*/
|
*/
|
||||||
@@ -6,7 +10,7 @@ public class Tree {
|
|||||||
private Node root;
|
private Node root;
|
||||||
private String exp;
|
private String exp;
|
||||||
|
|
||||||
Tree (String exp){
|
public Tree(String exp){
|
||||||
this.exp = exp;
|
this.exp = exp;
|
||||||
root = tree(0);
|
root = tree(0);
|
||||||
}
|
}
|
||||||
@@ -17,22 +21,16 @@ public class Tree {
|
|||||||
if(Expression.isOperator(item)) {
|
if(Expression.isOperator(item)) {
|
||||||
if (item == '!'){
|
if (item == '!'){
|
||||||
Node fils = tree(pos+1);
|
Node fils = tree(pos+1);
|
||||||
Node f = new Node(null, fils, null, item, 1+fils.getLvl());
|
Node f = new Node(fils, null, item, 1+fils.getLvl());
|
||||||
fils.setPos(1);
|
|
||||||
fils.setFather(f);
|
|
||||||
return f;
|
return f;
|
||||||
} else {
|
} else {
|
||||||
Node filsG = tree(pos+1);
|
Node filsG = tree(pos+1);
|
||||||
Node filsD = tree(pos+filsG.getLvl()+1);
|
Node filsD = tree(pos+filsG.getLvl()+1);
|
||||||
Node f = new Node(null, filsG, filsD, item, filsG.getLvl() + filsD.getLvl()+1);
|
Node f = new Node(filsG, filsD, item, filsG.getLvl() + filsD.getLvl()+1);
|
||||||
filsG.setPos(1);
|
|
||||||
filsD.setPos(2);
|
|
||||||
filsG.setFather(f);
|
|
||||||
filsD.setFather(f);
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new Node(null, null, null, item, 1);
|
return new Node(null, null, item, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
19
src/statement/World.java
Normal file
19
src/statement/World.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user