public IfMachineState GetNext(Token token) { IfMachineState nextState = this.CurrentState; IfStateTransition transition = new IfStateTransition(CurrentState, token.Type); if ((this.CurrentState == IfMachineState.IF_FIRST_EXP && !this.IsComparator(token)) || (this.CurrentState == IfMachineState.COMPARISON && token.Type != TokenType.THEN)) { this.exp.MoveToNextState(token); } else if (!transitions.TryGetValue(transition, out nextState)) { throw new Exception("Invalid transition: " + CurrentState + " -> " + nextState + "\n" + token.Text + " " + token.Type); } if ((nextState == IfMachineState.COMPARISON && this.IsComparator(token)) || (nextState == IfMachineState.DESTINATION && token.Type == TokenType.THEN)) { this.exp.Reset(); if (nextState == IfMachineState.COMPARISON && this.IsComparator(token)) { this.comparison = token; this.command.MoveResultToSecondRegister(); } } else if (nextState == IfMachineState.START && token.Type != TokenType.END) { this.destination = int.Parse(token.Text); this.command.IfInstructions(this.destination, this.comparison); this.comparison = null; this.destination = 0; } Console.WriteLine("IF: " + this.CurrentState + " -> " + nextState + ": " + token.Text); return(nextState); }
public override bool Equals(object obj) { IfStateTransition other = obj as IfStateTransition; return(other != null && this.CurrentState == other.CurrentState && this.Token == other.Token); }