Пример #1
0
 public bool AddLogic(LogicElement logic)
 {
     if (LogicElement == null)
     {
         LogicElement = logic;
         foreach (var item in logic.ToDictionary())
         {
             Properties.Add(item.Key, item.Value);
         }
         return(true);
     }
     try
     {
         foreach (var item in LogicElement.ToDictionary())
         {
             Properties.Remove(item.Key);
         }
         foreach (var item in logic.ToDictionary())
         {
             Properties.Add(item.Key, item.Value);
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #2
0
        public static LogicElement C4prime(ParserState state)
        {
            Token t = state.PeepToken();

            if (t == null)
            {
                return(null);
            }
            if (t.Name == "->")
            {
                state.PopToken();
                LogicElement exp = C5(state);
                if (exp.Right == null)
                {
                    exp.Right = C4prime(state);
                }
                If if_exp = new If(null, exp);
                return(if_exp);
            }
            else if (t.Type == TokenType.Operator)
            {
                return(null);
            }
            else if (t.Type != TokenType.Keyword && !state.Action.ContainsKey(t.Name))
            {
                t.ThrowException("Expected keyword token.");
            }
            return(null);
        }
Пример #3
0
 public override void ResetSettingsTo(LogicElement model)
 {
     if (model is SystemJournal journal)
     {
         UpdateProperties(journal);
     }
 }
Пример #4
0
        public void AddEquation(ILogicElement x1, ILogicElement x2)
        {
            LogicElement t1 = x1.ToLogicElement();
            LogicElement t2 = x2.ToLogicElement();

            if (t1 is Function <WorldSymbol> f1 && t2 is Function <WorldSymbol> f2)
            {
                AddFunctionEquation(f1, f2);
            }
            else if (t1 is Function <Terminal> f3 && t2 is Function <Terminal> f4)
            {
                AddFunctionEquation(f3, f4);
            }

            //Rule 3 [x = x -> Cancel Equation]
            if (t1.Name == t2.Name)
            {
                return;
            }

            //Rule 4 [t = x -> x = t]
            if (t1.GetType() == typeof(Variable) && t2.GetType() != typeof(Variable))
            {
                equations.Add(new Equation <ILogicElement>(x2, x1));
            }
            else
            {
                equations.Add(new Equation <ILogicElement>(x1, x2));
            }
        }
Пример #5
0
 public OrViewModel(LogicElement model, IApplicationGlobalCommands globalCommands) : base(model, globalCommands)
 {
     this.ElementName = "ИЛИ";
     this.Description = "Логический элемент ИЛИ";
     this.Symbol      = "|";
     SetModel(_logicElementModel);
 }
Пример #6
0
    /// <summary>
    /// Moves snake to new position according to direction of movement.
    /// </summary>
    /// <param name="direction">direction of movement</param>
    /// <param name="extend">if true snake will be extended by one segment</param>
    public void Move(Vector2Int direction)
    {
        var newHead = NextHeadPosition(direction);


        if (!LogicElement.IsWalkable(board[newHead].Content))
        {
            return;
        }

        bool extend = LogicElement.IsExtend(board[newHead].Content);

        body.AddLast(newHead);


        if (extend)
        {
            // body.AddLast(newHead);
        }
        else
        {
            board[body.First.Value].SetTile(LogicElement.LogicElementType.None, true);
            body.RemoveFirst();
        }

        UpdateSnakeState();
    }
Пример #7
0
 public override void ResetSettingsTo(LogicElement model)
 {
     if (model is Output output)
     {
         UpdateProperties(output);
     }
 }
Пример #8
0
 public TriggerViewModel(LogicElement model, IApplicationGlobalCommands globalCommands)
 {
     base._globalCommands     = globalCommands;
     _logicElementModel       = model;
     this.ConnectorViewModels = new ObservableCollection <ConnectorViewModel>();
     SetModel(_logicElementModel);
 }
Пример #9
0
 protected override void SetModel(LogicElement model)
 {
     if (model is SystemJournal journal)
     {
         UpdateProperties(journal);
         base.SetModel(model);
     }
 }
Пример #10
0
 protected override void SetModel(LogicElement model)
 {
     if (model is Output output)
     {
         UpdateProperties(output);
         base.SetModel(model);
     }
 }
Пример #11
0
 public void AddElements(LogicElement logicElement, int v)
 {
     if (PlayerData._elements.FirstOrDefault(le => le.ElementType == logicElement.ElementType) == null)
     {
         PlayerData._elements.Add(new PlayerElement(logicElement.ElementType, 0));
     }
     PlayerData._elements.FirstOrDefault(le => le.ElementType == logicElement.ElementType).Count += v;
     OnElementsListChanged();
 }
Пример #12
0
 public void Init(LogicElement le)
 {
     _shopObject            = le;
     ItemName.text          = le.ElementName;
     ItemCost.text          = le.ElementCost + "";
     ItemPreview.sprite     = le.Img;
     ByeButton.interactable = Player.Instance.Money >= le.ElementCost;
     InfoButton.onClick.AddListener(ShowInfo);
     ByeButton.onClick.AddListener(Buy);
 }
Пример #13
0
        public InversionViewModel(LogicElement model, IApplicationGlobalCommands globalCommands)
        {
            base._globalCommands = globalCommands;
            _logicElementModel   = (Inversion)model;

            this.ElementName         = "НЕ";
            this.Description         = "Елемент инверсии логического сигнала";
            this.Symbol              = "~";
            this.ConnectorViewModels = new ObservableCollection <ConnectorViewModel>();
            SetModel(_logicElementModel);
        }
Пример #14
0
    public void ElementClicked(LogicModules editingModule, Vector2 position, LogicElement currentElement)
    {
        if (!_elementCounter.SelectedElement || Player.Instance.GetElementCount(_elementCounter.SelectedElement) == 0)
        {
            return;
        }

        if (currentElement.ElementType != LogicElement.LogicElementType.MyHead)
        {
            if (_elementCounter.SelectedElement.ElementType == LogicElement.LogicElementType.MyHead)
            {
                //click on any with head
                RemovePreviousHead();
            }
        }
        else
        {
            if (_elementCounter.SelectedElement.ElementType == LogicElement.LogicElementType.MyHead)
            {
                //click with head on head
                return;
            }
        }

        LogicElement newElement;

        if (_elementCounter.SelectedElement.ElementType == currentElement.ElementType)
        {
            newElement = DefaultResources.GetElementByEnum(LogicElement.LogicElementType.Any);
            Player.Instance.AddElements(currentElement, 1);
        }
        else
        {
            if (Player.Instance.GetElementCount(_elementCounter.SelectedElement) > 0)
            {
                Player.Instance.AddElements(_elementCounter.SelectedElement, -1);
                Player.Instance.AddElements(currentElement, 1);
                newElement = _elementCounter.SelectedElement;
            }
            else
            {
                newElement = currentElement;
                Debug.LogWarning("Not enough elements!");
            }
        }


        ((SimpleModule)editingModule).SetElement(position, newElement.ElementType);

        if (currentElement.ElementType == LogicElement.LogicElementType.MyHead)
        {
            PlaceHeadNear(position);
        }
    }
Пример #15
0
        public TimerViewModel(LogicElement model, IApplicationGlobalCommands globalCommands)
        {
            this._globalCommands    = globalCommands;
            this._model             = (Timer)model;
            this._logicElementModel = model;

            this.ElementName         = "Таймер";
            this.Description         = "Логический элемент Таймер";
            this.Symbol              = "T";
            this.ConnectorViewModels = new ObservableCollection <ConnectorViewModel>();
            this.SetModel(this._model);
        }
Пример #16
0
 public OutputViewModel(LogicElement model, IApplicationGlobalCommands globalCommands)
 {
     _globalCommands     = globalCommands;
     _outputModel        = (Output)model;
     _logicElementModel  = _outputModel;
     ElementName         = "Выход";
     Description         = "Елемент выходного дискретного сигнала";
     Symbol              = "Out";
     ConnectorViewModels = new ObservableCollection <ConnectorViewModel>();
     OutputSignals       = new ObservableCollection <string>();
     SetModel(this._outputModel);
 }
Пример #17
0
 public SystemJournalViewModel(LogicElement model, IApplicationGlobalCommands globalCommands)
 {
     _globalCommands     = globalCommands;
     _model              = (SystemJournal)model;
     _logicElementModel  = _model;
     ElementName         = "Журнал Системы";
     Description         = "Елемент выходного дискретного сигнала Журнал Системы";
     Symbol              = "ЖС";
     ConnectorViewModels = new ObservableCollection <ConnectorViewModel>();
     OutputSignals       = new ObservableCollection <string>();
     SetModel(this._model);
 }
Пример #18
0
 protected SimpleLogicElementViewModel(LogicElement model, IApplicationGlobalCommands globalCommands)
 {
     _logicElementModel   = model;
     this._globalCommands = globalCommands;
     AddInputCommand      = new RelayCommand(AddInput, CanAddInput);
     RemoveInputCommand   = new RelayCommand(RemoveInput, CanRemove);
     Inputs                   = new ObservableCollection <ConnectorViewModel>();
     Outputs                  = new ObservableCollection <ConnectorViewModel>();
     InputsForSettings        = new ObservableCollection <ConnectorViewModel>();
     OutputsForSettings       = new ObservableCollection <ConnectorViewModel>();
     this.ConnectorViewModels = new ObservableCollection <ConnectorViewModel>();
     this.ConnectorViewModels.CollectionChanged += OnConnectorsCollectionChanged;
     SetModel(model);
 }
Пример #19
0
 public InputViewModel(LogicElement model, IApplicationGlobalCommands globalCommands)
 {
     this._globalCommands     = globalCommands;
     this._inputModel         = (Input)model;
     this._logicElementModel  = model;
     this._bases              = new List <string>();
     this._allInputSignals    = new List <Dictionary <int, string> >();
     this.ElementName         = "Вход";
     this.Description         = "Елемент входного дискретного сигнала";
     this.Symbol              = "In";
     this.Signals             = new ObservableCollection <string>();
     this.ConnectorViewModels = new ObservableCollection <ConnectorViewModel>();
     this.SetModel(this._inputModel);
 }
Пример #20
0
        public static LogicElement C4(ParserState state)
        {
            LogicElement fluent = C5(state);

            if (fluent == null)
            {
                return(null);
            }
            LogicElement exp = C4prime(state);

            if (exp != null)
            {
                exp.Left = fluent;
                return(exp);
            }
            return(fluent);
        }
Пример #21
0
        internal Entity RebuildSelf(INode node)
        {
            Id     = node.Id;
            Labels = node.Labels.ToArray();
            foreach (var item in node.Properties)
            {
                if (Properties.ContainsKey(item.Key))
                {
                    Properties.Remove(item.Key);
                }
                Properties.Add(item.Key, item.Value);
            }

            LogicElement = new LogicElement(Properties);

            return(this);
        }
Пример #22
0
        public Link RebuildSelf(IRelationship link)
        {
            Id   = link.Id;
            Type = link.Type;
            foreach (var item in link.Properties)
            {
                if (Properties.ContainsKey(item.Key))
                {
                    Properties.Remove(item.Key);
                }
                Properties.Add(item.Key, item.Value);
            }

            LogicElement = new LogicElement(Properties);

            return(this);
        }
Пример #23
0
        public static LogicElement EntryC1(ParserState state)
        {
            Token a;

            a = state.PopToken();
            if (a.Type != TokenType.Operator || a.Name != "[")
            {
                a.ThrowException("Expected '[' at the beginning of a logic expression.");
            }
            LogicElement c = C1(state);

            a = state.PopToken();
            if (a.Type != TokenType.Operator || a.Name != "]")
            {
                a.ThrowException("Expected ']' at the end of a logic expression.");
            }
            return(c);
        }
Пример #24
0
    public int GetElementCount(LogicElement element)
    {
        if (element.ElementType == LogicElement.LogicElementType.MyHead)
        {
            return(1);
        }

        if (element.ElementType == LogicElement.LogicElementType.Any)
        {
            return(int.MaxValue);
        }

        if (PlayerData._elements.FirstOrDefault(le => le.ElementType == element.ElementType) == null)
        {
            AddElements(element, 0);
        }


        return(PlayerData._elements.FirstOrDefault(le => le.ElementType == element.ElementType).Count);
    }
Пример #25
0
        public static LogicElement C5(ParserState state)
        {
            Token t = state.PopToken();

            if (t.Name == "(")
            {
                LogicElement inside = C1(state);
                Token        close  = state.PopToken();
                if (close == null || close.Name != ")")
                {
                    t.ThrowException("No closing brackets");
                }
                return(inside);
            }
            else if (t.Name == "~")
            {
                Token name = state.PopToken();
                if (!state.Fluent.ContainsKey(name.Name) && !state.Noninertial.ContainsKey(name.Name))
                {
                    name.ThrowException("Expected fluent name");
                }
                Fluent f      = new Fluent(name.Name);
                Not    retVal = new Not(f);
                return(retVal);
            }
            else if (state.Fluent.ContainsKey(t.Name) || state.Noninertial.ContainsKey(t.Name))
            {
                Fluent f = new Fluent(t.Name);
                f.Value = true;
                return(f);
            }
            else
            {
                t.ThrowException("Error in logical expression. Mismatched bracekts or operator in wrong places.");
            }
            return(null);
        }
Пример #26
0
    public Vector2Int GetDirection()
    {
        List <Vector2Int> avaliableDirections = new List <Vector2Int>
        {
            Vector2Int.left,
            Vector2Int.right,
            Vector2Int.up
        };

        List <Vector2Int> worldAvaliableDirections = new List <Vector2Int>();

        //remove not walkable tiles
        for (int i = 2; i >= 0; i--)
        {
            Vector2Int dir      = avaliableDirections[i];
            Vector2Int worldDir = HeadToBoard(this, dir);

            //Debug.Log((Head + worldDir)+" "+ board[Head + worldDir].Content);
            if (LogicElement.IsWalkable(board[Head + worldDir].Content))
            {
                worldAvaliableDirections.Add(worldDir);
            }
        }

        //return if ther is no walkable tiles near
        if (worldAvaliableDirections.Count == 0)
        {
            return(Vector2Int.zero);
        }

        worldAvaliableDirections = GetDirectionByModules(worldAvaliableDirections, this);


        int randomValue = Mathf.RoundToInt(UnityEngine.Random.Range(0, worldAvaliableDirections.Count));

        return(worldAvaliableDirections[randomValue]);
    }
Пример #27
0
    public void Buy(object shopObject)
    {
        switch (shopObject.GetType().ToString())
        {
        case "ModuleHolder":
            ModuleHolder moduleHolder = (ModuleHolder)shopObject;
            Player.Instance.Money -= moduleHolder.Cost;
            if (moduleHolder.moduleType == ModuleHolder.ModuleType.Simple)
            {
                Player.Instance.Modules.Add(new SimpleModule(moduleHolder));
            }
            else
            {
                Player.Instance.Modules.Add(new ComplexModule(moduleHolder));
            }
            break;

        case "SnakeSkin":
            SnakeSkin snakeSkin = (SnakeSkin)shopObject;
            Player.Instance.Money -= snakeSkin.SkinCost;
            Player.Instance.AddSkin(snakeSkin);
            break;

        case "LogicElement":
            LogicElement logicElement = (LogicElement)shopObject;
            Player.Instance.Money -= logicElement.ElementCost;
            Player.Instance.AddElements(logicElement, 1);
            break;

        case "ShopBonus":
            ShopBonus bonus = (ShopBonus)shopObject;
            Player.Instance.Money -= bonus.BonusCost;
            Player.Instance.AddBonus(bonus);
            break;
        }
    }
Пример #28
0
        public static void ParseKeyword(ParserState state, Token firstToken)
        {
            switch (firstToken.Name)
            {
            case "initially":
                LogicElement le = EntryC1(state);
                Initially    st = new Initially(le);
                state.Expression.Add(st);
                break;

            case "noninertial":
                ParseNoninertial(state, firstToken);
                break;

            case "by":
                Token action = state.TokenList[state.TokenList.Count - 1];
                state.TokenList.RemoveAt(state.TokenList.Count - 1);
                AgentsList al = GetAgentList(state);
                if (al == null)
                {
                    firstToken.ThrowException("Expected ']' at the end of agents list.");
                }
                Token t = state.PopToken();
                if (t == null)
                {
                    firstToken.ThrowException("Expected 'causes' or 'releases'.");
                }

                LogicElement result = null;
                if (t.Name == "releases")
                {
                    Token fT = state.PopToken();
                    if (fT == null)
                    {
                        firstToken.ThrowException("Expected fluent after release.");
                    }
                    else if (!state.Fluent.ContainsKey(fT.Name))
                    {
                        firstToken.ThrowException("Attempting to use undeclared fluent.");
                    }
                    result = state.Fluent[fT.Name];
                }
                else
                if (t.Name == "causes")
                {
                    result = EntryC1(state);
                }
                else
                {
                    t.ThrowException("Expected 'causes' or 'releases'.");
                }

                if (t.Name == "releases" && (result is Fluent) == false)
                {
                    t.ThrowException("Expected fluent after release.");
                }

                LogicElement condition = null;
                Token        if_token  = state.PeepToken();
                if (if_token != null && if_token.Name == "if")
                {
                    state.PopToken();
                    condition = EntryC1(state);
                }
                if (t.Name == "causes")
                {
                    if (condition == null)
                    {
                        state.Expression.Add(new MultiAgentLanguageModels.Expressions.ByCauses(
                                                 new MultiAgentLanguageModels.Action(action.Name),
                                                 al, result));
                    }
                    else
                    {
                        state.Expression.Add(new MultiAgentLanguageModels.Expressions.ByCausesIf(
                                                 new MultiAgentLanguageModels.Action(action.Name),
                                                 al, result, condition));
                    }
                }
                if (t.Name == "releases")
                {
                    if (condition == null)
                    {
                        state.Expression.Add(new MultiAgentLanguageModels.Expressions.ByReleases(
                                                 new MultiAgentLanguageModels.Action(action.Name),
                                                 al, (Fluent)result));
                        state.Expression.Add(new MultiAgentLanguageModels.Expressions.ByCauses(
                                                 new MultiAgentLanguageModels.Action(action.Name),
                                                 al, new Or(result, new Not(result))));
                    }
                    else
                    {
                        state.Expression.Add(new MultiAgentLanguageModels.Expressions.ByReleasesIf(
                                                 new MultiAgentLanguageModels.Action(action.Name),
                                                 al, (Fluent)result, condition));
                        state.Expression.Add(new MultiAgentLanguageModels.Expressions.ByCausesIf(
                                                 new MultiAgentLanguageModels.Action(action.Name),
                                                 al, new Or(result, new Not(result)), condition));
                    }
                }
                break;

            case "causes":
                MultiAgentLanguageModels.Action act =
                    new MultiAgentLanguageModels.Action(state.TokenList[state.TokenList.Count - 1].Name);
                state.TokenList.RemoveAt(state.TokenList.Count - 1);
                LogicElement effect = EntryC1(state);
                Token        if_exp = state.PeepToken();
                if (if_exp != null && if_exp.Name == "if")
                {
                    state.PopToken();
                    LogicElement con = EntryC1(state);
                    state.Expression.Add(new CausesIf(act, effect, con));
                }
                else
                {
                    state.Expression.Add(new Causes(act, effect));
                }
                break;

            case "releases":
                MultiAgentLanguageModels.Action act1 =
                    new MultiAgentLanguageModels.Action(state.TokenList[state.TokenList.Count - 1].Name);
                state.TokenList.RemoveAt(state.TokenList.Count - 1);
                Token eff1 = state.PopToken();
                if (eff1 == null)
                {
                    firstToken.ThrowException("Expected fluent after release.");
                }
                else if (!state.Fluent.ContainsKey(eff1.Name))
                {
                    firstToken.ThrowException("Attempting to use undeclared fluent.");
                }
                Token if_expr = state.PeepToken();
                if (if_expr != null && if_expr.Name == "if")
                {
                    state.PopToken();
                    LogicElement con = EntryC1(state);
                    state.Expression.Add(new ReleasesIf(act1, state.Fluent[eff1.Name], con));
                    state.Expression.Add(new CausesIf(act1, new Or(state.Fluent[eff1.Name], new Not(state.Fluent[eff1.Name])), con));
                }
                else
                {
                    state.Expression.Add(new Releases(act1, state.Fluent[eff1.Name]));
                    state.Expression.Add(new Causes(act1, new Or(state.Fluent[eff1.Name], new Not(state.Fluent[eff1.Name]))));
                }
                break;

            case "if":
                firstToken.ThrowException("Unexpected 'if' token.");
                break;

            case "impossible":
                Token token = state.PopToken();
                if (token == null)
                {
                    firstToken.ThrowException("Expected action name.");
                }
                if (!state.Action.ContainsKey(token.Name))
                {
                    token.ThrowException("Unknown action name.");
                }
                MultiAgentLanguageModels.Action ac = new MultiAgentLanguageModels.Action(token.Name);
                Token key = state.PopToken();
                if (key == null)
                {
                    firstToken.ThrowException("Expected 'by' or 'if' token.");
                }
                AgentsList agentsList = null;
                if (key.Name == "by")
                {
                    agentsList = GetAgentList(state);
                    Token cond_st = state.PeepToken();
                    if (cond_st == null || cond_st.Name != "if")
                    {
                        state.Expression.Add(new ImpossibleBy(ac, agentsList));
                    }
                    else
                    {
                        state.PopToken();
                        LogicElement c = EntryC1(state);
                        state.Expression.Add(new ImpossibleByIf(ac, agentsList, c));
                    }
                }
                else if (key.Name == "if")
                {
                    //Token cond_st = state.PopToken();
                    //if (cond_st == null || cond_st.Name != "if")
                    //key.ThrowException("Expected if after the list of agents.");
                    LogicElement c = EntryC1(state);
                    state.Expression.Add(new ImpossibleIf(ac, c));
                }
                else
                {
                    firstToken.ThrowException("Expected 'by' or 'if' token.");
                }
                break;

            case "always":
                LogicElement cond = EntryC1(state);
                state.Expression.Add(new Always(cond));
                break;

            case "not":
                Token act2 = state.TokenList[state.TokenList.Count - 1];
                MultiAgentLanguageModels.Action actt = new MultiAgentLanguageModels.Action(act2.Name);
                state.TokenList.RemoveAt(state.TokenList.Count - 1);
                Token by = state.PopToken();
                if (by == null || by.Name != "by")
                {
                    firstToken.ThrowException("Expected 'by' after 'not'.");
                }
                AgentsList agents = GetAgentList(state);
                Token      if_st  = state.PeepToken();
                if (if_st != null && if_st.Name == "if")
                {
                    state.PopToken();
                    condition = EntryC1(state);
                    foreach (Agent a in agents)
                    {
                        state.Expression.Add(new ImpossibleByIf(actt, new AgentsList()
                        {
                            a
                        }, condition));
                        Output.Print($"{actt.Name} not by {a.Name} under cond {condition.ToString()}");
                    }
                }
                else
                {
                    foreach (Agent a in agents)
                    {
                        state.Expression.Add(new ImpossibleBy(actt, new AgentsList()
                        {
                            a
                        }));
                    }
                }
                break;

            case "after":
                LogicElement observable = EntryC1(state);
                Token        aft        = state.PopToken();
                if (aft == null || aft.Name != "after")
                {
                    firstToken.ThrowException("Expected 'after' after logic expression.");
                }
                Instruction instr     = GetInstructions(state, aft);
                After       after_exp = new After(observable, instr);
                state.Expression.Add(after_exp);
                break;

            case "observable":
                LogicElement obs   = EntryC1(state);
                Token        after = state.PopToken();
                if (after == null || after.Name != "after")
                {
                    firstToken.ThrowException("Expected 'after' after logic expression.");
                }
                Instruction     inst     = GetInstructions(state, after);
                ObservableAfter obsAfter = new ObservableAfter(obs, inst);
                state.Expression.Add(obsAfter);
                break;
            }
        }
Пример #29
0
        public static Query ParseQuery(List <Token> tokenList, ParserState story)
        {
            ParserState state = new ParserState(tokenList);

            state.Action      = story.Action;
            state.Agent       = story.Agent;
            state.Noninertial = story.Noninertial;
            state.Fluent      = story.Fluent;
            if (tokenList.Count == 0)
            {
                throw new Exception("Empty query");
            }

            Token first = state.PopToken();

            if (first.Name == "necessary" || first.Name == "possibly")
            {
                Token t    = state.PopToken();
                Token next = state.PeepToken();
                if (t == null)
                {
                    first.ThrowException("Expected: executable, agents list or logic expression.");
                }
                if (t.Name == "executable") // necessary executable
                {
                    if (state.PeepToken() == null)
                    {
                        t.ThrowException("Expected program.");
                    }
                    Instruction inst = GetInstructions(state, t);
                    Token       from = state.PopToken();
                    if (from == null)
                    {
                        if (first.Name == "necessary")
                        {
                            return(new NecessaryExecutable(inst));
                        }
                        else
                        {
                            return(new PossiblyExecutable(inst));
                        }
                    }
                    if (from.Name != "from")
                    {
                        t.ThrowException("Expected from after program.");
                    }
                    LogicElement cond = EntryC1(state);
                    if (first.Name == "necessary")
                    {
                        return(new NecessaryExecutableFrom(inst, cond));
                    }
                    else
                    {
                        return(new PossiblyExecutableFrom(inst, cond));
                    }
                }
                else if (state.Agent.ContainsKey(next.Name)) // necessary engaged
                {
                    state.TokenList.Insert(0, t);
                    AgentsList agents  = GetAgentList(state);
                    Token      engaged = state.PopToken();
                    if (engaged == null || engaged.Name != "engaged")
                    {
                        t.ThrowException("Expected engaged after agents list.");
                    }
                    Token in_token = state.PopToken();
                    if (in_token == null || in_token.Name != "in")
                    {
                        t.ThrowException("Expected in after engaged.");
                    }
                    Instruction inst = GetInstructions(state, in_token);
                    Token       from = state.PopToken();
                    if (from == null)
                    {
                        if (first.Name == "necessary")
                        {
                            return(new NecessaryEngaged(agents, inst));
                        }
                        else
                        {
                            return(new PossiblyEngaged(agents, inst));
                        }
                    }
                    if (from.Name != "from")
                    {
                        t.ThrowException("Expected from after action list.");
                    }
                    LogicElement cond = EntryC1(state);
                    if (first.Name == "necessary")
                    {
                        return(new NecessaryEngagedFrom(agents, inst, cond));
                    }
                    else
                    {
                        return(new PossiblyEngagedFrom(agents, inst, cond));
                    }
                }
                else if (next != null && (state.Fluent.ContainsKey(next.Name) ||
                                          state.Noninertial.ContainsKey(next.Name) || next.Name == "(" || next.Name == "~")) // necessary value
                {
                    state.TokenList.Insert(0, t);
                    LogicElement result = EntryC1(state);
                    Token        after  = state.PopToken();
                    if (after == null || after.Name != "after")
                    {
                        t.ThrowException("Expected 'after' after result.");
                    }
                    Instruction inst = GetInstructions(state, t);
                    Token       from = state.PopToken();
                    if (from == null)
                    {
                        if (first.Name == "necessary")
                        {
                            return(new NecessaryAfter(inst, result));
                        }
                        else
                        {
                            return(new PossiblyAfter(inst, result));
                        }
                    }
                    if (from.Name != "from")
                    {
                        t.ThrowException("Expected from after program.");
                    }
                    LogicElement cond = EntryC1(state);
                    if (first.Name == "necessary")
                    {
                        return(new NecessaryAfterFrom(inst, result, cond));
                    }
                    else
                    {
                        return(new PossiblyAfterFrom(inst, result, cond));
                    }
                }
                else
                {
                    throw new Exception("Incorrect query.");
                }
            }
            else
            {
                first.ThrowException("Expected 'necessary' or 'possibly'.");
            }
            return(null);
        }
Пример #30
0
 public SrTriggerViewModel(LogicElement model, IApplicationGlobalCommands globalCommands) : base(model, globalCommands)
 {
     this.ElementName = "SR-триггер";
     this.Description = "Логический элемент SR-триггер";
     this.Symbol      = "SRT";
 }