use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by antlr.
the class BasePythonTest method getTypesFromString.
// public void minimizeDFA(DFA dfa) {
// DFAMinimizer dmin = new DFAMinimizer(dfa);
// dfa.minimized = dmin.minimize();
// }
IntegerList getTypesFromString(Grammar g, String expecting) {
IntegerList expectingTokenTypes = new IntegerList();
if (expecting != null && !expecting.trim().isEmpty()) {
for (String tname : expecting.replace(" ", "").split(",")) {
int ttype = g.getTokenType(tname);
expectingTokenTypes.add(ttype);
}
}
return expectingTokenTypes;
}
use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by antlr.
the class BasePythonTest method checkRuleDFA.
void checkRuleDFA(Grammar g, DecisionState blk, String expecting) throws Exception {
DFA dfa = createDFA(g, blk);
String result = null;
if (dfa != null)
result = dfa.toString();
assertEquals(expecting, result);
}
use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by antlr.
the class BaseCppTest method getTypesFromString.
// public void minimizeDFA(DFA dfa) {
// DFAMinimizer dmin = new DFAMinimizer(dfa);
// dfa.minimized = dmin.minimize();
// }
IntegerList getTypesFromString(Grammar g, String expecting) {
IntegerList expectingTokenTypes = new IntegerList();
if (expecting != null && !expecting.trim().isEmpty()) {
for (String tname : expecting.replace(" ", "").split(",")) {
int ttype = g.getTokenType(tname);
expectingTokenTypes.add(ttype);
}
}
return expectingTokenTypes;
}
use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by antlr.
the class BaseCppTest method getTokenTypes.
public List<String> getTokenTypes(LexerGrammar lg, ATN atn, CharStream input) {
LexerATNSimulator interp = new LexerATNSimulator(atn, new DFA[] { new DFA(atn.modeToStartState.get(Lexer.DEFAULT_MODE)) }, null);
List<String> tokenTypes = new ArrayList<String>();
int ttype;
boolean hitEOF = false;
do {
if (hitEOF) {
tokenTypes.add("EOF");
break;
}
int t = input.LA(1);
ttype = interp.match(input, Lexer.DEFAULT_MODE);
if (ttype == Token.EOF) {
tokenTypes.add("EOF");
} else {
tokenTypes.add(lg.typeToTokenList.get(ttype));
}
if (t == IntStream.EOF) {
hitEOF = true;
}
} while (ttype != Token.EOF);
return tokenTypes;
}
use of org.antlr.v4.runtime.dfa.DFA in project antlr4 by tunnelvisionlabs.
the class ParserATNSimulator method addDFAState.
/**
* See comment on LexerInterpreter.addDFAState.
*/
@NotNull
protected DFAState addDFAState(@NotNull DFA dfa, @NotNull ATNConfigSet configs, PredictionContextCache contextCache) {
final boolean enableDfa = enable_global_context_dfa || !configs.isOutermostConfigSet();
if (enableDfa) {
if (!configs.isReadOnly()) {
configs.optimizeConfigs(this);
}
DFAState proposed = createDFAState(dfa, configs);
DFAState existing = dfa.states.get(proposed);
if (existing != null)
return existing;
}
if (!configs.isReadOnly()) {
if (configs.getConflictInfo() == null) {
configs.setConflictInfo(isConflicted(configs, contextCache));
}
}
DFAState newState = createDFAState(dfa, configs.clone(true));
DecisionState decisionState = atn.getDecisionState(dfa.decision);
int predictedAlt = getUniqueAlt(configs);
if (predictedAlt != ATN.INVALID_ALT_NUMBER) {
newState.setAcceptState(new AcceptStateInfo(predictedAlt));
} else if (configs.getConflictingAlts() != null) {
newState.setAcceptState(new AcceptStateInfo(newState.configs.getConflictingAlts().nextSetBit(0)));
}
if (newState.isAcceptState() && configs.hasSemanticContext()) {
predicateDFAState(newState, configs, decisionState.getNumberOfTransitions());
}
if (!enableDfa) {
return newState;
}
DFAState added = dfa.addState(newState);
if (debug && added == newState)
System.out.println("adding new DFA state: " + newState);
return added;
}
Aggregations