Ejemplo n.º 1
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);
        }
        public override FA VisitRegexpStatement(CASTElement currentNode)
        {
            CRegexpStatement curNode = currentNode as CRegexpStatement;

            m_currentRegularExpression = curNode;

            // Generate the FA for the current regular expression
            FA fa = base.VisitRegexpStatement(currentNode);

            fa.UpdateAlphabet();
            m_currentNFA  = fa;
            m_currentLine = curNode.M_Line;

            m_ReportingServices.ExctractThompsonStep(fa, "merge" + m_currentLine + ".dot", this.GetHashCode(), true);

            // Record the derived NFA to the RERecords
            m_reRecords[curNode.M_Line].M_Nfa = fa;

            // Name the nodes of current branch of the FA with the name of the current regular expression
            fa.SetFANodePrefix(curNode.M_StatementID);
            fa.SetFANodesLineDependency(curNode.M_Line);

            m_currentRegularExpression = null;
            fa.EmmitToFile("merge" + m_currentLine + ".txt", new object[1] {
                FA.m_FAINFOKEY
            });
            return(fa);
        }
Ejemplo n.º 3
0
        public override FA VisitRegexpStatement(CASTElement currentNode)
        {
            CRegexpStatement curNode = currentNode as CRegexpStatement;

            m_currentRegularExpression = curNode;

            // Generate the FA for the current regular expression
            FA fa = base.VisitRegexpStatement(currentNode);

            m_currentNFA  = fa;
            m_currentLine = curNode.M_Line;

            m_ReportingServices.ExctractThompsonStep(fa, "merge" + m_currentLine + ".dot");

            // Record the derived NFA to the RERecords
            m_reRecords[curNode.M_Line].M_Nfa = fa;

            // Name the nodes of current branch of the FA with the name of the current regular expression
            fa.SetFANodePrefix(curNode.M_StatementID);
            fa.SetFANodesLineDependency(curNode.M_Line);

            m_currentRegularExpression = null;

            return(fa);
        }
Ejemplo n.º 4
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.º 5
0
        public override int VisitAssertionBwdneg(CASTElement currentNode)
        {
            CASTComposite current = currentNode as CASTComposite;
            string        clusterName;
            string        contextName;

            m_outputStream.WriteLine("\"{0}\"->\"{1}\"", currentNode.M_Parent.M_Label, currentNode.M_Label);

            // Visit assertionbwdneg context
            if (current.GetNumberOfContextElements(ContextType.CT_ASSERTION_BWDNEG) > 0)
            {
                clusterName = "cluster" + ms_clusterCounter++;
                contextName = ContextType.CT_ASSERTION_BWDNEG.ToString();
                m_outputStream.WriteLine(
                    "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                    clusterName, contextName);
                foreach (CASTElement element in current.GetContextChildren(ContextType.CT_ASSERTION_BWDNEG))
                {
                    m_outputStream.WriteLine("\"{0}\"", element.M_Label);
                    if (CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_Color != Color.C_DEFAULT)
                    {
                        m_outputStream.Write(" [fillcolor = " + CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_ColorName + "]");
                    }
                }
                m_outputStream.WriteLine("}");
            }


            base.VisitAssertionBwdneg(currentNode);

            return(0);
        }
        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);
        }
        public override FA VisitRegexpbasicParen(CASTElement currentNode)
        {
            CASTComposite curNode = currentNode as CASTComposite;

            m_currentNFA = Visit(curNode.GetChild(ContextType.CT_RGEXPBASIC_PAREN, 0));

            return(m_currentNFA);
        }
        public override FA VisitRegexpClosure(CASTElement currentNode)
        {
            CRegexpClosure closNode = currentNode as CRegexpClosure;

            //1.Create FA
            CThompsonClosureTemplate newFA = new CThompsonClosureTemplate(this.GetHashCode(), currentNode.M_Text);

            //2.Check the type of the closure
            if (closNode.M_ClosureType == CRegexpClosure.ClosureType.CLT_NONEORMULTIPLE)
            {
                FA customFA = Visit(closNode.GetChild(ContextType.CT_REGEXPCLOSURE_REGEXP, 0));
                m_currentNFA = newFA.SynthesizeNoneOrMul(customFA);
            }

            else if (closNode.M_ClosureType == CRegexpClosure.ClosureType.CLT_ONEORMULTIPLE)
            {
                FA customFA = Visit(closNode.GetChild(ContextType.CT_REGEXPCLOSURE_REGEXP, 0));
                m_currentNFA = newFA.SynthesisOneOrMul(customFA);
            }
            else if (closNode.M_ClosureType == CRegexpClosure.ClosureType.CLT_ONEORZERO)
            {
                FA customFA = Visit(closNode.GetChild(ContextType.CT_REGEXPCLOSURE_REGEXP, 0));
                m_currentNFA = newFA.SynthesizeOneOrNone(customFA);
            }
            else if (closNode.M_ClosureType == CRegexpClosure.ClosureType.CLT_FINITECLOSURE)
            {
                CClosureRange rangeNode = closNode.GetChild(ContextType.CT_REGEXPCLOSURE_QUANTIFIER, 0) as CClosureRange;
                FA            customFA  = Visit(closNode.GetChild(ContextType.CT_REGEXPCLOSURE_REGEXP, 0));
                m_currentNFA = newFA.SynthesizeFinite(customFA, rangeNode.M_ClosureMultiplicityLB,
                                                      rangeNode.M_ClosureMultiplicityUB);
            }
            else if (closNode.M_ClosureType == CRegexpClosure.ClosureType.CLT_NONEORMULTIPLE_NONGREEDY)
            {
                //TODO
            }
            else if (closNode.M_ClosureType == CRegexpClosure.ClosureType.CLT_ONEORMULTIPLE_NONGREEDY)
            {
                //TODO
            }
            else
            {
                Console.WriteLine("No proper input");
            }

            // Prefix the nodes of the new NFA with the prefix  for the current regular expression
            CIt_GraphNodes it = new CIt_GraphNodes(m_currentNFA);

            for (it.Begin(); !it.End(); it.Next())
            {
                m_currentNFA.PrefixElementLabel(m_currentRegularExpression.M_StatementID, it.M_CurrentItem);
            }

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

            //4.Pass FA to the predecessor
            return(m_currentNFA);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Its a leaf in the tree
        /// Visits the node given as an argument and prints the cluster affilliated to it
        /// </summary>
        /// <param name="currentNode">the node we want to print </param>
        ///
        public override int VisitRegexpbasicString(CASTElement currentNode)
        {
            CASTLeaf <string> current = currentNode as CASTLeaf <string>;
            string            clusterName;
            string            contextName;

            m_outputStream.WriteLine("\"{0}\"->\"{1}\"", currentNode.M_Parent.M_Label, currentNode.M_Label);

            return(0);
        }
Ejemplo n.º 11
0
        public override int VisitTerminal(CASTElement node)
        {
            CASTComposite current = node as CASTComposite;
            string        clusterName;
            string        contextName;

            m_outputStream.WriteLine("\"{0}\"->\"{1}\"", node.M_Parent.M_Label, node.M_Label);

            // Visit range_min context
            return(0);
        }
        public override FA VisitRange(CASTElement currentNode)
        {
            CRange rangeNode = currentNode as CRange;
            CThompsonRangeTemplate rangeTemplate = new CThompsonRangeTemplate(this.GetHashCode());

            m_currentNFA = rangeTemplate.Synthesize(rangeNode);

            m_ReportingServices.ExctractThompsonStep(m_currentNFA, @"Range_" + rangeNode.MRange.ToString() + ".dot", this.GetHashCode());
            m_ReportingServices.AddThompsonStepToReporting(m_currentNFA, this.GetHashCode());
            //4.Pass FA to the predecessor
            return(m_currentNFA);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Visits the children of the specified context in the currentNode
        /// </summary>
        /// <param name="currentNode">The current node.</param>
        /// <returns></returns>
        public virtual Return VisitContext(CASTElement currentNode, ContextType context)
        {
            CAbstractIterator <CASTElement> it = m_iteratorFactory.CreateIteratorASTElementDescentantsContext(currentNode);

            // Call Accept to all children in the specified context of the current node
            for (it.ItBegin(context); !it.ItEnd(); it.ITNext())
            {
                it.M_item.AcceptVisitor(this);
            }

            return(default(Return));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// <c>VisitChildren</c> method is used to visit child nodes of the node given
        /// as a parameter. This method provides default functionality for
        /// </summary>
        /// <param name="currentNode">The current node.</param>
        /// <returns></returns>
        public virtual Return VisitChildren(CASTElement currentNode)
        {
            CAbstractIterator <CASTElement> it = m_iteratorFactory.CreateIteratorASTElementDescentantsFlatten(currentNode);
            Return r = default(Return);

            // Call Accept to all children of the current node
            for (it.ItBegin(); !it.ItEnd(); it.ITNext())
            {
                r = AggregateResult(it.M_item.AcceptVisitor(this));
            }
            return(r);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Visits the children of the specified node <c>current</c> raising events
        /// at specific sequence points determined by the iterator
        /// </summary>
        /// <param name="currentNode">The current node.</param>
        /// <returns></returns>
        public virtual Return VisitChildrenEvents(CASTElement currentNode)
        {
            CAbstractIterator <CASTElement> it =
                m_iteratorFactory.CreateIteratorASTElementDescentantsFlattenEvents(currentNode, m_events, this);

            // Call Accept to all children of the current node
            for (it.ItBegin(); !it.ItEnd(); it.ITNext())
            {
                it.M_item.AcceptVisitor(this);
            }

            return(default(Return));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Visits the node given as an argument and all of its contexts
        /// and prints the cluster affilliated to it
        /// </summary>
        /// <param name="currentNode">the node we want to print </param>
        ///
        public override int VisitRegexpClosure(CASTElement currentNode)
        {
            CASTComposite current = currentNode as CASTComposite;
            string        clusterName;
            string        contextName;

            m_outputStream.WriteLine("\"{0}\"->\"{1}\"", currentNode.M_Parent.M_Label, currentNode.M_Label);

            // Visit closure's regexp context
            if (current.GetNumberOfContextElements(ContextType.CT_REGEXPCLOSURE_REGEXP) > 0)
            {
                clusterName = "cluster" + ms_clusterCounter++;
                contextName = ContextType.CT_REGEXPCLOSURE_REGEXP.ToString();
                m_outputStream.WriteLine(
                    "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                    clusterName, contextName);
                foreach (CASTElement element in current.GetContextChildren(ContextType.CT_REGEXPCLOSURE_REGEXP))
                {
                    m_outputStream.WriteLine("\"{0}\"", element.M_Label);
                    if (CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_Color != Color.C_DEFAULT)
                    {
                        m_outputStream.WriteLine(" [fillcolor = " + CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_ColorName + "]");
                    }
                }
                m_outputStream.WriteLine("}");
            }

            // Visit closure's quantifier context
            if (current.GetNumberOfContextElements(ContextType.CT_REGEXPCLOSURE_QUANTIFIER) > 0)
            {
                clusterName = "cluster" + ms_clusterCounter++;
                contextName = ContextType.CT_REGEXPCLOSURE_QUANTIFIER.ToString();
                m_outputStream.WriteLine(
                    "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                    clusterName, contextName);
                foreach (CASTElement element in current.GetContextChildren(ContextType.CT_REGEXPCLOSURE_QUANTIFIER))
                {
                    m_outputStream.WriteLine("\"{0}\"", element.M_Label);
                    if (CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_Color != Color.C_DEFAULT)
                    {
                        m_outputStream.WriteLine(" [fillcolor = " + CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_ColorName + "]");
                    }
                }
                m_outputStream.WriteLine("}");
            }

            base.VisitRegexpClosure(currentNode);

            return(0);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Visits the node given as an argument and prints the cluster affilliated to it
        /// </summary>
        /// <param name="currentNode">The node we want to print</param>
        /// <returns></returns>
        public override int VisitRegexpbasicSet(CASTElement currentNode)
        {
            CRegexpbasicSet current = currentNode as CRegexpbasicSet;
            string          clusterName;
            string          contextName;

            m_outputStream.WriteLine("\"{0}\"->\"{1}\"", currentNode.M_Parent.M_Label, currentNode.M_Label);
            //set negation
            if (current.M_IsSetNegation)
            {
                if (current.GetNumberOfContextElements(ContextType.CT_REGEXPBASIC_SETNEGATION) > 0)
                {
                    clusterName = "cluster" + ms_clusterCounter++;
                    contextName = ContextType.CT_REGEXPBASIC_SETNEGATION.ToString();
                    m_outputStream.WriteLine(
                        "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                        clusterName, contextName);
                    foreach (CASTElement element in current.GetContextChildren(ContextType.CT_REGEXPBASIC_SETNEGATION))
                    {
                        m_outputStream.WriteLine("\"{0}\"", element.M_Label);
                        if (CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_Color != Color.C_DEFAULT)
                        {
                            m_outputStream.Write(" [fillcolor = " + CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_ColorName + "]");
                        }
                    }
                    m_outputStream.WriteLine("}");
                }
            }
            // Visit regexpbasic set context
            else if (current.GetNumberOfContextElements(ContextType.CT_REGEXPBASIC_SET) > 0)
            {
                clusterName = "cluster" + ms_clusterCounter++;
                contextName = ContextType.CT_REGEXPBASIC_SET.ToString();
                m_outputStream.WriteLine(
                    "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                    clusterName, contextName);
                foreach (CASTElement element in current.GetContextChildren(ContextType.CT_REGEXPBASIC_SET))
                {
                    m_outputStream.WriteLine("\"{0}\"", element.M_Label);
                    if (CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_Color != Color.C_DEFAULT)
                    {
                        m_outputStream.Write(" [fillcolor = " + CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_ColorName + "]");
                    }
                }
                m_outputStream.WriteLine("}");
            }
            base.VisitRegexpbasicSet(currentNode);

            return(0);
        }
        public override FA VisitRegexpbasicSet(CASTElement currentNode)
        {
            CRegexpbasicSet setNode = currentNode as CRegexpbasicSet;

            CThompsonBasicSet setTemplate = new CThompsonBasicSet(this.GetHashCode());

            m_currentNFA = setTemplate.Synthesize(setNode.MSet);

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

            m_ReportingServices.ExctractThompsonStep(m_currentNFA, @"BasicSet_" + setNode.MSet.ToString() + ".dot", this.GetHashCode());
            m_ReportingServices.AddThompsonStepToReporting(m_currentNFA, this.GetHashCode());

            return(m_currentNFA);
        }
Ejemplo n.º 19
0
        /*
         * /* 27 #1# , CT_RANGE_MAX = 28,
         *  CT_NA*/

        /// <summary>
        /// Visits the node given as an argument and all of its contexts
        ///  and prints the cluster affilliated to it
        /// </summary>
        /// <param name="currentNode">the node we want to print </param>
        ///
        public override int VisitLexerDescription(CASTElement currentNode)
        {
            CASTComposite current = currentNode as CASTComposite;
            string        clusterName;
            string        contextName;

            m_outputStream.WriteLine("digraph {\n");

            // Visit context
            if (current.GetNumberOfContextElements(ContextType.CT_LEXERDESCRIPTION_BODY) > 0)
            {
                clusterName = "cluster" + ms_clusterCounter++;
                contextName = ContextType.CT_LEXERDESCRIPTION_BODY.ToString();
                m_outputStream.WriteLine(
                    "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                    clusterName, contextName);
                foreach (CASTElement element in current.GetContextChildren(ContextType.CT_LEXERDESCRIPTION_BODY))
                {
                    m_outputStream.WriteLine("\"{0}\"", element.M_Label);
                    if (CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_Color != Color.C_DEFAULT)
                    {
                        m_outputStream.WriteLine(" [fillcolor = " + CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_ColorName + "]");
                    }
                }
                m_outputStream.WriteLine("}");
            }

            base.VisitLexerDescription(currentNode);

            m_outputStream.WriteLine("}");
            m_outputStream.Close();

            if (true)
            {
                Process process = new Process();
                // Configure the process using the StartInfo properties.
                process.StartInfo.FileName  = "dot.exe";
                process.StartInfo.Arguments = "-Tgif " + m_outputFile + " -o" +
                                              Path.GetFileNameWithoutExtension(m_outputFile) + ".gif";
                process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                process.Start();
                process.WaitForExit();// Waits here for the process to exit.
            }


            return(0);
        }
Ejemplo n.º 20
0
        public override FA VisitRegexpStatement(CASTElement currentNode)
        {
            CRegexpStatement curNode = currentNode as CRegexpStatement;

            m_currentRegularExpression = curNode;

            // Generate the FA for the current regular expression
            FA fa = base.VisitRegexpStatement(currentNode);

            // Name the nodes of current branch of the FA with the name of the current regular expression
            fa.SetFANodePrefix(curNode.M_StatementID);
            fa.SetFANodesLineDependency(curNode.M_Line);

            m_currentRegularExpression = null;

            return(fa);
        }
Ejemplo n.º 21
0
        public override int VisitRange(CASTElement currentNode)
        {
            CASTComposite current = currentNode as CASTComposite;
            string        clusterName;
            string        contextName;

            m_outputStream.WriteLine("\"{0}\"->\"{1}\"", currentNode.M_Parent.M_Label, currentNode.M_Label);

            // Visit range_min context
            clusterName = "cluster" + ms_clusterCounter++;
            contextName = ContextType.CT_RANGE_MIN.ToString();
            m_outputStream.WriteLine(
                "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                clusterName, contextName);
            foreach (CASTElement element in current.GetContextChildren(ContextType.CT_RANGE_MIN))
            {
                m_outputStream.WriteLine("\"{0}\"", element.M_Label);
                if (CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_Color != Color.C_DEFAULT)
                {
                    m_outputStream.Write(" [fillcolor = " + CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_ColorName + "]");
                }
            }

            m_outputStream.WriteLine("}");

            // Visit range_max context
            clusterName = "cluster" + ms_clusterCounter++;
            contextName = ContextType.CT_RANGE_MAX.ToString();
            m_outputStream.WriteLine(
                "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                clusterName, contextName);
            foreach (CASTElement element in current.GetContextChildren(ContextType.CT_RANGE_MAX))
            {
                m_outputStream.WriteLine("\"{0}\"", element.M_Label);
                if (CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_Color != Color.C_DEFAULT)
                {
                    m_outputStream.Write(" [fillcolor = " + CConfigurationSettings.m_nodeTypeConfiguration[element.M_NodeType].M_ColorName + "]");
                }
            }
            m_outputStream.WriteLine("}");


            base.VisitRange(currentNode);

            return(0);
        }
Ejemplo n.º 22
0
        public override int VisitActionCode(CASTElement currentNode)
        {
            CASTComposite current = currentNode as CASTComposite;
            string        clusterName;
            string        contextName;

            m_outputStream.WriteLine("\"{0}\"->\"{1}\"", currentNode.M_Parent.M_Label, currentNode.M_Label);

            // Visit range_min context
            if (current.GetNumberOfContextElements(ContextType.CT_ACTIONCODE) > 0)
            {
                clusterName = "cluster" + ms_clusterCounter++;
                contextName = ContextType.CT_ACTIONCODE.ToString();
                m_outputStream.WriteLine(
                    "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                    clusterName, contextName);
                m_outputStream.WriteLine("}");
            }
            return(0);
        }
Ejemplo n.º 23
0
        public override FA VisitRegexpClosure(CASTElement currentNode)
        {
            CRegexpClosure closNode = currentNode as CRegexpClosure;

            //1.Create FA
            CThompsonClosureTemplate newFA = new CThompsonClosureTemplate();

            //2.Check the type of the closure
            if (closNode.M_ClosureType == CRegexpClosure.ClosureType.CLT_NONEORMULTIPLE)
            {
                FA customFA = Visit(closNode.GetChild(ContextType.CT_REGEXPCLOSURE_REGEXP, 0));
                m_currentNFA = newFA.SynthesizeNoneOrMul(customFA);
            }

            else if (closNode.M_ClosureType == CRegexpClosure.ClosureType.CLT_ONEORMULTIPLE)
            {
                FA customFA = Visit(closNode.GetChild(ContextType.CT_REGEXPCLOSURE_REGEXP, 0));
                m_currentNFA = newFA.SynthesisOneOrMul(customFA);
            }
            else if (closNode.M_ClosureType == CRegexpClosure.ClosureType.CLT_ONEORZERO)
            {
                FA customFA = Visit(closNode.GetChild(ContextType.CT_REGEXPCLOSURE_REGEXP, 0));
                m_currentNFA = newFA.SynthesizeOneOrNone(customFA);
            }
            else
            {
                Console.WriteLine("No proper input");
            }

            CIt_GraphNodes it = new CIt_GraphNodes(m_currentNFA);

            for (it.Begin(); !it.End(); it.Next())
            {
                m_currentNFA.PrefixElementLabel(m_currentRegularExpression.M_StatementID, it.M_CurrentItem);
            }
            m_ReportingServices.ExctractThompsonStep(m_currentNFA, @"../bin/Debug/Closure_" + m_currentNFA.M_Label + ".dot");
            m_ReportingServices.AddThompsonStepToReporting(m_currentNFA);

            //4.Pass FA to the predecessor
            return(m_currentNFA);
        }
Ejemplo n.º 24
0
        /// <summary>
        ///
        /// Visits the node given as an argument and prints the cluster affilliated to it
        /// </summary>
        /// <param name="currentNode">the node we want to print </param>
        ///
        public override int VisitRegexpbasicParen(CASTElement currentNode)
        {
            CASTComposite current = currentNode as CASTComposite;
            string        clusterName;
            string        contextName;

            m_outputStream.WriteLine("\"{0}\"->\"{1}\"", currentNode.M_Parent.M_Label, currentNode.M_Label);
            // Visit regexpalternation context
            if (current.GetNumberOfContextElements(ContextType.CT_RGEXPBASIC_PAREN) > 0)
            {
                clusterName = "cluster" + ms_clusterCounter++;
                contextName = ContextType.CT_RGEXPBASIC_PAREN.ToString();
                m_outputStream.WriteLine(
                    "subgraph {0} {{\n node [style=filled,color=white];\n style=filled;\n color=lightgrey;\n label = \"{1}\";\n",
                    clusterName, contextName);
                m_outputStream.WriteLine("}");
            }


            base.VisitRegexpbasicParen(currentNode);

            return(0);
        }
        public override FA VisitRegexpConcatenation(CASTElement currentNode)
        {
            CRegexpConcatenation altNode = currentNode as CRegexpConcatenation;

            //1. Create FA
            CThompsonConcatenationTemplate alttempSyn = new CThompsonConcatenationTemplate(this.GetHashCode());
            FA leftFa  = Visit(altNode.GetChild(ContextType.CT_REGEXPCONCATENATION_TERMS, 0));
            FA rightFa = Visit(altNode.GetChild(ContextType.CT_REGEXPCONCATENATION_TERMS, 1));

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

            CIt_GraphNodes it = new CIt_GraphNodes(m_currentNFA);

            for (it.Begin(); !it.End(); it.Next())
            {
                m_currentNFA.PrefixElementLabel(m_currentRegularExpression.M_StatementID, it.M_CurrentItem);
            }

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

            return(m_currentNFA);
        }
Ejemplo n.º 26
0
 public virtual Return VisitRegexpConcatenation(CASTElement currentNode)
 {
     return(base.VisitChildren(currentNode));
 }
Ejemplo n.º 27
0
 public virtual CAbstractIterator <CASTElement> CreateIteratorASTElementDescentantsContextEvents(CASTElement element,
                                                                                                 CASTGenericIteratorEvents events, object info = null)
 {
     return(new CASTElementDescentantsContextEventIterator(element, events, info));
 }
Ejemplo n.º 28
0
 public virtual CAbstractIterator <CASTElement> CreateIteratorASTElementDescentantsContext(CASTElement element)
 {
     return(new CASTElementDescentantsContextIterator(element));
 }
Ejemplo n.º 29
0
 public virtual Return VisitAction_code(CASTElement currentNode)
 {
     return(base.VisitChildren(currentNode));
 }
Ejemplo n.º 30
0
 public virtual Return VisitRegexpStatement(CASTElement currentNode)
 {
     return(base.VisitChildren(currentNode));
 }