Search in sources :

Example 6 with Grammar

use of org.antlr.tool.Grammar 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)

Example 7 with Grammar

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

the class GrammarEngineImpl method getGrammarLanguage.

public String getGrammarLanguage() {
    try {
        antlrEngine.createGrammars();
        Grammar g = antlrEngine.getParserGrammar();
        if (g == null) {
            g = antlrEngine.getLexerGrammar();
        }
        if (g != null) {
            return (String) g.getOption("language");
        }
    } catch (Exception e) {
        delegate.reportError(e);
    }
    return null;
}
Also used : Grammar(org.antlr.tool.Grammar)

Aggregations

Grammar (org.antlr.tool.Grammar)7 DFA (org.antlr.analysis.DFA)3 NFAState (org.antlr.analysis.NFAState)2 DOTGenerator (org.antlr.tool.DOTGenerator)2 Rule (org.antlr.tool.Rule)2 ANTLRGrammarEngine (org.antlr.works.grammar.antlr.ANTLRGrammarEngine)2 StringTokenizer (java.util.StringTokenizer)1 Tool (org.antlr.Tool)1 CodeGenerator (org.antlr.codegen.CodeGenerator)1 ParseTree (org.antlr.runtime.tree.ParseTree)1 Interpreter (org.antlr.tool.Interpreter)1