Search in sources :

Example 1 with TokenExp

use of priv.bajdcc.LALR1.syntax.exp.TokenExp in project jMiniLang by bajdcc.

the class Syntax method getParagraphString.

/**
 * 获得段落式描述
 * @return 段落式描述
 */
public String getParagraphString() {
    StringBuilder sb = new StringBuilder();
    /* 起始符号 */
    sb.append("#### 起始符号 ####");
    sb.append(System.lineSeparator());
    sb.append(strBeginRuleName);
    sb.append(System.lineSeparator());
    /* 终结符 */
    sb.append("#### 终结符 ####");
    sb.append(System.lineSeparator());
    for (TokenExp exp : arrTerminals) {
        sb.append(exp.toString());
        sb.append(System.lineSeparator());
    }
    /* 非终结符 */
    sb.append("#### 非终结符 ####");
    sb.append(System.lineSeparator());
    for (RuleExp exp : arrNonTerminals) {
        sb.append(exp.toString());
        sb.append(System.lineSeparator());
    }
    /* 推导规则 */
    sb.append("#### 文法产生式 ####");
    sb.append(System.lineSeparator());
    for (RuleExp exp : arrNonTerminals) {
        for (RuleItem item : exp.rule.arrRules) {
            /* 规则正文 */
            sb.append(getSingleString(exp.name, item.expression));
            sb.append(System.lineSeparator());
            /* First集合 */
            sb.append("\t--== 终结符First集合 ==--");
            sb.append(System.lineSeparator());
            for (TokenExp token : item.setFirstSetTokens) {
                sb.append("\t\t").append(token.name);
                sb.append(System.lineSeparator());
            }
            sb.append("\t--== 非终结符First集合 ==--");
            sb.append(System.lineSeparator());
            for (RuleExp rule : item.setFirstSetRules) {
                sb.append("\t\t").append(rule.name);
                sb.append(System.lineSeparator());
            }
        }
    }
    return sb.toString();
}
Also used : RuleExp(priv.bajdcc.LALR1.syntax.exp.RuleExp) RuleItem(priv.bajdcc.LALR1.syntax.rule.RuleItem) TokenExp(priv.bajdcc.LALR1.syntax.exp.TokenExp)

Example 2 with TokenExp

use of priv.bajdcc.LALR1.syntax.exp.TokenExp in project jMiniLang by bajdcc.

the class Syntax method getParagraphString.

/**
 * 获得段落式描述
 * @return 段落式描述
 */
public String getParagraphString() {
    StringBuilder sb = new StringBuilder();
    /* 起始符号 */
    sb.append("#### 起始符号 ####");
    sb.append(System.lineSeparator());
    sb.append(beginRuleName);
    sb.append(System.lineSeparator());
    /* 终结符 */
    sb.append("#### 终结符 ####");
    sb.append(System.lineSeparator());
    for (TokenExp exp : arrTerminals) {
        sb.append(exp.toString());
        sb.append(System.lineSeparator());
    }
    /* 非终结符 */
    sb.append("#### 非终结符 ####");
    sb.append(System.lineSeparator());
    for (RuleExp exp : arrNonTerminals) {
        sb.append(exp.toString());
        sb.append(System.lineSeparator());
    }
    /* 推导规则 */
    sb.append("#### 文法产生式 ####");
    sb.append(System.lineSeparator());
    for (RuleExp exp : arrNonTerminals) {
        for (RuleItem item : exp.rule.arrRules) {
            /* 规则正文 */
            sb.append(getSingleString(exp.name, item.expression));
            sb.append(System.lineSeparator());
            /* First集合 */
            sb.append("\t--== First ==--");
            sb.append(System.lineSeparator());
            for (TokenExp token : item.arrFirstSetTokens) {
                sb.append("\t\t").append(token.toString());
                sb.append(System.lineSeparator());
            }
            sb.append("\t--== Follow ==--");
            sb.append(System.lineSeparator());
            for (TokenExp token : item.parent.arrFollows) {
                sb.append("\t\t").append(token.toString());
                sb.append(System.lineSeparator());
            }
        }
    }
    return sb.toString();
}
Also used : RuleExp(priv.bajdcc.LL1.syntax.exp.RuleExp) RuleItem(priv.bajdcc.LL1.syntax.rule.RuleItem) TokenExp(priv.bajdcc.LL1.syntax.exp.TokenExp)

Example 3 with TokenExp

use of priv.bajdcc.LALR1.syntax.exp.TokenExp in project jMiniLang by bajdcc.

the class SelectSetSolver method visitBegin.

@Override
public void visitBegin(TokenExp node, VisitBag bag) {
    bag.bVisitChildren = false;
    bag.bVisitEnd = false;
    if (node.kType == TokenType.EOF) {
        // Epsilon
        // 空串,则指令集为空(不压入新状态)
        addRule();
        for (TokenExp token : getFollow()) {
            // 有空串,添加Follow集
            setCellToRuleId(token.id);
        }
        firstSymbol = false;
    } else if (firstSymbol) {
        // 需要添加指令集
        addRule();
        setCellToRuleId(node.id);
        firstSymbol = false;
        insertSymbol = true;
    }
    if (insertSymbol) {
        addInstToRule(PredictType.TERMINAL, node.id);
    }
    if (node.kType != TokenType.EOF) {
        epsilon = false;
    }
}
Also used : TokenExp(priv.bajdcc.LL1.syntax.exp.TokenExp)

Example 4 with TokenExp

use of priv.bajdcc.LALR1.syntax.exp.TokenExp in project jMiniLang by bajdcc.

the class Syntax method setEpsilonName.

/**
 * 定义空串名
 *
 * @param name
 *            空串名称
 * @throws SyntaxException 词法错误
 */
public void setEpsilonName(String name) throws SyntaxException {
    TokenExp exp = new TokenExp(arrTerminals.size(), name, priv.bajdcc.util.lexer.token.TokenType.EOF, null);
    if (!mapTerminals.containsKey(name)) {
        epsilonName = name;
        mapTerminals.put(name, exp);
        arrTerminals.add(exp);
    } else {
        err(SyntaxError.REDECLARATION);
    }
}
Also used : TokenExp(priv.bajdcc.LL1.syntax.exp.TokenExp)

Example 5 with TokenExp

use of priv.bajdcc.LALR1.syntax.exp.TokenExp in project jMiniLang by bajdcc.

the class Syntax method addTerminal.

/**
 * 添加终结符
 *
 * @param name
 *            终结符名称
 * @param type
 *            单词类型
 * @param obj
 *            单词信息
 * @throws SyntaxException 词法错误
 */
public void addTerminal(String name, priv.bajdcc.util.lexer.token.TokenType type, Object obj) throws SyntaxException {
    TokenExp exp = new TokenExp(arrTerminals.size(), name, type, obj);
    if (!mapTerminals.containsKey(name)) {
        mapTerminals.put(name, exp);
        arrTerminals.add(exp);
    } else {
        err(SyntaxError.REDECLARATION);
    }
}
Also used : TokenExp(priv.bajdcc.LL1.syntax.exp.TokenExp)

Aggregations

TokenExp (priv.bajdcc.LL1.syntax.exp.TokenExp)4 TokenExp (priv.bajdcc.LALR1.syntax.exp.TokenExp)2 RuleExp (priv.bajdcc.LALR1.syntax.exp.RuleExp)1 RuleItem (priv.bajdcc.LALR1.syntax.rule.RuleItem)1 RuleExp (priv.bajdcc.LL1.syntax.exp.RuleExp)1 RuleItem (priv.bajdcc.LL1.syntax.rule.RuleItem)1