public LetMachineState GetNext(Token token) { LetMachineState nextState = this.CurrentState; LetStateTransition transition = new LetStateTransition(CurrentState, token.Type); if (this.CurrentState == LetMachineState.LET && (token.Type == TokenType.VAR || token.Type == TokenType.ARRAY_ELEMENT)) { this.variable = token; } if (!(this.CurrentState == LetMachineState.EQUALS && token.Type != TokenType.END) && !transitions.TryGetValue(transition, out nextState)) { throw new Exception("LET: Invalid transition: " + CurrentState + " -> " + nextState + "\n" + token.Text + " " + token.Type); } if (this.CurrentState == LetMachineState.EQUALS && token.Type == TokenType.END && nextState == LetMachineState.START) { this.exp.Reset(); this.variables.variableToIndex[this.variable.Text] = this.variables.variableCounter++; this.command.GenerateStoreInMemInstructions(this.variables.variableToIndex[this.variable.Text]); } else if (this.CurrentState == LetMachineState.EQUALS) { this.exp.MoveToNextState(token); } Console.WriteLine("LET: " + this.CurrentState + " -> " + nextState + ": " + token.Text); return(nextState); }
public override bool Equals(object obj) { LetStateTransition other = obj as LetStateTransition; return(other != null && this.CurrentState == other.CurrentState && this.Token == other.Token); }