Instruction AnalyseUnaryOperator(Tokenizer.Token[] tokens, int index, out int tokenCount) { InstructionUnaryOperator instructionUnaryOperator = new InstructionUnaryOperator(); tokenCount = 1; int tc = 0; instructionUnaryOperator.Path = AnalysePath(tokens, index + tokenCount, out tc); tokenCount += tc; if (tokens[index + tokenCount].TokenName == Tokenizer.TokenName.Increment) { instructionUnaryOperator.Type = InstructionUnaryOperator.OperatorType.Increment; instructionUnaryOperator.VariableName = tokens[index].Value; } if (tokens[index + 1].TokenName == Tokenizer.TokenName.Decrement) { instructionUnaryOperator.Type = InstructionUnaryOperator.OperatorType.Decrement; instructionUnaryOperator.VariableName = tokens[index].Value; } tokenCount += 2; return(instructionUnaryOperator); }
InstructionResult ExecuteInstructionUnaryOperator(Instruction instruction) { InstructionUnaryOperator instructionUnaryOperator = instruction as InstructionUnaryOperator; Variable variable = GetVariableByName(instructionUnaryOperator.VariableName); Value variableValue = GetVariableValue(variable); variableValue = ResolvePath(variableValue, instructionUnaryOperator.Path); switch (instructionUnaryOperator.Type) { case InstructionUnaryOperator.OperatorType.Increment: variableValue.NumericValue++; break; case InstructionUnaryOperator.OperatorType.Decrement: variableValue.NumericValue--; break; } return(new InstructionResult()); }