Beispiel #1
0
        public DefStateMachine(FileManager fileManager)
        {
            CurrentState = DefMachineState.START;
            transitions  = new Dictionary <DefStateTransition, DefMachineState>
            {
                { new DefStateTransition(DefMachineState.START, TokenType.END), DefMachineState.START }
            };

            this.command = new DefCommand(fileManager);
        }
Beispiel #2
0
        public DefMachineState GetNext(Token token)
        {
            DefMachineState    nextState  = this.CurrentState;
            DefStateTransition transition = new DefStateTransition(CurrentState, token.Type);

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

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

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

            return(nextState);
        }
Beispiel #3
0
 public DefStateTransition(DefMachineState currentState, TokenType token)
 {
     this.CurrentState = currentState;
     this.Token        = token;
 }
Beispiel #4
0
        public void MoveToNextState(Token token)
        {
            DefMachineState nextState = GetNext(token);

            this.CurrentState = nextState;
        }