Пример #1
0
        /// <summary>
        /// Populates the actions for each state and symbol combination.
        /// </summary>
        private void FillActions()
        {
            var acceptProduction = Grammar.Productions[0];

            foreach (var state in LrStates)
            {
                try
                {
                    var actions = new LrAction[state.Gotos.Count];

                    for (var sym = 0; sym < Grammar.Tokens.Length; sym++)
                    {
                        var possibleActions = new ActionSet();

                        var target = state.Gotos[sym];
                        if (target != null)
                        {
                            if (Terminals.Contains(sym))
                            {
                                possibleActions.Add(LrAction.Shift(target, state.GotoPrecedences[sym]));
                            }
                            if (NonTerminals.Contains(sym))
                            {
                                possibleActions.Add(LrAction.Goto(target, state.GotoPrecedences[sym]));
                            }
                        }
                        foreach (var item in state.Items)
                        {
                            if (item.LookAheadSymbol != sym)
                            {
                                continue;
                            }
                            if (item.CanIncrement == false)
                            {
                                if (item.Production == acceptProduction && item.ProductionProgress == 1)
                                {
                                    possibleActions.Add(LrAction.Accept());
                                }
                                else
                                {
                                    possibleActions.Add(LrAction.Reduce(item.Production, item.Production.Precedence));
                                }
                            }
                        }
                        SetAction(actions, sym, possibleActions);
                    }
                    state.Actions = actions;
                }
                catch (Exception ex)
                {
                    throw new Exception($"Error processing state: {state}", ex);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Populates the specified shell with sub-menus.
        /// </summary>
        /// <param name="shell">The shell.</param>
        public void Populate(
            ActionManager manager,
            MenuShell shell)
        {
            // Create a new submenu for ourselves.
            var menu = new Menu();

            var menuItem = new MenuItem(Label);

            menuItem.Submenu        = menu;
            menuItem.RightJustified = RightAligned;

            // If we have a group name, add it to the list.
            if (!String.IsNullOrEmpty(GroupName))
            {
                ActionSet group = manager.GetOrCreateGroup(GroupName);

                group.Add(menuItem);
            }

            // Attach our menu to the shell.
            shell.Append(menuItem);

            // Go through all of our elements and add them to our menu.
            foreach (ILayoutListItem item in this)
            {
                // Go through and populate the menu itself.
                item.Populate(manager, menu);
            }
        }
Пример #3
0
    private void GenerateNewAction()
    {
        Action action = GetRandomAction();

        if (action != null)
        {
            toDoList.Add(action);
            lastGenerationTime = 0;
            toDoListHasChanged.Raise();
            Debug.Log("Action " + action.name + " generated.");
        }
    }
Пример #4
0
 private void MarkActionAsFinished(Action action)
 {
     toDoActions.Remove(action);
     finishedActions.Add(action);
     toDoListHasChanged.Raise();
 }