public SyntaxMachineState GetNext(Token token) { SyntaxMachineState nextState = this.CurrentState; SyntaxStateTransition transition = new SyntaxStateTransition(CurrentState, token.Type); if ((this.CurrentState == SyntaxMachineState.START || this.CurrentState != SyntaxMachineState.START && token.Type == TokenType.END) && !transitions.TryGetValue(transition, out nextState)) { throw new Exception("Syntax: Invalid transition: " + CurrentState + " -> " + nextState + "\nToken Text: " + token.Text + " Token Type: " + token.Type.ToString()); } if (this.CurrentState == SyntaxMachineState.START && token.Type == TokenType.INT) { this.sequenceId.ConsumeToken(token); } else if (this.CurrentState == SyntaxMachineState.START && token.Type == TokenType.FINAL) { this.endCommand.EndInstruction(); } else if (this.CurrentState == SyntaxMachineState.START && token.Type == TokenType.RETURN) { this.returnCommand.ReturnInstructions(); } else { this.engine.ConsumeToken(this.CurrentState, token, nextState); } Console.WriteLine("Syntax: " + this.CurrentState + " -> " + nextState + ": " + token.Text); return(nextState); }
public override bool Equals(object obj) { SyntaxStateTransition other = obj as SyntaxStateTransition; return(other != null && this.CurrentState == other.CurrentState && this.Token == other.Token); }