private ReturnValue print(ReturnValue[] parameters) { ReturnValue parameter0 = parameters[0]; m_output.Add(parameter0.ToString()); return(new ReturnValue()); // void }
private ReturnValue AddStuffTogetherHack() { ReturnValue rhs = PopValue(); ReturnValue lhs = PopValue(); if (rhs.getReturnValueType() == ReturnValueType.NUMBER && lhs.getReturnValueType() == ReturnValueType.NUMBER) { return(new ReturnValue(rhs.NumberValue + lhs.NumberValue)); } else if (rhs.getReturnValueType() != ReturnValueType.STRING && lhs.getReturnValueType() != ReturnValueType.STRING) { SortedDictionary <int, ReturnValue> newArray = new SortedDictionary <int, ReturnValue>(); //int totalLength = lhs.ArrayValue.Count + rhs.ArrayValue.Count; //ReturnValue[] array = new ReturnValue[totalLength]; for (int i = 0; i < lhs.ArrayValue.Count; i++) { newArray.Add(i, lhs.ArrayValue[i]); } for (int i = 0; i < rhs.ArrayValue.Count; i++) { newArray.Add(i + lhs.ArrayValue.Count, rhs.ArrayValue[i]); } return(new ReturnValue(newArray)); } else { return(new ReturnValue(lhs.ToString() + rhs.ToString())); } }
private ReturnValue equalityTest() { ReturnValue rhs = PopValue(); ReturnValue lhs = PopValue(); if (rhs.getReturnValueType() == ReturnValueType.NUMBER && lhs.getReturnValueType() == ReturnValueType.NUMBER) { return(new ReturnValue(lhs.NumberValue == rhs.NumberValue)); } if (rhs.getReturnValueType() == ReturnValueType.BOOL && lhs.getReturnValueType() == ReturnValueType.BOOL) { return(new ReturnValue(lhs.BoolValue == rhs.BoolValue)); } if (rhs.getReturnValueType() == ReturnValueType.STRING && lhs.getReturnValueType() == ReturnValueType.STRING) { return(new ReturnValue(lhs.StringValue.ToLower() == rhs.StringValue.ToLower())); } throw new Error("Can't compare those two things (" + lhs.ToString() + " of type " + lhs.getReturnValueType() + " and " + rhs.ToString() + " of type " + rhs.getReturnValueType() + ")"); }
private AST CreateAssignmentTreeFromInitValue(string pVariableName, ReturnValue pInitValue) { Token.TokenType tokenType; switch (pInitValue.getReturnValueType()) { case ReturnValueType.BOOL: tokenType = Token.TokenType.BOOLEAN_VALUE; break; case ReturnValueType.STRING: tokenType = Token.TokenType.QUOTED_STRING; break; case ReturnValueType.NUMBER: tokenType = Token.TokenType.NUMBER; break; case ReturnValueType.ARRAY: tokenType = Token.TokenType.ARRAY; break; case ReturnValueType.VOID: throw new Error("Can't assign void to variable"); default: throw new Exception("Forgot to implement support for a type?"); } Token initValueToken = new TokenWithValue(tokenType, pInitValue.ToString(), pInitValue); AST assignmentTree = new AST_Assignment(new Token(Token.TokenType.ASSIGNMENT, "="), pVariableName); assignmentTree.addChild(initValueToken); return(assignmentTree); }
private ReturnValue ConvertToType(ReturnValue valueToConvert, ReturnValueType type) { #if WRITE_CONVERT_INFO Console.WriteLine("Converting from " + valueToConvert.getReturnValueType() + " (" + valueToConvert.ToString() + ")" + " to " + type); #endif ReturnValue result = null; if (type == ReturnValueType.VOID) { throw new Error("Can't convert to void."); } else if (type == ReturnValueType.UNKNOWN_TYPE) { // Don't convert but make a new copy with the same type type = valueToConvert.getReturnValueType(); } if (type == ReturnValueType.ARRAY) { result = new ReturnValue(valueToConvert.ArrayValue); } else if (type == ReturnValueType.BOOL) { result = new ReturnValue(valueToConvert.BoolValue); } else if (type == ReturnValueType.NUMBER) { result = new ReturnValue(valueToConvert.NumberValue); } else if (type == ReturnValueType.STRING) { result = new ReturnValue(valueToConvert.StringValue); } else { throw new Exception("Can't happen!"); } #if WRITE_CONVERT_INFO Console.WriteLine("Result: " + result.ToString()); #endif return(result); }
private AST CreateAssignmentTreeFromInitValue(string pVariableName, ReturnValue pInitValue) { Token.TokenType tokenType; switch(pInitValue.getReturnValueType()) { case ReturnValueType.BOOL: tokenType = Token.TokenType.BOOLEAN_VALUE; break; case ReturnValueType.STRING: tokenType = Token.TokenType.QUOTED_STRING; break; case ReturnValueType.NUMBER: tokenType = Token.TokenType.NUMBER; break; case ReturnValueType.ARRAY: tokenType = Token.TokenType.ARRAY; break; case ReturnValueType.VOID: throw new Error("Can't assign void to variable"); default: throw new Exception("Forgot to implement support for a type?"); } Token initValueToken = new TokenWithValue(tokenType, pInitValue.ToString(), pInitValue); AST assignmentTree = new AST_Assignment(new Token(Token.TokenType.ASSIGNMENT, "="), pVariableName); assignmentTree.addChild(initValueToken); return assignmentTree; }