Example #1
0
        public static Machine GetFromOptions(SMOptions options)
        {
            Machine stateMachine;

            if (options.Transitions.Any(tr => tr.IsEpsilon) ||
                options.Transitions
                .GroupBy(tr => tr.StartState + tr.Token)
                .Any(gr => gr.Count() > 1))
            {
                stateMachine = new MachineNonDetermined();
            }
            else
            {
                stateMachine = new MachineDetermined();
            }

            var statesNames = options.GetStates();
            var statesDict  = new Dictionary <string, State>();

            foreach (var stateName in statesNames)
            {
                var state = new State(stateName, options.FinalStates.Contains(stateName));
                statesDict.Add(stateName, state);
                stateMachine.AddState(state);
            }

            foreach (var transitionOptions in options.Transitions)
            {
                if (transitionOptions.IsEpsilon)
                {
                    stateMachine.AddTransition(new Transition(
                                                   statesDict[transitionOptions.StartState],
                                                   statesDict[transitionOptions.EndState]
                                                   ));
                }

                else
                {
                    stateMachine.AddTransition(new Transition(
                                                   statesDict[transitionOptions.StartState],
                                                   transitionOptions.Token,
                                                   statesDict[transitionOptions.EndState]
                                                   ));
                }
            }

            stateMachine.Init(options.InitialState);

            return(stateMachine);
        }
        public override void Apply(CstDeclaration cstDeclaration)
        {
            var stateMachineArchOptions = new SMOptions();

            cstDeclaration.Identity.Visit(this);

            if (cstDeclaration.States != null)
            {
                stateMachineArchOptions.States = new List <string>();

                foreach (var state in cstDeclaration.States)
                {
                    state.Visit(this);
                    stateMachineArchOptions.States.Add((string)_buffer.Pop());
                }
            }


            stateMachineArchOptions.FinalStates = new List <string>();

            foreach (var final in cstDeclaration.Finals)
            {
                final.Visit(this);
                stateMachineArchOptions.FinalStates.Add((string)_buffer.Pop());
            }


            cstDeclaration.InitialStateName.Visit(this);
            stateMachineArchOptions.InitialState = (string)_buffer.Pop();


            stateMachineArchOptions.Transitions = new List <TransitionOptions>();

            foreach (var transition in cstDeclaration.Trancitions)
            {
                transition.Visit(this);
                stateMachineArchOptions.Transitions.Add((TransitionOptions)_buffer.Pop());
            }

            var identity = (string)_buffer.Pop();

            stateMachineArchOptions.MachineId = identity;

            _buffer.Push(stateMachineArchOptions);
        }
Example #3
0
 public SMController(SMOptions o) : base("Victor CLI", Ct)
 {
     if (_beeperThread == null)
     {
         EnableBeeper();
     }
     SayInfoLine("Victor Self-Management loading...");
     StartBeeper();
     Options = o;
     if (Options.Debug)
     {
         DebugEnabled = true;
         SayInfoLine("Debug enabled.");
     }
     Packages.Add(new SMHome(this));
     HomePackage     = Packages[0];
     ActivePackage   = Packages[0];
     PreviousPackage = Packages[0];
     JuliusSession   = new JuliusSession();
     Initialized     = Packages[0].Initialized;
     StopBeeper();
 }