Ejemplo n.º 1
0
 public FAGraphVizPrinter(CGraph graph, UOPCore.Options <ThompsonOptions> options,
                          CGraphLabeling <CGraphNode> nodeLabeling = null,
                          CGraphLabeling <CGraphEdge> edgeLabeling = null) : base(graph, nodeLabeling, edgeLabeling)
 {
     m_FAInfo  = new FAGraphQueryInfo(graph, FA.m_FAINFOKEY);
     m_options = options;
 }
Ejemplo n.º 2
0
        public override FA VisitRange(CASTElement currentNode)
        {
            CRange           rangeNode = currentNode as CRange;
            FAGraphQueryInfo FAInfo;

            //1.Create FA
            m_NFA  = new FA();
            FAInfo = new FAGraphQueryInfo(m_NFA, FA.m_FAINFOKEY);
            //2.Create nodes initial-final
            CGraphNode init  = m_NFA.CreateGraphNode <CGraphNode>();
            CGraphNode final = m_NFA.CreateGraphNode <CGraphNode>();

            m_NFA.M_Initial = init;
            m_NFA.SetFinalState(final);
            m_NFA.M_Alphabet.AddRange(rangeNode.MRange);

            //3.Draw the edge including the character
            CGraphEdge newEdge = m_NFA.AddGraphEdge <CGraphEdge, CGraphNode>(init, final, GraphType.GT_DIRECTED);

            FAInfo.Info(newEdge).M_TransitionCharSet = (CCharRangeSet)rangeNode.MRange;
            newEdge.SetLabel(rangeNode.MRange.ToString());

            m_ReportingServices.ExctractThompsonStep(m_NFA, @"../Debug/Range_" + rangeNode.MRange.ToString() + ".dot");
            m_ReportingServices.AddThompsonStepToReporting(m_NFA);
            //4.Pass FA to the predecessor
            return(m_NFA);
        }
Ejemplo n.º 3
0
    internal FA Synthesize(CCharRangeSet set)
    {
        FAGraphQueryInfo FAInfo;

        m_currentFA    = new FA();
        m_ThompsonInfo = new ThompsonInfo(m_currentFA, m_ThompsonInfoKey);
        FAInfo         = new FAGraphQueryInfo(m_currentFA, FA.m_FAINFOKEY);

        //2.Create nodes initial-final
        CGraphNode init  = m_currentFA.CreateGraphNode <CGraphNode>();
        CGraphNode final = m_currentFA.CreateGraphNode <CGraphNode>();

        m_ThompsonInfo.InitNodeInfo(init, new ThompsonNodeFAInfo());
        m_ThompsonInfo.InitNodeInfo(final, new ThompsonNodeFAInfo());

        m_currentFA.M_Initial = init;
        m_currentFA.SetFinalState(final);
        m_currentFA.M_Alphabet.AddSet(set);

        //3.Draw the edge including the character
        CGraphEdge newEdge = m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(init, final, GraphType.GT_DIRECTED);

        FAInfo.Info(newEdge).M_TransitionCharSet = set;

        return(m_currentFA);
    }
Ejemplo n.º 4
0
        public override FA VisitRegexpbasicSet(CASTElement currentNode)
        {
            CRegexpbasicSet  setNode = currentNode as CRegexpbasicSet;
            FAGraphQueryInfo FAInfo;

            //Create FA
            m_NFA  = new FA();
            FAInfo = new FAGraphQueryInfo(m_NFA, FA.m_FAINFOKEY);
            CGraphNode init  = m_NFA.CreateGraphNode <CGraphNode>();
            CGraphNode final = m_NFA.CreateGraphNode <CGraphNode>();

            m_NFA.M_Initial = init;
            m_NFA.SetFinalState(final);
            m_NFA.M_Alphabet.AddSet(setNode.MSet);

            CGraphEdge newEdge = m_NFA.AddGraphEdge <CGraphEdge, CGraphNode>(init, final, GraphType.GT_DIRECTED);

            FAInfo.Info(newEdge).M_TransitionCharSet = setNode.MSet;
            //4.Pass FA to the predecessor

            m_NFA.PrefixGraphElementLabels(m_currentRegularExpression.M_StatementID, GraphElementType.ET_NODE);

            m_ReportingServices.ExctractThompsonStep(m_NFA, @"../Debug/BasicSet_" + setNode.MSet.ToString() + ".dot");
            m_ReportingServices.AddThompsonStepToReporting(m_NFA);

            return(m_NFA);
        }
Ejemplo n.º 5
0
 public CConfigurations(FA DFA, FA NFA)
 {
     m_DFA          = DFA;
     m_NFA          = NFA;
     m_mappings     = new Dictionary <CGraphNode, HashSet <CGraphNode> >();
     m_NFAStateInfo = new FAGraphQueryInfo(m_NFA, FA.m_FAINFOKEY);
     m_DFAStateInfo = new FAGraphQueryInfo(m_DFA, FA.m_FAINFOKEY);
 }
 internal ThompsonGraphVizPrinter(CGraph graph, UOPCore.Options <ThompsonOptions> options,
                                  object thompsonkeyinfo,
                                  CGraphLabeling <CGraphNode> nodeLabeling = null,
                                  CGraphLabeling <CGraphEdge> edgeLabeling = null
                                  ) : base(graph, nodeLabeling, edgeLabeling)
 {
     m_options         = options;
     m_thompsonKeyInfo = thompsonkeyinfo;
     m_thompsonInfo    = new ThompsonInfo(graph, m_thompsonKeyInfo);
     m_FAInfo          = new FAGraphQueryInfo(graph, FA.m_FAINFOKEY);
 }
Ejemplo n.º 7
0
        public HashSet <CGraphNode> Start()
        {
            GraphLibrary.CGraphNode Qprime, Q;
            CGraphEdge    e;
            CCharRangeSet set;
            //q0 ← -closure({n0});
            HashSet <CGraphNode> q0 = CEclosureAlgorithm.Init(m_NFA, new HashSet <CGraphNode>()
            {
                m_NFA.M_Initial
            }).Start();

            m_NFA.UpdateAlphabet();

            // Create DFA
            m_DFA = new FA();

            // DEBUG
            m_reporting.AddDFA(0, m_DFA);

            m_DFAInfo        = new FAGraphQueryInfo(m_DFA, FA.m_FAINFOKEY);
            m_configurations = new CConfigurations(m_DFA, m_NFA);
            m_configurations.CreateDFANode(q0);

            //WorkList ← { q0};
            m_workList.Enqueue(q0);

            while (m_workList.Count != 0)
            {
                HashSet <CGraphNode> q = m_workList.Dequeue();
                Q = m_configurations.GetDFANode(q);

                // ********* DEBUG *************
                CSubsetConstructionReporting.IterationRecord cRecord = m_reporting.AddIteration(0, q, Q);

                // for each NFA alphabet character
                foreach (CCharRange range in m_NFA.M_Alphabet)
                {
                    foreach (Int32 i in range)
                    {
                        CDeltaAlgorithm      delta       = CDeltaAlgorithm.Init(m_NFA, i, q);
                        HashSet <CGraphNode> deltaResult = delta.Start();
                        CEclosureAlgorithm   eClosure    = CEclosureAlgorithm.Init(m_NFA, deltaResult);
                        HashSet <CGraphNode> qprime      = eClosure.Start();
                        if (qprime.Count != 0)
                        {
                            Qprime = m_configurations.GetDFANode(qprime);
                            if (Qprime == null)
                            {
                                m_workList.Enqueue(qprime);
                                Qprime = m_configurations.CreateDFANode(qprime);
                            }
                            // Check if an edge between Q and Qprime alredy exists
                            e = m_DFA.Edge(Q, Qprime);
                            if (e == null)
                            {
                                e   = m_DFA.AddGraphEdge <CGraphEdge, CGraphNode>(Q, Qprime, GraphType.GT_DIRECTED);
                                set = new CCharRangeSet(false);
                                m_DFAInfo.SetDFAEdgeTransitionCharacterSet(e, set);
                            }
                            else
                            {
                                set = m_DFAInfo.GetDFAEdgeTransitionCharacterSet(e);
                            }
                            set.AddRange(i);

                            // ********** DEBUG ************
                            CSubsetConstructionReporting.EdgeRecord charRecord = cRecord.AddEdgeRecord(deltaResult, qprime, e);
                            charRecord.AddCharacterCode(i);
                        }
                    }
                }
            }
            m_DFA.UpdateAlphabet();
            m_DFA.RegisterGraphPrinter(new FAGraphVizPrinter(m_DFA, new UOPCore.Options <ThompsonOptions>()));
            m_DFA.Generate(@"mergeDFA.dot", true);

            // DEBUG
            m_reporting.Report("SubsetREPORT.txt");
            return(null);
        }
Ejemplo n.º 8
0
 internal FATextPrinter(CGraph graph, AbstractGraphLabeling <CGraphNode> nodeLabeller = null, AbstractGraphLabeling <CGraphEdge> edgeLabeller = null) : base(graph, nodeLabeller, edgeLabeller)
 {
     m_FAInfo = new FAGraphQueryInfo(graph, FA.m_FAINFOKEY);
 }
 public SubsetGraphvizPrinter(CGraph graph, object subsetinfoKey, CGraphLabeling <CGraphNode> nodeLabeling = null, CGraphLabeling <CGraphEdge> edgeLabeling = null) : base(graph, nodeLabeling, edgeLabeling)
 {
     m_FAInfo        = new FAGraphQueryInfo(graph, FA.m_FAINFOKEY);
     m_subsetInfoKey = subsetinfoKey;
 }