public String toLexerString() { if ( s0==null ) return ""; DFASerializer serializer = new LexerDFASerializer(this); return serializer.toString(); }
public String toString(Vocabulary vocabulary) { if (s0 == null) { return ""; } DFASerializer serializer = new DFASerializer(this, vocabulary); return serializer.toString(); }
@Override public String toString() { return toString(VocabularyImpl.EMPTY_VOCABULARY); }
if (dfa.isPrecedenceDfa()) { s0 = dfa.getPrecedenceStartState(parser.getPrecedence()); fullCtx); if (dfa.isPrecedenceDfa()) { s0 = addDFAState(dfa, new DFAState(s0_closure)); dfa.setPrecedenceStartState(parser.getPrecedence(), s0); s0 = addDFAState(dfa, new DFAState(s0_closure)); dfa.s0 = s0;
@Override public String toString() { if ( dfa.s0==null ) return null; StringBuilder buf = new StringBuilder(); List<DFAState> states = dfa.getStates(); for (DFAState s : states) { int n = 0; if ( s.edges!=null ) n = s.edges.length; for (int i=0; i<n; i++) { DFAState t = s.edges[i]; if ( t!=null && t.stateNumber != Integer.MAX_VALUE ) { buf.append(getStateString(s)); String label = getEdgeLabel(i); buf.append("-").append(label).append("->").append(getStateString(t)).append('\n'); } } } String output = buf.toString(); if ( output.length()==0 ) return null; //return Utils.sortLinesInString(output); return output; }
@Override public void clearDFA() { for (int d = 0; d < decisionToDFA.length; d++) { decisionToDFA[d] = new DFA(atn.getDecisionState(d), d); } }
/** * Get the start state for a specific precedence value. * * @param precedence The current precedence. * @return The start state corresponding to the specified precedence, or * {@code null} if no start state exists for the specified precedence. * * @throws IllegalStateException if this is not a precedence DFA. * @see #isPrecedenceDfa() */ @SuppressWarnings("null") public final DFAState getPrecedenceStartState(int precedence) { if (!isPrecedenceDfa()) { throw new IllegalStateException("Only precedence DFAs may contain a precedence start state."); } // s0.edges is never null for a precedence DFA if (precedence < 0 || precedence >= s0.edges.length) { return null; } return s0.edges[precedence]; }
public DFA(DecisionState atnStartState, int decision) { this.atnStartState = atnStartState; this.decision = decision; boolean precedenceDfa = false; if (atnStartState instanceof StarLoopEntryState) { if (((StarLoopEntryState)atnStartState).isPrecedenceDecision) { precedenceDfa = true; DFAState precedenceState = new DFAState(new ATNConfigSet()); precedenceState.edges = new DFAState[0]; precedenceState.isAcceptState = false; precedenceState.requiresFullContext = false; this.s0 = precedenceState; } } this.precedenceDfa = precedenceDfa; }
protected DFAState.PredPrediction[] getPredicatePredictions(BitSet ambigAlts, SemanticContext[] altToPred) { List<DFAState.PredPrediction> pairs = new ArrayList<DFAState.PredPrediction>(); boolean containsPredicate = false; for (int i = 1; i < altToPred.length; i++) { SemanticContext pred = altToPred[i]; // unpredicated is indicated by SemanticContext.NONE assert pred != null; if (ambigAlts!=null && ambigAlts.get(i)) { pairs.add(new DFAState.PredPrediction(pred, i)); } if ( pred!=SemanticContext.NONE ) containsPredicate = true; } if ( !containsPredicate ) { return null; } // System.out.println(Arrays.toString(altToPred)+"->"+pairs); return pairs.toArray(new DFAState.PredPrediction[pairs.size()]); }
@Override public void clearDFA() { for (int d = 0; d < decisionToDFA.length; d++) { decisionToDFA[d] = new DFA(atn.getDecisionState(d), d); } }
/** * @deprecated Use {@link #toString(Vocabulary)} instead. */ @Deprecated public String toString(String[] tokenNames) { if ( s0==null ) return ""; DFASerializer serializer = new DFASerializer(this,tokenNames); return serializer.toString(); }
/** * Sets whether this is a precedence DFA. * * @param precedenceDfa {@code true} if this is a precedence DFA; otherwise, * {@code false} * * @throws UnsupportedOperationException if {@code precedenceDfa} does not * match the value of {@link #isPrecedenceDfa} for the current DFA. * * @deprecated This method no longer performs any action. */ @Deprecated public final void setPrecedenceDfa(boolean precedenceDfa) { if (precedenceDfa != isPrecedenceDfa()) { throw new UnsupportedOperationException("The precedenceDfa field cannot change after a DFA is constructed."); } }
/** For debugging and other purposes. */ public List<String> getDFAStrings() { synchronized (_interp.decisionToDFA) { List<String> s = new ArrayList<String>(); for (int d = 0; d < _interp.decisionToDFA.length; d++) { DFA dfa = _interp.decisionToDFA[d]; s.add( dfa.toString(getVocabulary()) ); } return s; } }
DFAState proposed = new DFAState(configs); ATNConfig firstConfigWithRuleStopState = null; for (ATNConfig c : configs) {
public LexerInterpreter(String grammarFileName, Vocabulary vocabulary, Collection<String> ruleNames, Collection<String> channelNames, Collection<String> modeNames, ATN atn, CharStream input) { super(input); if (atn.grammarType != ATNType.LEXER) { throw new IllegalArgumentException("The ATN must be a lexer ATN."); } this.grammarFileName = grammarFileName; this.atn = atn; this.tokenNames = new String[atn.maxTokenType]; for (int i = 0; i < tokenNames.length; i++) { tokenNames[i] = vocabulary.getDisplayName(i); } this.ruleNames = ruleNames.toArray(new String[ruleNames.size()]); this.channelNames = channelNames.toArray(new String[channelNames.size()]); this.modeNames = modeNames.toArray(new String[modeNames.size()]); this.vocabulary = vocabulary; this._decisionToDFA = new DFA[atn.getNumberOfDecisions()]; for (int i = 0; i < _decisionToDFA.length; i++) { _decisionToDFA[i] = new DFA(atn.getDecisionState(i), i); } this._interp = new LexerATNSimulator(this,atn,_decisionToDFA,_sharedContextCache); }
/** * Set the start state for a specific precedence value. * * @param precedence The current precedence. * @param startState The start state corresponding to the specified * precedence. * * @throws IllegalStateException if this is not a precedence DFA. * @see #isPrecedenceDfa() */ @SuppressWarnings({"SynchronizeOnNonFinalField", "null"}) public final void setPrecedenceStartState(int precedence, DFAState startState) { if (!isPrecedenceDfa()) { throw new IllegalStateException("Only precedence DFAs may contain a precedence start state."); } if (precedence < 0) { return; } // synchronization on s0 here is ok. when the DFA is turned into a // precedence DFA, s0 will be initialized once and not updated again synchronized (s0) { // s0.edges is never null for a precedence DFA if (precedence >= s0.edges.length) { s0.edges = Arrays.copyOf(s0.edges, precedence + 1); } s0.edges[precedence] = startState; } }
/** For debugging and other purposes. */ public void dumpDFA() { synchronized (_interp.decisionToDFA) { boolean seenOne = false; for (int d = 0; d < _interp.decisionToDFA.length; d++) { DFA dfa = _interp.decisionToDFA[d]; if ( !dfa.states.isEmpty() ) { if ( seenOne ) System.out.println(); System.out.println("Decision " + dfa.decision + ":"); System.out.print(dfa.toString(getVocabulary())); seenOne = true; } } } }
DFAState D = new DFAState(reach);
public ParserInterpreter(String grammarFileName, Vocabulary vocabulary, Collection<String> ruleNames, ATN atn, TokenStream input) { super(input); this.grammarFileName = grammarFileName; this.atn = atn; this.tokenNames = new String[atn.maxTokenType]; for (int i = 0; i < tokenNames.length; i++) { tokenNames[i] = vocabulary.getDisplayName(i); } this.ruleNames = ruleNames.toArray(new String[ruleNames.size()]); this.vocabulary = vocabulary; // init decision DFA int numberOfDecisions = atn.getNumberOfDecisions(); this.decisionToDFA = new DFA[numberOfDecisions]; for (int i = 0; i < numberOfDecisions; i++) { DecisionState decisionState = atn.getDecisionState(i); decisionToDFA[i] = new DFA(decisionState, i); } // get atn simulator that knows how to do predictions setInterpreter(new ParserATNSimulator(this, atn, decisionToDFA, sharedContextCache)); }
if (_dfa != null && _dfa.isPrecedenceDfa()) { int outermostPrecedenceReturn = ((EpsilonTransition)t).outermostPrecedenceReturn(); if (outermostPrecedenceReturn == _dfa.atnStartState.ruleIndex) {