-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegExTree.java
38 lines (32 loc) · 1.01 KB
/
RegExTree.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.ArrayList;
public class RegExTree {
private int root;
private ArrayList<RegExTree> subTrees;
public RegExTree(int root, ArrayList<RegExTree> subTrees) {
this.root = root;
this.subTrees = subTrees;
}
public String toString() {
if (this.subTrees.isEmpty())
return rootToString();
String str = rootToString() + "(" + this.subTrees.get(0).toString();
for (int i = 1; i < this.subTrees.size(); i++)
str += "," + this.subTrees.get(i).toString();
return str + ")";
}
private String rootToString() {
if (this.root == Parser.CONCAT || this.root == Parser.DOT)
return ".";
if (this.root == Parser.ETOILE)
return "*";
if (this.root == Parser.ALTERN)
return "|";
return Character.toString((char) this.root);
}
public int getRoot() {
return this.root;
}
public ArrayList<RegExTree> getSubTrees() {
return this.subTrees;
}
}