39 lines
509 B
Java
39 lines
509 B
Java
|
|
public class Prefixe {
|
||
|
|
|
||
|
|
|
||
|
|
String value;
|
||
|
|
Prefixe left;
|
||
|
|
Prefixe right;
|
||
|
|
|
||
|
|
public Prefixe(String v) {
|
||
|
|
this.value = v;
|
||
|
|
}
|
||
|
|
|
||
|
|
public boolean isOperator() {
|
||
|
|
return "+-*/".contains(value);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static int index = 0;
|
||
|
|
|
||
|
|
public static Prefixe build(String[] t) {
|
||
|
|
String token = t[index++];
|
||
|
|
Prefixe p = new Prefixe(token);
|
||
|
|
|
||
|
|
if (p.isOperator()) {
|
||
|
|
p.left = build(t);
|
||
|
|
p.right = build(t);
|
||
|
|
}
|
||
|
|
return p;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|