Package dk.brics.automaton

Examples of dk.brics.automaton.StatePair


                            public Automaton visitAutomatonTransition(AutomatonTransition t) {
                                return t.getAutomaton().clone();
                            }

                            public Automaton visitEpsilonTransition(EpsilonTransition t) {
                                epsilons.add(new StatePair(qq, pp));
                                return null;
                            }

                            public Automaton visitIdentityTransition(IdentityTransition t) {
                                return extract(t.getStartState(), t.getFinalState(), stack).clone();
                            }

                            public Automaton visitUnaryTransition(UnaryTransition t) {
                                return t.getOperation().op(extract(t.getStartState(), t.getFinalState(), stack));
                            }

                            public Automaton visitBinaryTransition(BinaryTransition t) {
                                return t.getOperation().op(
                                        extract(t.getStartState1(), t.getFinalState1(), stack),
                                        extract(t.getStartState2(), t.getFinalState2(), stack));
                            }
                        });
                        if (b != null) {
                            epsilons.add(new StatePair(qq, b.getInitialState()));
                            for (State rr : b.getAcceptStates()) {
                                rr.setAccept(false);
                                epsilons.add(new StatePair(rr, pp));
                            }
                        }
                    }
                }
            }
View Full Code Here


        Automaton b = a.clone();
        State accept = new State();
        accept.setAccept(true);
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : b.getStates()) {
            epsilons.add(new StatePair(s, accept));
        }
        b.addEpsilons(epsilons);
        b.minimize();
        return b;
    }
View Full Code Here

        pad.setAccept(true);
        pad.addTransition(new Transition('\u0000', pad));
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : b.getStates()) {
            if (s.isAccept()) {
                epsilons.add(new StatePair(s, pad));
            } else {
                s.setAccept(true);
            }
        }
        b.setDeterministic(false);
View Full Code Here

          continue;
       
        forward.add(epsilon.from, epsilon.to);
        backward.add(epsilon.to, epsilon.from);
       
        StatePair pair = new StatePair(epsilon.from, epsilon.to);
        if (!all.containsKey(pair))
          all.put(pair, new TreeSet<Character>(epsilon.illegalCharacters()));
        else
          all.get(pair).retainAll(epsilon.illegalCharacters());
        workset.add(pair);
      }
     
      // calculate the transitive closure.
      // for every eps.tr. (s1,s2), we find a transition (s2,s3), and create (s1,s3).
      // workset contains the (s1,s2) pairs that may yield a new transition like above.
      while (!workset.isEmpty()) {
        Iterator<StatePair> it = workset.iterator();
        StatePair pair = it.next();
        it.remove();
       
        State s1 = pair.getFirstState();
        State s2 = pair.getSecondState();
       
        for (State s3 : forward.getView(s2)) {
          // do not create degenerate epsilons
          if (s1 == s3)
            continue;
         
          assert s1 != s2 && s2 != s3;
         
          TreeSet<Character> illegal = new TreeSet<Character>(all.get(pair));
          illegal.addAll(all.get(new StatePair(s2, s3)));
         
          boolean changed;
          StatePair p2 = new StatePair(s1, s3);
          if (!all.containsKey(p2)) {
            all.put(p2, illegal);
            forward.add(s1, s3); // note: we are not modifying the view being iterated because s1!=s2
            backward.add(s3, s1);
            changed = true;
          } else {
            changed = all.get(p2).retainAll(illegal);
          }
         
          if (changed) {
            workset.add(p2);
            for (State s0 : backward.getView(s1)) {
              workset.add(new StatePair(s0, s1));
            }
          }
        }
      }
   
    // closure completed, time to add the transitions
      LinkedList<StateTransitionPair> transitions = new LinkedList<StateTransitionPair>();
    for (Map.Entry<StatePair, TreeSet<Character>> entry : all.entrySet()) {
      StatePair pair = entry.getKey();
      for (Transition tr : pair.getSecondState().getTransitions()) {
        char ch = tr.getMin();
        // TreeSet is sorted, so we visit the illegal characters in increasing order
        // at every illegal character, we add the interval below, since it must be a legal interval
        for (Character illegal : entry.getValue()) {
          if (illegal < ch)
            continue;
          if (illegal > tr.getMax())
            break;
          if (illegal > ch) {
            transitions.add(new StateTransitionPair(pair.getFirstState(), new Transition(ch, (char)(illegal - 1), tr.getDest())));
          }
          ch = (char)(illegal + 1);
        }
        if (ch <= tr.getMax()) {
          transitions.add(new StateTransitionPair(pair.getFirstState(), new Transition(ch, tr.getMax(), tr.getDest())));
        }
      }
    }
    for (StateTransitionPair pair : transitions) {
      pair.state.addTransition(pair.transition);
View Full Code Here

        a1.setDeterministic(false);
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : a1s) {
            Set<State> reachable = Basic.findReachableStates(map.get(s));
            for (State p : reachable) {
                epsilons.add(new StatePair(s, p));
            }
        }
        a1.addEpsilons(epsilons);
        a1.minimize();
        return a1;
View Full Code Here

        }
        a1.setDeterministic(false);
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : a1s) {
            for (Transition t : map.get(s).getTransitions()) {
                epsilons.add(new StatePair(s, t.getDest()));
            }
        }
        a1.addEpsilons(epsilons);
        a1.minimize();
        return a1;
View Full Code Here

        Automaton a2 = a.clone();
        Automaton bb = b.clone();
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : a1.getStates()) {
            s.setAccept(false);
            epsilons.add(new StatePair(s, bb.getInitialState()));
        }
        for (State s : bb.getAcceptStates()) {
            s.setAccept(false);
            for (State p : a2.getStates()) {
                epsilons.add(new StatePair(s, p));
            }
        }
        a1.addEpsilons(epsilons);
        a1.minimize();
        return a1;
View Full Code Here

    public static Automaton getSuffixesOf(Automaton automaton) {
        Automaton result = automaton.clone();
        Collection<StatePair> epsilons = new ArrayList<StatePair>();
        for (State state : result.getLiveStates()) {
            if (state != result.getInitialState()) {
                epsilons.add(new StatePair(result.getInitialState(), state));
            }
        }
        result.addEpsilons(epsilons);
        if (automaton.isDeterministic()) {
            result.determinize();
View Full Code Here

        result.removeDeadTransitions();
        Collection<StatePair> epsilons = new ArrayList<StatePair>();
        for (State state : result.getStates()) {
            state.setAccept(true);
            if (state != result.getInitialState()) {
                epsilons.add(new StatePair(result.getInitialState(), state));
            }
        }
        result.restoreInvariant(); // accept states have been modified
        result.addEpsilons(epsilons);
        result.determinize();
View Full Code Here

    public Automaton op(Automaton a) {
        Automaton b = a.clone();
        State initial = new State();
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : b.getStates()) {
            epsilons.add(new StatePair(initial, s));
        }
        b.setInitialState(initial);
        b.addEpsilons(epsilons);
        b.minimize();
        return b;
View Full Code Here

TOP

Related Classes of dk.brics.automaton.StatePair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.