use of priv.bajdcc.LL1.syntax.ISyntaxComponent in project jMiniLang by bajdcc.
the class BranchExp method visit.
@Override
public void visit(ISyntaxComponentVisitor visitor) {
VisitBag bag = new VisitBag();
visitor.visitBegin(this, bag);
if (bag.bVisitChildren) {
for (ISyntaxComponent exp : arrExpressions) {
exp.visit(visitor);
}
}
if (bag.bVisitEnd) {
visitor.visitEnd(this);
}
}
use of priv.bajdcc.LL1.syntax.ISyntaxComponent in project jMiniLang by bajdcc.
the class SequenceExp method visit.
@Override
public void visit(ISyntaxComponentVisitor visitor) {
VisitBag bag = new VisitBag();
visitor.visitBegin(this, bag);
if (bag.bVisitChildren) {
for (ISyntaxComponent exp : arrExpressions) {
exp.visit(visitor);
}
}
if (bag.bVisitEnd) {
visitor.visitEnd(this);
}
}
use of priv.bajdcc.LL1.syntax.ISyntaxComponent in project jMiniLang by bajdcc.
the class Syntax method getSingleString.
/**
* 获得单一产生式描述
*
* @param name
* 非终结符名称
* @param exp
* 表达式树
* @param focused
* 焦点
* @param front
* 前向
* @return 原产生式描述
*/
public static String getSingleString(String name, ISyntaxComponent exp, ISyntaxComponent focused, boolean front) {
StringBuilder sb = new StringBuilder();
sb.append(name);
sb.append(" -> ");
SyntaxToString alg = new SyntaxToString(focused, front);
exp.visit(alg);
sb.append(alg.toString());
return sb.toString();
}
use of priv.bajdcc.LL1.syntax.ISyntaxComponent in project jMiniLang by bajdcc.
the class Syntax method doAnalysis.
/**
* 分析表达式
*
* @param type
* 结束类型
* @param obj
* 结束数据
* @return 表达式树根结点
* @throws SyntaxException 词法错误
*/
private ISyntaxComponent doAnalysis(TokenType type, Object obj) throws SyntaxException {
/* 新建序列用于存放结果 */
SequenceExp sequence = new SequenceExp();
/* 可能会使用的分支 */
BranchExp branch = null;
/* 添加子结点接口 */
IExpCollction collection = sequence;
/* 表达式通用接口 */
ISyntaxComponent result = sequence;
for (; ; ) {
if ((token.kToken == type && (token.object == null || token.object.equals(obj)))) {
// 结束字符
if (syntaxLexer.index() == 0) {
// 表达式为空
err(SyntaxError.NULL);
} else if (collection.isEmpty()) {
// 部件为空
err(SyntaxError.INCOMPLETE);
} else {
next();
// 正常终止
break;
}
} else if (token.kToken == TokenType.EOF) {
err(SyntaxError.INCOMPLETE);
}
// 当前待赋值的表达式
ISyntaxComponent exp = null;
switch(token.kToken) {
case OPERATOR:
OperatorType op = (OperatorType) token.object;
next();
switch(op) {
case ALTERNATIVE:
if (// 在此之前没有存储表达式 (|...)
collection.isEmpty()) {
err(SyntaxError.INCOMPLETE);
} else {
if (branch == null) {
// 分支为空,则建立分支
branch = new BranchExp();
// 用新建的分支包含并替代当前序列
branch.add(sequence);
result = branch;
}
// 新建一个序列
sequence = new SequenceExp();
branch.add(sequence);
continue;
}
break;
default:
err(SyntaxError.SYNTAX);
break;
}
break;
case EOF:
return result;
case TERMINAL:
exp = matchTerminal();
next();
break;
case NONTERMINAL:
exp = matchNonTerminal();
next();
break;
default:
err(SyntaxError.SYNTAX);
break;
}
if (exp != null) {
sequence.add(exp);
}
}
return result;
}
use of priv.bajdcc.LL1.syntax.ISyntaxComponent in project jMiniLang by bajdcc.
the class BranchExp method visit.
@Override
public void visit(ISyntaxComponentVisitor visitor) {
VisitBag bag = new VisitBag();
visitor.visitBegin(this, bag);
if (bag.bVisitChildren) {
for (ISyntaxComponent exp : arrExpressions) {
exp.visit(visitor);
}
}
if (bag.bVisitEnd) {
visitor.visitEnd(this);
}
}
Aggregations