/** * Creates a DFA from regular expression * @param expression * @param reducer Reducer marks the accepting state with unique identifier * @param options * @return */ public static DFA<Integer> createDFA(String expression, int reducer, Option... options) { NFA<Integer> nfa = createNFA(new Scope<NFAState<Integer>>(expression), expression, reducer, options); DFA<Integer> dfa = nfa.constructDFA(new Scope<DFAState<Integer>>(expression)); return dfa; }
public State(Scope scope) { this.scope = scope; this.number = scope.next(); }
/** * Constructs a dfa from using first nfa state as starting state. * @param scope * @return */ public DFA<T> constructDFA(Scope<DFAState<T>> scope) { return new DFA<>(first.constructDFA(scope), scope.count()); } /**
public void add(S state) { if (set == null) { set = new BitSet(state.getScope().count()); scope = state.getScope(); } set.set(state.getNumber()); }
private <T> DFA<T> createDFA(Map<String,T> map) { RegexParserIntf<T> regexParser = (RegexParserIntf<T>) RegexParserFactory.newInstance(); Scope<NFAState<T>> nfaScope = new Scope<>("scope"); Scope<DFAState<T>> dfaScope = new Scope<>("scope"); NFA<T> nfa = null; for (Map.Entry<String, T> entry : map.entrySet()) { String expression = entry.getKey(); T token = entry.getValue(); if (nfa == null) { nfa = regexParser.createNFA(nfaScope, expression, token); } else { NFA<T> nfa2 = regexParser.createNFA(nfaScope, expression, token); nfa = new NFA(nfaScope, nfa, nfa2); } } return nfa.constructDFA(dfaScope); } private Map<String,String> createMap(DFAMap mapdef)
/** * Copy constructor * @param other */ protected State(Scope scope, State<T> other) { this.scope = scope; this.number = scope.next(); token = other.token; }
/** * Compiles expressions */ public void compile() { Scope<DFAState<T>> dfaScope = new Scope<>("org.vesalainen.regex.RegexMatcher"); if (nfa == null) { nfa = new NFA(dfaScope); } dfa = nfa.constructDFA(dfaScope); state = root = dfa.getRoot(); parser = null; nfaScope = null; nfa = null; } /**
/** * Marks all nfa states that can be accepting to end stop. */ public void analyzeEndStop() { DFA<T> dfa = constructDFA(new Scope<DFAState<T>>("analyzeEndStop")); for (DFAState<T> s : dfa) { if (s.isAccepting()) { if (s.isEndStop()) { for (NFAState<T> n : s.getNfaSet()) { if (n.isAccepting()) { n.setEndStop(true); } } } } } } /**