use of priv.bajdcc.util.lexer.automata.BreadthFirstSearch in project jMiniLang by bajdcc.
the class NGAToString method visitBegin.
@Override
public void visitBegin(NGAStatus status, VisitBag bag) {
/* 若首次访问节点则先构造状态表 */
if (arrNGAStatus.isEmpty()) {
BreadthFirstSearch<NGAEdge, NGAStatus> bfs = new BreadthFirstSearch<>();
status.visit(bfs);
arrNGAStatus = bfs.arrStatus;
}
/* 输出状态标签 */
appendLine();
appendPrefix();
context.append("--== 状态[").append(arrNGAStatus.indexOf(status)).append("]").append(status.data.bFinal ? "[结束]" : "").append(" ==--");
appendLine();
appendPrefix();
context.append("项目: ").append(status.data.label);
appendLine();
/* 输出边 */
for (NGAEdge edge : status.outEdges) {
appendPrefix();
context.append("\t到达 ").append(arrNGAStatus.indexOf(edge.end)).append(" : ");
context.append(edge.data.kAction.getName());
switch(edge.data.kAction) {
case EPSILON:
break;
case RULE:
context.append(" = ").append(edge.data.rule);
break;
case TOKEN:
context.append(" = ").append(edge.data.token);
break;
default:
break;
}
appendLine();
}
}
use of priv.bajdcc.util.lexer.automata.BreadthFirstSearch in project jMiniLang by bajdcc.
the class NPAStatus method visit.
/**
* 用于遍历包括该状态在内的所有状态(连通),结果存放在PATH中
*
* @param bfs
* 遍历算法
*/
public void visit(BreadthFirstSearch<NPAEdge, NPAStatus> bfs) {
ArrayList<NPAStatus> stack = bfs.arrStatus;
HashSet<NPAStatus> set = new HashSet<>();
stack.clear();
set.add(this);
stack.add(this);
for (int i = 0; i < stack.size(); i++) {
// 遍历每个状态
NPAStatus status = stack.get(i);
VisitBag bag = new VisitBag();
bfs.visitBegin(status, bag);
if (bag.bVisitChildren) {
// 遍历状态的出边
// 边未被访问,且边类型符合要求
status.outEdges.stream().filter(edge -> !set.contains(edge.end) && bfs.testEdge(edge)).forEach(edge -> {
// 边未被访问,且边类型符合要求
stack.add(edge.end);
set.add(edge.end);
});
}
if (bag.bVisitEnd) {
bfs.visitEnd(status);
}
}
}
Aggregations