Search in sources :

Example 1 with IManageSymbol

use of priv.bajdcc.LALR1.grammar.symbol.IManageSymbol in project jMiniLang by bajdcc.

the class Semantic method run.

/**
 * 进行语义处理
 */
private void run() throws SyntaxException {
    if (!arrErrors.isEmpty()) {
        System.err.println(getTrackerError());
        throw new SyntaxException(SyntaxError.COMPILE_ERROR, arrErrors.get(0).position, "出现语法错误");
    }
    /* 规则集合 */
    ArrayList<RuleItem> items = npa.getRuleItems();
    /* 符号表查询接口 */
    IQuerySymbol query = getQuerySymbolService();
    /* 符号表管理接口 */
    IManageSymbol manage = getManageSymbolService();
    /* 语义错误处理接口 */
    ISemanticRecorder recorder = getSemanticRecorderService();
    /* 复制单词流 */
    ArrayList<Token> tokens = arrTokens.stream().map(Token::copy).collect(Collectors.toCollection(ArrayList::new));
    /* 运行时自动机 */
    SemanticMachine machine = new SemanticMachine(items, arrActions, tokens, query, manage, recorder, debug);
    /* 遍历所有指令 */
    arrInsts.forEach(machine::run);
    object = machine.getObject();
    if (object != null) {
        Function entry = (Function) object;
        manage.getManageScopeService().registerFunc(entry);
    }
}
Also used : Function(priv.bajdcc.LALR1.grammar.tree.Function) SyntaxException(priv.bajdcc.LALR1.syntax.handler.SyntaxException) RuleItem(priv.bajdcc.LALR1.syntax.rule.RuleItem) IManageSymbol(priv.bajdcc.LALR1.grammar.symbol.IManageSymbol) Token(priv.bajdcc.util.lexer.token.Token) IQuerySymbol(priv.bajdcc.LALR1.grammar.symbol.IQuerySymbol) ISemanticRecorder(priv.bajdcc.LALR1.grammar.semantic.ISemanticRecorder)

Aggregations

ISemanticRecorder (priv.bajdcc.LALR1.grammar.semantic.ISemanticRecorder)1 IManageSymbol (priv.bajdcc.LALR1.grammar.symbol.IManageSymbol)1 IQuerySymbol (priv.bajdcc.LALR1.grammar.symbol.IQuerySymbol)1 Function (priv.bajdcc.LALR1.grammar.tree.Function)1 SyntaxException (priv.bajdcc.LALR1.syntax.handler.SyntaxException)1 RuleItem (priv.bajdcc.LALR1.syntax.rule.RuleItem)1 Token (priv.bajdcc.util.lexer.token.Token)1