public int getIntArrayElement(int index) { if (!this.type.Contains("Array")) { throw new ExecutorException("该元素并不是一个数组", line_num); } else { if (this.type.Contains("int")) { IntArrayValue array = (IntArrayValue)this; return(array.array_elements.Length); } else if (this.type.Contains("char")) { CharArrayValue array = (CharArrayValue)this; return(array.array_elements.Length); } else if (this.type.Contains("string")) { StringArrayValue array = (StringArrayValue)this; return(array.array_elements.Length); } else if (this.type.Contains("real")) { RealArrayValue array = (RealArrayValue)this; return(array.array_elements.Length); } else { throw new ExecutorException("究竟是何方妖孽?", line_num); } } }
internal static void write_value(Value v, int linenum) { if (v.type == "int") { IntValue value = (IntValue)v; MessageBox.Show(value.value.ToString()); } else if (v.type == "real") { RealValue value = (RealValue)v; MessageBox.Show(value.value.ToString()); } else if (v.type == "number") { NumberValue value = (NumberValue)v; MessageBox.Show(value.value.ToString()); } else if (v.type == "char") { CharValue value = (CharValue)v; MessageBox.Show(value.value); } else if (v.type == "string") { StringValue value = (StringValue)v; MessageBox.Show(value.value); } else if (v.type == "bool") { BoolValue value = (BoolValue)v; MessageBox.Show(value.value.ToString()); } else if (v.type == "intArray") { IntArrayValue value = (IntArrayValue)v; string text = ""; for (int i = 0; i < value.array_elements.Length; i++) { text += value.array_elements[i]; text += "|"; } MessageBox.Show(text); } else if (v.type == "realArray") { RealArrayValue value = (RealArrayValue)v; string text = ""; for (int i = 0; i < value.array_elements.Length; i++) { text += value.array_elements[i]; text += "|"; } MessageBox.Show(text); } else if (v.type == "charArray") { CharArrayValue value = (CharArrayValue)v; string text = ""; for (int i = 0; i < value.array_elements.Length; i++) { text += value.array_elements[i]; text += "|"; } MessageBox.Show(text); } else if (v.type == "stringArray") { StringArrayValue value = (StringArrayValue)v; string text = ""; for (int i = 0; i < value.array_elements.Length; i++) { text += value.array_elements[i]; text += "|"; } MessageBox.Show(text); } else { throw new ExecutorException("出现了没有考虑到的新类型", linenum); } }
public void changeValueOfArray(int index, string value) { if (!type.Contains("Array")) { throw new ExecutorException("该变量并不是数组!"); } else { if (type.Contains("int")) { IntArrayValue array = (IntArrayValue)this; if (array.array_elements.Length <= index) { throw new ExecutorException("数组访问越界", line_num); } else { try { array.array_elements[index] = int.Parse(value); } catch (Exception ee) { throw new ExecutorException("该类型的值无法为int类型赋值", line_num); } } } else if (type.Contains("real")) { RealArrayValue array = (RealArrayValue)this; if (array.array_elements.Length <= index) { throw new ExecutorException("数组访问越界", line_num); } else { try { array.array_elements[index] = double.Parse(value); } catch (Exception ee) { throw new ExecutorException("该类型的值无法为real类型赋值", line_num); } } } else if (type.Contains("char")) { CharArrayValue array = (CharArrayValue)this; if (array.array_elements.Length <= index) { throw new ExecutorException("数组访问越界", line_num); } else { if (value.Length > 1 && !value.Contains("\\")) { throw new ExecutorException("值" + value + "与类型" + type + "不符合", line_num); } else { array.array_elements[index] = value; } } } else if (type.Contains("string")) { StringArrayValue array = (StringArrayValue)this; if (array.array_elements.Length <= index) { throw new ExecutorException("数组访问越界", line_num); } else { array.array_elements[index] = value; } } } }