Example #1
0
        /// <summary>
        /// Parse the specification from string input into objects
        /// </summary>
        /// <param name="spec">string input of the model</param>
        /// <param name="option">option for LTL parsing, usually it is an empty string</param>
        protected virtual void ParseSpec(string spec, string option)
        {
            IsParsing = true;

            PNModel pn = PNModel.LoadLTSFromXML(spec);

            //Read Specification Name
            if (pn.Declaration.StartsWith(@"//@@"))
            {
                int index = pn.Declaration.IndexOf("@@", 4);
                if (index != -1)
                    SpecificationName = pn.Declaration.Substring(4, index - 4);
            }

            string program = pn.ToSpecificationString();

            ////parse the specification
            ////build the grammar tree
            ICharStream input = new ANTLRStringStream(program);
            PNTreeLexer lex = new PNTreeLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lex);
            PNTreeParser parser = new PNTreeParser(tokens);
            parser.Spec = this;
            PNTreeParser.specification_return r = parser.specification();
            if (parser.HiddenVars.Count > 0)
                Valuation.HiddenVars = parser.HiddenVars;

            Common.Utility.ParsingUltility.CheckIsParsingComplete(tokens, r.Tree);
            CommonTreeNodeStream nodes = new CommonTreeNodeStream(r.Tree);
            nodes.TokenStream = tokens;

            // construct the internal representation of the tree via a tree walker
            PNTreeWalker walker = new PNTreeWalker(nodes);
            walker.GlobalVarNames = parser.GlobalVarNames;
            walker.GlobalConstNames = parser.GlobalConstNames;
            walker.GlobalRecordNames = parser.GlobalRecordNames;
            walker.ChannelNames = parser.ChannelNames;
            walker.LTLStatePropertyNames = parser.LTLStatePropertyNames;
            walker.DefinitionNames = parser.DefinitionNames;
            walker.IsParameterized = parser.IsParameterized;
            walker.HasArbitraryProcess = parser.HasArbitraryProcess;

            walker.Spec = this;
            walker.program(option);
            IsParsing = false;
            GlobalConstantDatabase = walker.ConstantDatabase;

            foreach (KeyValuePair<string, Definition> pair in DefinitionDatabase)
            {
                List<string> gVar = pair.Value.GlobalVars;

                int i = 0;
                while (i < gVar.Count)
                {
                    if (SpecValuation.Variables != null && !SpecValuation.Variables.ContainsKey(gVar[i]))
                        gVar.RemoveAt(i);
                    else
                        i++;
                }
            }

            //get the relevant channels;
            if (ChannelDatabase.Count > 0)
            {
                SyncrhonousChannelNames = new List<string>(0);
                Dictionary<string, ChannelQueue> newChannelDatabase = new Dictionary<string, ChannelQueue>();

                foreach (KeyValuePair<string, ChannelQueue> pair in ChannelDatabase)
                {
                    if (pair.Value.Size == 0)
                        SyncrhonousChannelNames.Add(pair.Key);
                    else
                        newChannelDatabase.Add(pair.Key, pair.Value);
                }

                SpecValuation.Channels = newChannelDatabase;
                HasSyncrhonousChannel = SyncrhonousChannelNames.Count > 0;
            }

            foreach (KeyValuePair<string, AssertionBase> entry in AssertionDatabase)
                entry.Value.Initialize(this);

            CheckVariableRange();
        }
Example #2
0
        /// <summary>
        /// Parse the specification from string input into objects
        /// </summary>
        /// <param name="spec">string input of the model</param>
        /// <param name="option">option for LTL parsing, usually it is an empty string</param>
        protected virtual void ParseSpec(string spec, string option)
        {
            IsParsing = true;

            PAT.Common.GUI.PNModule.PNModel pn = PAT.Common.GUI.PNModule.PNModel.LoadLTSFromXML(spec);

            //Read Specification Name
            if (pn.Declaration.StartsWith(@"//@@"))
            {
                int index = pn.Declaration.IndexOf("@@", 4);
                if (index != -1)
                {
                    SpecificationName = pn.Declaration.Substring(4, index - 4);
                }
            }

            string program = pn.ToSpecificationString();

            ////parse the specification
            ////build the grammar tree
            ICharStream       input  = new ANTLRStringStream(program);
            PNTreeLexer       lex    = new PNTreeLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lex);
            PNTreeParser      parser = new PNTreeParser(tokens);

            parser.Spec = this;
            PNTreeParser.specification_return r = parser.specification();
            if (parser.HiddenVars.Count > 0)
            {
                Valuation.HiddenVars = parser.HiddenVars;
            }

            Common.Ultility.ParsingUltility.CheckIsParsingComplete(tokens, r.Tree);
            CommonTreeNodeStream nodes = new CommonTreeNodeStream(r.Tree);

            nodes.TokenStream = tokens;

            // construct the internal representation of the tree via a tree walker
            PNTreeWalker walker = new PNTreeWalker(nodes);

            walker.GlobalVarNames        = parser.GlobalVarNames;
            walker.GlobalConstNames      = parser.GlobalConstNames;
            walker.GlobalRecordNames     = parser.GlobalRecordNames;
            walker.ChannelNames          = parser.ChannelNames;
            walker.LTLStatePropertyNames = parser.LTLStatePropertyNames;
            walker.DefinitionNames       = parser.DefinitionNames;
            walker.IsParameterized       = parser.IsParameterized;
            walker.HasArbitraryProcess   = parser.HasArbitraryProcess;

            walker.Spec = this;
            walker.program(option);
            IsParsing = false;
            GlobalConstantDatabase = walker.ConstantDatabase;

            foreach (KeyValuePair <string, Definition> pair in DefinitionDatabase)
            {
                List <string> gVar = pair.Value.GlobalVars;

                int i = 0;
                while (i < gVar.Count)
                {
                    if (SpecValuation.Variables != null && !SpecValuation.Variables.ContainsKey(gVar[i]))
                    {
                        gVar.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }
            }

            //get the relevant channels;
            if (ChannelDatabase.Count > 0)
            {
                SyncrhonousChannelNames = new List <string>(0);
                Dictionary <string, ChannelQueue> newChannelDatabase = new Dictionary <string, ChannelQueue>();

                foreach (KeyValuePair <string, ChannelQueue> pair in ChannelDatabase)
                {
                    if (pair.Value.Size == 0)
                    {
                        SyncrhonousChannelNames.Add(pair.Key);
                    }
                    else
                    {
                        newChannelDatabase.Add(pair.Key, pair.Value);
                    }
                }

                SpecValuation.Channels = newChannelDatabase;
                HasSyncrhonousChannel  = SyncrhonousChannelNames.Count > 0;
            }

            foreach (KeyValuePair <string, AssertionBase> entry in AssertionDatabase)
            {
                entry.Value.Initialize(this);
            }

            CheckVariableRange();
        }