public static AgentsList GetAgentList(ParserState state)
        {
            AgentsList al   = new AgentsList();
            Token      open = state.PopToken();

            if (open.Name != "[")
            {
                open.ThrowException("Expected '[' at the beginning of agents list.");
            }
            bool  correctSyntax = false;
            Token close         = state.PeepToken();

            if (close == null)
            {
                open.ThrowException("Expected empty list of agents '[]' or agent name.");
            }
            if (close.Name == "]")
            {
                state.PopToken();
                return(al);
            }
            while (state.TokenList.Count > 0)
            {
                Token t = state.PopToken();
                if (state.Agent.ContainsKey(t.Name))
                {
                    al.Add(new Agent(t.Name));
                }
                else
                {
                    t.ThrowException("Agent name doesn't exist.");
                }
                if (state.TokenList.Count == 0)
                {
                    return(null);
                }

                Token x = state.PopToken();
                if (x.Name == "]")
                {
                    correctSyntax = true;
                    break;
                }
                if (x.Name != ",")
                {
                    x.ThrowException("',' should separate agents' names.");
                }
            }
            if (correctSyntax)
            {
                return(al);
            }
            return(null);
        }
        public List <AgentsList> AgentsGroups()
        {
            AgentsList agents;

            if (Agent is null)
            {
                agents = new AgentsList();
            }
            else
            {
                agents = new AgentsList(Agent.ToList());
            }

            foreach (Expression ex in this)
            {
                if (ex as ByCausesIf != null)
                {
                    var temp = ex as ByCausesIf;
                    agents.AddRange(temp.G);
                }
                else if (ex as ByReleasesIf != null)
                {
                    var temp = ex as ByReleasesIf;
                    agents.AddRange(temp.Agents);
                }
                else if (ex as ObservableAfter != null)
                {
                    var temp = ex as ObservableAfter;
                    agents.AddRange(temp.Instructions.SelectMany(x => x.Item2));
                }
                else if (ex as After != null)
                {
                    var temp = ex as After;
                    agents.AddRange(temp.Instructions.SelectMany(x => x.Item2));
                }
            }
            agents = new AgentsList(agents.Distinct().ToList());
            var result = new List <AgentsList>();

            for (int i = 0; i < Math.Pow(2, agents.Count); i++)
            {
                var        binary = Convert.ToString(i, 2).PadLeft(agents.Count, '0').Select(x => x == '1' ? true : false).ToArray();
                AgentsList temp   = new AgentsList();
                for (int j = 0; j < agents.Count; j++)
                {
                    if (binary[j])
                    {
                        temp.Add(agents[j]);
                    }
                }
                result.Add(temp);
            }
            return(result);
        }