public void reportNondeterminism(DFAState d, Set<Integer> nondeterministicAlts) { altsWithProblem.addAll(nondeterministicAlts); // track overall list statesWithSyntacticallyAmbiguousAltsSet.add(d); dfa.nfa.grammar.setOfNondeterministicDecisionNumbers.add( Utils.integer(dfa.getDecisionNumber()) ); }
if ( getUserMaxLookahead()>0 ) { for (int i = 0; i <= getMaxStateNumber(); i++) { DFAState s = getState(i); if ( snum!=getNumberOfStates() ) { ErrorManager.internalError("DFA "+decisionNumber+": "+ decisionNFAStartState.getDescription()+" num unique states "+getNumberOfStates()+ "!= num renumbered states "+snum);
if ( PRUNE_EBNF_EXIT_BRANCHES && dfa.canInlineDecision() ) { visited.clear(); int decisionType = dfa.getNFADecisionStartState().decisionStateType; if ( dfa.isGreedy() && (decisionType==NFAState.OPTIONAL_BLOCK_START || decisionType==NFAState.LOOPBACK) ) dfa.isTokensRuleDecision() && dfa.probe.stateToSyntacticallyAmbiguousTokensRuleAltsMap.size()>0 )
public boolean canInlineDecision() { return !isCyclic() && !probe.isNonLLStarDecision() && getNumberOfStates() < CodeGenerator.MAX_ACYCLIC_DFA_STATES_INLINE; }
description = getNFADecisionStartState().getDescription(); description = generator.target.getTargetStringLiteralFromString(description); special = new Vector<Integer>(this.getNumberOfStates()); // Vector<short> special.setSize(this.getNumberOfStates()); specialStates = new ArrayList<DFAState>(); // List<DFAState> specialStateSTs = new ArrayList<ST>(); // List<ST> accept = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> accept.setSize(this.getNumberOfStates()); eot = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> eot.setSize(this.getNumberOfStates()); eof = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> eof.setSize(this.getNumberOfStates()); min = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> min.setSize(this.getNumberOfStates()); max = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> max.setSize(this.getNumberOfStates()); transition = new Vector<Vector<Integer>>(this.getNumberOfStates()); // Vector<Vector<int>> transition.setSize(this.getNumberOfStates()); transitionEdgeTables = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> transitionEdgeTables.setSize(this.getNumberOfStates()); if ( getUserMaxLookahead()>0 ) { it = states.iterator(); it = getUniqueStates().values().iterator(); createMinMaxTables(s);
DFA lookaheadDFA = new DFA(decision, decisionStartState); lookaheadDFA.analysisTimedOut() || lookaheadDFA.probe.isNonLLStarDecision() || lookaheadDFA.probe.analysisOverflowed(); if ( failed && lookaheadDFA.okToRetryDFAWithK1() ) { System.out.print("trying decision "+decision+ " again with k=1; reason: "+ lookaheadDFA.getReasonForFailure()); lookaheadDFA = new DFA(decision, decisionStartState); if ( lookaheadDFA.analysisTimedOut() ) { // did analysis bug out? ErrorManager.internalError("could not even do k=1 for decision "+ decision+"; reason: "+ lookaheadDFA.getReasonForFailure()); for (DFAState s : lookaheadDFA.getUniqueStates().values()) { s.reset(); System.out.println("cost: "+lookaheadDFA.getNumberOfStates()+ " states, "+(int)(stopDFA-startDFA)+" ms");
DFAState predDFATarget = d.dfa.getAcceptState(c.alt); if ( predDFATarget==null ) { predDFATarget = dfa.newState(); // create if not there. c.semanticContext); predDFATarget.setAcceptState(true); dfa.setAcceptState(c.alt, predDFATarget); DFAState existingState = dfa.addState(predDFATarget); if ( predDFATarget != existingState ) { dfa.setState(predDFATarget.stateNumber, existingState); predDFATarget = existingState;
if ( dfa.canInlineDecision() ) { decisionST = acyclicDFAGenerator.genFixedLookaheadDecision(getTemplates(), dfa); dfa.createStateTables(this); outputFileST.add("cyclicDFAs", dfa); headerFileST.add("cyclicDFAs", dfa); decisionST = templates.getInstanceOf("dfaDecision"); String description = dfa.getNFADecisionStartState().getDescription(); description = target.getTargetStringLiteralFromString(description); if ( description!=null ) { Utils.integer(dfa.getDecisionNumber()));
public String toString() { GrammarAST decisionASTNode = probe.dfa.getDecisionASTNode(); line = decisionASTNode.getLine(); column = decisionASTNode.getColumn(); String fileName = probe.dfa.nfa.grammar.getFileName(); if ( fileName!=null ) { file = fileName; } StringTemplate st = getMessageTemplate(); String ruleName = probe.dfa.getNFADecisionStartState().enclosingRule.name; st.setAttribute("ruleName", ruleName); List sortedAlts = new ArrayList(); sortedAlts.addAll(altsWithRecursion); Collections.sort(sortedAlts); // make sure it's 1, 2, ... st.setAttribute("alts", sortedAlts); return super.toString(st); }
if(dfa.getDecisionNumber() == s.getDecisionNumber()) continue; String title = "DFA decision "+dfa.getDecisionNumber(); String info = ""; if(usesSemPreds.contains(dfa.getDecisionNumber())) { info += "uses semantic predicate"; c = new Color(255, 220, 0); } else if(usesSynPreds.contains(dfa.getDecisionNumber())) { info += "uses syntactic predicate"; c = new Color(255, 220, 0); if(dfa.isCyclic()) { if(info.length() > 0) info += ", "; info += "cyclic"; if (dfa.getNumberOfStates() != 0) { info += dfa.getNumberOfStates()+" states"; info += "<=" + dfa.getMaxStateNumber() + " states";
DFAState startState = dfa.newState(); computingStartState = true; int i = 0; dfa.getNFADecisionStartState().decisionStateType==NFAState.LOOPBACK ) dfa.addState(startState); // make sure dfa knows about this state work.add(startState); computingStartState = false;
int k = d.dfa.getMaxLookaheadDepth(); Rule enclosingRule = d.dfa.decisionNFAStartState.enclosingRule; if ( enclosingRule.isSynPred ) continue; // don't count synpred rules buf.append(" decision "+decision+":"); if ( d.dfa.isCyclic() ) buf.append(" cyclic"); if ( k!=Integer.MAX_VALUE ) buf.append(" k="+k); // fixed, no sempreds if ( d.dfa.hasSynPred() ) buf.append(" backtracks"); // isolated synpred not gated if ( d.dfa.hasSemPred() ) buf.append(" sempred"); // user-defined sempred
/** Is this DFA derived from the NFA for the Tokens rule? */ public boolean isTokensRuleDecision() { if ( nfa.grammar.type!=Grammar.LEXER ) { return false; } NFAState nfaStart = getNFADecisionStartState(); Rule r = nfa.grammar.getLocallyDefinedRule(Grammar.ARTIFICIAL_TOKENS_RULENAME); NFAState TokensRuleStart = r.startState; NFAState TokensDecisionStart = (NFAState)TokensRuleStart.transition[0].target; return nfaStart == TokensDecisionStart; }
/** Return k if decision is LL(k) for some k else return max int */ public int getMaxLookaheadDepth() { if ( isCyclic() ) { return Integer.MAX_VALUE; } return max_k; }
private GrammarError buildUnreachableAltsError(GrammarUnreachableAltsMessage message) { GrammarError error = new GrammarError(); error.setLine(message.probe.dfa.getDecisionASTNode().getLine()-1); error.setMessageText("The following alternatives are unreachable: "+message.alts); error.setMessage(message); return error; }
int predictedAlt = predict(dfa); if ( predictedAlt == NFA.INVALID_ALT_NUMBER ) { String description = dfa.getNFADecisionStartState().getDescription(); NoViableAltException nvae = new NoViableAltException(description, dfa.getDecisionNumber(), s.stateNumber, input);
decision = generator.genLookaheadDecision(recognizerST,dfa); code.setAttribute("decision", decision); code.setAttribute("decisionNumber", dfa.getDecisionNumber()); code.setAttribute("maxK",dfa.getMaxLookaheadDepth()); code.setAttribute("maxAlt",dfa.getNumberOfAlts());
/** How many states does the DFA predictor have? */ public int getNumberOfStates() { return dfa.getNumberOfStates(); }
description = getNFADecisionStartState().getDescription(); description = generator.target.getTargetStringLiteralFromString(description); special = new Vector<Integer>(this.getNumberOfStates()); // Vector<short> special.setSize(this.getNumberOfStates()); specialStates = new ArrayList<DFAState>(); // List<DFAState> specialStateSTs = new ArrayList<ST>(); // List<ST> accept = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> accept.setSize(this.getNumberOfStates()); eot = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> eot.setSize(this.getNumberOfStates()); eof = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> eof.setSize(this.getNumberOfStates()); min = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> min.setSize(this.getNumberOfStates()); max = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> max.setSize(this.getNumberOfStates()); transition = new Vector<Vector<Integer>>(this.getNumberOfStates()); // Vector<Vector<int>> transition.setSize(this.getNumberOfStates()); transitionEdgeTables = new Vector<Integer>(this.getNumberOfStates()); // Vector<int> transitionEdgeTables.setSize(this.getNumberOfStates()); if ( getUserMaxLookahead()>0 ) { it = states.iterator(); it = getUniqueStates().values().iterator(); createMinMaxTables(s);