public override FA VisitRegexpAlternation(CASTElement currentNode)
        {
            CRegexpAlternation           altNode = currentNode as CRegexpAlternation;
            CSubsetConstructionAlgorithm subcon;
            CHopcroftAlgorithm           hopmin;
            //1. Create FA
            CThompsonAlternationTemplate alttempSyn = new CThompsonAlternationTemplate(this.GetHashCode());
            FA leftFa = Visit(altNode.GetChild(ContextType.CT_REGEXPALTERNATION_TERMS, 0));

            CIt_GraphNodes it = new CIt_GraphNodes(leftFa);

            for (it.Begin(); !it.End(); it.Next())
            {
                leftFa.PrefixElementLabel(leftFa.GetFANodePrefix(it.M_CurrentItem), it.M_CurrentItem);
            }

            FA rightFa = Visit(altNode.GetChild(ContextType.CT_REGEXPALTERNATION_TERMS, 1));

            it = new CIt_GraphNodes(rightFa);
            for (it.Begin(); !it.End(); it.Next())
            {
                rightFa.PrefixElementLabel(rightFa.GetFANodePrefix(it.M_CurrentItem), it.M_CurrentItem);
            }

            //2.Synthesize the two FAs to a new one
            m_currentNFA = alttempSyn.Sythesize(leftFa, rightFa, CGraph.CMergeGraphOperation.MergeOptions.MO_DEFAULT);

            m_ReportingServices.ExctractThompsonStep(m_currentNFA, @"Alternation_" + m_currentNFA.M_Label + ".dot", this.GetHashCode());
            m_ReportingServices.AddThompsonStepToReporting(m_currentNFA, this.GetHashCode());


            //return the final-synthesized FA
            return(m_currentNFA);
        }
Пример #2
0
        public override FA VisitLexerDescription(CASTElement currentNode)
        {
            int i = 0;
            FA  leftFa = null, rightFa;

            CGraph.CMergeGraphOperation.MergeOptions mergeOptions = CGraph.CMergeGraphOperation.MergeOptions.MO_DEFAULT;
            CSubsetConstructionAlgorithm             subcon;
            CHopcroftAlgorithm hopmin;
            CLexerDescription  lexerDescription = currentNode as CLexerDescription;
            List <CASTElement> rExpStatements = lexerDescription.GetContextChildren(ContextType.CT_LEXERDESCRIPTION_BODY);

            // Preserve labels of RegExp-derived NFA
            if (!m_options.IsSet(ThompsonOptions.TO_STEPS))
            {
                mergeOptions = CGraph.CMergeGraphOperation.MergeOptions.MO_PRESERVELABELS;
            }

            //1. Create FA
            foreach (var rExpStatement in rExpStatements)
            {
                if (i > 0)
                {
                    rightFa = Visit(rExpStatement);
                    //2.Synthesize the two FAs to a new one
                    CThompsonAlternationTemplate alttempSyn = new CThompsonAlternationTemplate(this.GetHashCode());
                    leftFa = alttempSyn.Sythesize(leftFa, rightFa, mergeOptions);

                    // Prefix node elements of the resulting graph with
                    CIt_GraphNodes it = new CIt_GraphNodes(leftFa);
                    for (it.Begin(); !it.End(); it.Next())
                    {
                        leftFa.PrefixElementLabel(leftFa.GetFANodePrefix(it.M_CurrentItem), it.M_CurrentItem);
                    }
                }
                else
                {
                    leftFa = Visit(rExpStatement);
                }
                i++;
            }

            m_NFA = leftFa;
            m_NFA.UpdateAlphabet();
            m_ReportingServices.ExctractThompsonStep(m_NFA, @"merge.dot", this.GetHashCode());
            if (i > 1)
            {
                m_ReportingServices.AddThompsonStepToReporting(m_NFA, this.GetHashCode(), true);
            }
            else
            {
                m_ReportingServices.ThompsonStepsGenerate();
            }

            //return the final-synthesized FA
            return(m_NFA);
        }