コード例 #1
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);
    }
コード例 #2
0
    private FA CreateNewFA(FA synth)
    {
        CGraphNode oldEntryNode, oldExitNode;
        FA         m_currentFA = new FA();

        m_ThompsonInfo = new ThompsonInfo(m_currentFA, m_ThompsonInfoKey);
        m_ThompsonInfo.InitFAInfo(new ThompsonFAInfo());

        //2.Merge graph
        m_mergeOperation = m_currentFA.Merge(synth, CGraph.CMergeGraphOperation.MergeOptions.MO_DEFAULT);
        m_mergeOperation.MergeGraphInfo(synth, GraphElementType.ET_EDGE, FA.m_FAINFOKEY);
        m_mergeOperation.MergeGraphInfo(synth, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY);
        m_mergeOperation.MergeGraphInfo(synth, GraphElementType.ET_NODE, FA.m_FAINFOKEY);

        m_mergeOperation.MergeGraphInfo(synth, GraphElementType.ET_EDGE, m_ThompsonInfoKey);
        m_mergeOperation.MergeGraphInfo(synth, GraphElementType.ET_GRAPH, m_ThompsonInfoKey);
        m_mergeOperation.MergeGraphInfo(synth, GraphElementType.ET_NODE, m_ThompsonInfoKey);

        // Create boundary nodes
        m_newFASource = m_currentFA.CreateGraphNode <CGraphNode>();
        m_ThompsonInfo.InitNodeInfo(m_newFASource, new ThompsonNodeFAInfo());

        m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(m_newFASource, m_mergeOperation.GetMirrorNode(synth.M_Initial), GraphType.GT_DIRECTED);
        m_newFATarget = m_currentFA.CreateGraphNode <CGraphNode>();
        m_ThompsonInfo.InitNodeInfo(m_newFATarget, new ThompsonNodeFAInfo());

        m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(m_mergeOperation.GetMirrorNode(synth.GetFinalStates()[0]), m_newFATarget, GraphType.GT_DIRECTED);

        //4.Create the initial and the final node
        oldEntryNode          = m_mergeOperation.GetMirrorNode(synth.M_Initial);
        oldExitNode           = m_mergeOperation.GetMirrorNode(synth.GetFinalStates()[0]);
        m_currentFA.M_Initial = m_newFASource;
        m_currentFA.SetFinalState(m_newFATarget);
        m_currentFA.UpdateAlphabet();

        // Update closure information from operand closure
        FAInfo currentFAInfo = UpdateClosureInformation(synth, m_currentFA, m_mergeOperation);

        // Update closure information from current closure
        m_currentFAloop             = new FALoop();
        m_currentFAloop.MEntryNode  = oldEntryNode;
        m_currentFAloop.MExitNode   = oldExitNode;
        m_currentFAloop.MLoopSerial = m_currentClosureSerial;
        CIt_GraphNodes it = new CIt_GraphNodes(m_currentFA);

        for (it.Begin(); !it.End(); it.Next())
        {
            if (it.M_CurrentItem != m_currentFA.M_Initial &&
                it.M_CurrentItem != m_currentFA.GetFinalStates()[0])
            {
                m_currentFAloop.MParticipatingNodes.Add(it.M_CurrentItem);
            }
        }
        // Add new closure to the current FA
        currentFAInfo.AddFALoop(m_currentFAloop);

        return(m_currentFA);
    }
コード例 #3
0
    internal FA Sythesize(FA l, FA r, CGraph.CMergeGraphOperation.MergeOptions options)
    {
        //1.Create FA
        m_currentFA    = new FA();
        m_ThompsonInfo = new ThompsonInfo(m_currentFA, m_ThompsonInfoKey);

        //2.Merge left graph
        CGraph.CMergeGraphOperation lmerge = m_currentFA.Merge(l, options);
        //Console.WriteLine(l.ToString());
        lmerge.MergeGraphInfo(l, GraphElementType.ET_EDGE, FA.m_FAINFOKEY);
        lmerge.MergeGraphInfo(l, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY);
        lmerge.MergeGraphInfo(l, GraphElementType.ET_NODE, FA.m_FAINFOKEY);

        lmerge.MergeGraphInfo(l, GraphElementType.ET_EDGE, m_ThompsonInfoKey);
        lmerge.MergeGraphInfo(l, GraphElementType.ET_GRAPH, m_ThompsonInfoKey);
        lmerge.MergeGraphInfo(l, GraphElementType.ET_NODE, m_ThompsonInfoKey);

        CGraphNode il = lmerge.GetMirrorNode(l.M_Initial);
        CGraphNode fl = lmerge.GetMirrorNode(l.GetFinalStates()[0]);

        //3.Merge right graph
        CGraph.CMergeGraphOperation rmerge = m_currentFA.Merge(r, options);
        rmerge.MergeGraphInfo(r, GraphElementType.ET_EDGE, FA.m_FAINFOKEY);
        rmerge.MergeGraphInfo(r, GraphElementType.ET_GRAPH, FA.m_FAINFOKEY);
        rmerge.MergeGraphInfo(r, GraphElementType.ET_NODE, FA.m_FAINFOKEY);

        rmerge.MergeGraphInfo(r, GraphElementType.ET_EDGE, m_ThompsonInfoKey);
        rmerge.MergeGraphInfo(r, GraphElementType.ET_GRAPH, m_ThompsonInfoKey);
        rmerge.MergeGraphInfo(r, GraphElementType.ET_NODE, m_ThompsonInfoKey);

        CGraphNode ir = rmerge.GetMirrorNode(r.M_Initial);
        CGraphNode fr = rmerge.GetMirrorNode(r.GetFinalStates()[0]);

        //4.Create the initial and the final node
        CGraphNode FAinit  = m_currentFA.CreateGraphNode <CGraphNode>();
        CGraphNode FAfinal = m_currentFA.CreateGraphNode <CGraphNode>();

        m_ThompsonInfo.InitNodeInfo(FAinit, new ThompsonNodeFAInfo());
        m_ThompsonInfo.InitNodeInfo(FAfinal, new ThompsonNodeFAInfo());

        m_currentFA.M_Initial = FAinit;
        m_currentFA.SetFinalState(FAfinal);
        m_currentFA.UpdateAlphabet();

        m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(FAinit, il, GraphType.GT_DIRECTED);
        m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(FAinit, ir, GraphType.GT_DIRECTED);
        m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(fr, FAfinal, GraphType.GT_DIRECTED);
        m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(fl, FAfinal, GraphType.GT_DIRECTED);

        // Update closure information from operand closure
        // Update closure information from operand closure
        UpdateClosureInformation(l, m_currentFA, lmerge);
        UpdateClosureInformation(r, m_currentFA, rmerge);

        //7.Return result
        return(m_currentFA);
    }