Ejemplo n.º 1
0
/// <summary>
/// creates a function data structure
/// </summary>
/// <param name="line">Inital Line</param>
        public void FunctionDeclarative(string line)
        {
            int tempPC = PC + 1;

            string token = "";

            try
            {
                string[] lineData = StringUtilities.split(delims, this.data[PC]);

                List <FlowControll>           fc           = new List <FlowControll>();
                List <string>                 paramaters   = new List <string>();
                List <Ask>                    ak           = new List <Ask>();
                List <AgentCreationStatement> createAgents = new List <AgentCreationStatement>();

                bool report = false;
                bool param  = false;

                string name = lineData[1];
                foreach (string td in lineData)
                {
                    if (lineData.Length > 1 && td == "[" && lineData[1] == name)
                    {
                        param = true;
                    }

                    if (td == "]")
                    {
                        param = false;
                    }

                    if (param && !(td == "[" || td == "]") && !string.IsNullOrEmpty(td))
                    {
                        paramaters.Add(td);
                    }
                }

                if (lineData[0] == "to-report")
                {
                    report = true;
                }
                while (token != "end")
                {
                    if (this.data[tempPC].IndexOfAny(delims) != -1)
                    {
                        lineData = StringUtilities.split(delims, this.data[tempPC]);
                    }
                    else
                    {
                        lineData = new[] { this.data[tempPC] };
                    }
                    foreach (string td in lineData)
                    {
                        if (flowControllKeywords.Any(a => td.Equals(a)))
                        {
                            FlowControll fcc = FlowControl(tempPC + 1, this.data[tempPC]);
                            foreach (Block b in fcc.JumpTable.Values)
                            {
                                tempPC += b.body.Length;
                            }

                            fc.Add(fcc);
                        }
                        if (td.Equals(askKeyword))
                        {
                            ak.Add(AskDeclarative(this.data[tempPC], tempPC, tempPC - PC));
                        }
                        if (td.StartsWith(createKeyword))
                        {
                            createAgents.Add(AgentCreate(this.data[tempPC], tempPC, tempPC - PC));
                        }
                    }

                    foreach (string s in lineData)
                    {
                        if (s == "end")
                        {
                            token = s;
                            break;
                        }
                    }
                    tempPC++;
                    //token = this.data[tempPC];
                }
                string[] lines = new string[tempPC - (PC + 1)];
                for (int i = PC + 1; i < tempPC; i++)
                {
                    lines[i - (PC + 1)] = this.data[i];
                }

                Function f = new Function(lines, PC + 1, name)
                {
                    paramaters = paramaters, Report = report
                };
                f.askData      = ak;
                f.flowControls = fc;
                f.agentData    = createAgents;
                s.AddFunction(f);
            }
            catch (Exception e)
            { throw new RTException("Function parsing failed on line " + tempPC + " with exception " + e.Message); }
        }