Search in sources :

Example 1 with DOTGenerator

use of org.antlr.tool.DOTGenerator in project antlrworks by antlr.

the class TokensDFA method getDOTString.

@Override
public String getDOTString() throws Exception {
    ANTLRGrammarEngine eg = window.getGrammarEngine().getANTLRGrammarEngine();
    eg.analyze();
    Grammar g = eg.getLexerGrammar();
    if (g == null) {
        throw new Exception("Cannot show tokens DFA because there is no lexer grammar");
    }
    Rule r = g.getRule(Grammar.ARTIFICIAL_TOKENS_RULENAME);
    NFAState s = (NFAState) r.startState.transition(0).target;
    DFA dfa = g.getLookaheadDFA(s.getDecisionNumber());
    DOTGenerator dg = new DOTGenerator(g);
    dg.setArrowheadType("none");
    // Left-to-right
    dg.setRankdir("LR");
    return dg.getDOT(dfa.startState);
}
Also used : ANTLRGrammarEngine(org.antlr.works.grammar.antlr.ANTLRGrammarEngine) DOTGenerator(org.antlr.tool.DOTGenerator) NFAState(org.antlr.analysis.NFAState) Grammar(org.antlr.tool.Grammar) Rule(org.antlr.tool.Rule) DFA(org.antlr.analysis.DFA)

Example 2 with DOTGenerator

use of org.antlr.tool.DOTGenerator in project antlrworks by antlr.

the class DecisionDFA method getDOTString.

@Override
public String getDOTString() throws Exception {
    DecisionDFAEngine engine = window.decisionDFAEngine;
    Grammar g;
    int adjustedColumn = getDecisionColumn(g = engine.getDiscoveredParserGrammar());
    if (adjustedColumn == -1)
        adjustedColumn = getDecisionColumn(g = engine.getDiscoveredLexerGrammar());
    if (adjustedColumn == -1)
        throw new Exception("No decision in the current line");
    CodeGenerator generator = new CodeGenerator(new Tool(), g, (String) g.getOption("language"));
    DFA dfa = g.getLookaheadDFAFromPositionInFile(line, adjustedColumn);
    decisionNumber = dfa.getDecisionNumber();
    DOTGenerator dg = new DOTGenerator(g);
    g.setCodeGenerator(generator);
    dg.setArrowheadType("none");
    // Left-to-right
    dg.setRankdir("LR");
    return dg.getDOT(dfa.startState);
}
Also used : DOTGenerator(org.antlr.tool.DOTGenerator) Grammar(org.antlr.tool.Grammar) CodeGenerator(org.antlr.codegen.CodeGenerator) DFA(org.antlr.analysis.DFA) Tool(org.antlr.Tool)

Aggregations

DFA (org.antlr.analysis.DFA)2 DOTGenerator (org.antlr.tool.DOTGenerator)2 Grammar (org.antlr.tool.Grammar)2 Tool (org.antlr.Tool)1 NFAState (org.antlr.analysis.NFAState)1 CodeGenerator (org.antlr.codegen.CodeGenerator)1 Rule (org.antlr.tool.Rule)1 ANTLRGrammarEngine (org.antlr.works.grammar.antlr.ANTLRGrammarEngine)1