public PrintMachineState GetNext(Token token)
        {
            PrintMachineState    nextState  = this.CurrentState;
            PrintStateTransition transition = new PrintStateTransition(CurrentState, token.Type);

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

            if (this.CurrentState == PrintMachineState.PRINT && token.Type != TokenType.END)
            {
                this.command.ConsumeToken(token);
            }

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

            return(nextState);
        }
        public PrintStateMachine(VariableTable variables, FileManager fileManager)
        {
            CurrentState = PrintMachineState.START;
            transitions  = new Dictionary <PrintStateTransition, PrintMachineState>
            {
                { new PrintStateTransition(PrintMachineState.START, TokenType.END), PrintMachineState.START },
                { new PrintStateTransition(PrintMachineState.START, TokenType.PRINT), PrintMachineState.PRINT },

                { new PrintStateTransition(PrintMachineState.PRINT, TokenType.STRING), PrintMachineState.PRINT_MULTIPLE },
                { new PrintStateTransition(PrintMachineState.PRINT, TokenType.QUOTED_STRING), PrintMachineState.PRINT_MULTIPLE },
                { new PrintStateTransition(PrintMachineState.PRINT, TokenType.VAR), PrintMachineState.PRINT_MULTIPLE },
                { new PrintStateTransition(PrintMachineState.PRINT, TokenType.INT), PrintMachineState.PRINT_MULTIPLE },
                { new PrintStateTransition(PrintMachineState.PRINT, TokenType.ARRAY), PrintMachineState.PRINT_MULTIPLE },
                { new PrintStateTransition(PrintMachineState.PRINT, TokenType.END), PrintMachineState.START },

                { new PrintStateTransition(PrintMachineState.PRINT_MULTIPLE, TokenType.COMMA), PrintMachineState.PRINT },
                { new PrintStateTransition(PrintMachineState.PRINT_MULTIPLE, TokenType.END), PrintMachineState.START },
            };
            this.variables = variables;
            this.command   = new PrintCommand(fileManager);
        }
 public PrintStateTransition(PrintMachineState currentState, TokenType token)
 {
     this.CurrentState = currentState;
     this.Token        = token;
 }
        public void MoveToNextState(Token token)
        {
            PrintMachineState nextState = GetNext(token);

            this.CurrentState = nextState;
        }