Ejemplo n.º 1
0
        /// <summary>
        /// Compiles the given AST <code>ast</code> into a oWFN petri net
        /// </summary>
        /// <exception cref="System.NullReferenceException">Thrown when the AST <c>ast</c> is null</exception>
        /// <returns>An equivalent <c>PetriNet</c> representation</returns>
        public PetriNet Compile()
        {
            if (this.ast == null)
            {
                throw new NullReferenceException("AST cannot be null");
            }

            // Phylum
            net = new PetriNet();
            String prefix = net.ActivityCount + ".internal.";
            Place  p1     = net.NewPlace(prefix + "initialized");
            Place  p2     = net.NewPlace(prefix + "closed");

            // Initial Marking
            p1.Tokens = 1;
            // Final Marking
            HashSet <Place> final = new HashSet <Place>();

            final.Add(p2);
            net.AddFinalSet(final);
            // Compile inner activities
            int newID = ++net.ActivityCount;

            net = ast.Compile(net);
            // Merge final net
            net.Merge(p1, newID + ".internal.initialized");
            net.Merge(p2, newID + ".internal.closed");

            return(net);
        }