public GoSubStateMachine(VariableTable variables, FileManager fileManager)
        {
            CurrentState = GoSubMachineState.START;
            transitions  = new Dictionary <GoSubStateTransition, GoSubMachineState>
            {
                { new GoSubStateTransition(GoSubMachineState.START, TokenType.END), GoSubMachineState.START },
                { new GoSubStateTransition(GoSubMachineState.START, TokenType.GOSUB), GoSubMachineState.GOSUB },

                { new GoSubStateTransition(GoSubMachineState.GOSUB, TokenType.INT), GoSubMachineState.LABEL },

                { new GoSubStateTransition(GoSubMachineState.LABEL, TokenType.END), GoSubMachineState.START }
            };

            this.variables = variables;
            this.command   = new GoSubCommand(variables, fileManager);
        }
        public GoSubMachineState GetNext(Token token)
        {
            GoSubMachineState    nextState  = this.CurrentState;
            GoSubStateTransition transition = new GoSubStateTransition(CurrentState, token.Type);

            if (!transitions.TryGetValue(transition, out nextState))
            {
                throw new Exception("GOSUB: Invalid transition: " + CurrentState + " -> " + nextState + "\n" + token.Text + " " + token.Type);
            }

            if (this.CurrentState == GoSubMachineState.GOSUB && token.Type == TokenType.INT)
            {
                this.command.ConsumeToken(token);
            }

            Console.WriteLine("GOSUB: " + this.CurrentState + " -> " + nextState + ": " + token.Text);

            return(nextState);
        }
 public GoSubStateTransition(GoSubMachineState currentState, TokenType token)
 {
     this.CurrentState = currentState;
     this.Token        = token;
 }
        public void MoveToNextState(Token token)
        {
            GoSubMachineState nextState = GetNext(token);

            this.CurrentState = nextState;
        }