public ForMachineState GetNext(Token token) { ForMachineState nextState = this.CurrentState; ForStateTransition transition = new ForStateTransition(CurrentState, token.Type); if (this.CurrentState == ForMachineState.EQUALS && token.Type == TokenType.TO) { this.exp.Reset(); //valor inicial a ser atribuido na variavel esta em r0 this.command.ReceivedLoopedVariable(this.loopedVariable); } else if (this.CurrentState == ForMachineState.TO && token.Type == TokenType.STEP) { this.exp.Reset(); //valor maximo para parada do loop esta em r0 this.command.SaveMaxValueForLoop(this.loopedVariable); } else if (this.CurrentState == ForMachineState.STEP && token.Type == TokenType.END) { this.exp.Reset(); //valor de passo do loop esta em r0 this.command.SaveStepValueForLoop(this.loopedVariable); } if ((this.CurrentState == ForMachineState.EQUALS && token.Type != TokenType.TO) || (this.CurrentState == ForMachineState.TO && token.Type != TokenType.STEP) || (this.CurrentState == ForMachineState.STEP && token.Type != TokenType.END)) { this.exp.MoveToNextState(token); } else if (!transitions.TryGetValue(transition, out nextState)) { throw new Exception("For: Invalid transition: " + CurrentState + " -> " + nextState + "\n" + token.Text + " " + token.Type); } if (this.CurrentState == ForMachineState.FOR && (token.Type == TokenType.VAR || token.Type == TokenType.ARRAY)) { this.loopedVariable = token; } Console.WriteLine("FOR: " + this.CurrentState + " -> " + nextState + ": " + token.Text); return(nextState); }
public override bool Equals(object obj) { ForStateTransition other = obj as ForStateTransition; return(other != null && this.CurrentState == other.CurrentState && this.Token == other.Token); }