//修改result对应的所在表的value值,为change public void retSetValue(string result, string change) { string a = getValue(result); switch (ARG) { case "VARG": int indexID = VarList.IndexOf(IN_1); VarTable BStmp = (VarTable)VarTableList[indexID]; BStmp.Value = change; break; case "TARG": int indexTempID = TempVarList.IndexOf(IN_1); TempVarTable LStmp = (TempVarTable)TempVarTableList[indexTempID]; LStmp.Value = change; break; case "SARG": if (!Regex.IsMatch(IN_2, pattern)) //如果数组下标为常数 { int indexBS1 = VarList.IndexOf(IN_2); VarTable BStmp1 = (VarTable)VarTableList[indexBS1]; IN_2 = BStmp1.Value; } int indexSZ = ArrayList.IndexOf(IN_1); ArrayTable SZtmp = (ArrayTable)ArrayTableList[indexSZ]; SZtmp.element[Convert.ToInt32(IN_2)] = change; break; default: break; } }
//返回result对应的所在表的value值 public string getValue(string result) { IN_1 = find_Table_Kind(result); switch (ARG) { case "VARG": //标识符 int indexID = VarList.IndexOf(IN_1); VarTable BStmp = (VarTable)VarTableList[indexID]; return(BStmp.Value); case "TARG": //临时变量 int indexTempID = TempVarList.IndexOf(IN_1); TempVarTable LStmp = (TempVarTable)TempVarTableList[indexTempID]; return(LStmp.Value); case "SARG": //数组 try //如果数组出界,返回一个空值null { if (!Regex.IsMatch(IN_2, pattern)) //如果数组下标为常数 { int indexBS1 = VarList.IndexOf(IN_2); VarTable BStmp1 = (VarTable)VarTableList[indexBS1]; IN_2 = BStmp1.Value; //得到数组下标的值 } int indexSZ = ArrayList.IndexOf(IN_1); ArrayTable SZtmp = (ArrayTable)ArrayTableList[indexSZ]; if (Convert.ToInt32(IN_2) > Convert.ToInt32(SZtmp.Length) - 1) { return("OutSide"); //数组越界 } return(Convert.ToString(SZtmp.element[Convert.ToInt32(IN_2)])); } catch (ArgumentNullException) { return(null); //如果返回的为空值 } default: return(ARG); //如果为常数,得到常数的值 } }
//返回result在对应的符号表中的类型 public string getType(string result) { IN_1 = find_Table_Kind(result); switch (ARG) { case "VARG": //标识符 int indexID = VarList.IndexOf(IN_1); VarTable BStmp = (VarTable)VarTableList[indexID]; return(BStmp.Type); case "TARG": //临时变量 int indexTempID = TempVarList.IndexOf(IN_1); TempVarTable LStmp = (TempVarTable)TempVarTableList[indexTempID]; return(LStmp.Type); case "SARG": //数组 int indexSZ = ArrayList.IndexOf(IN_1); ArrayTable SZtmp = (ArrayTable)ArrayTableList[indexSZ]; return(SZtmp.Type); default: return("real"); //理论上是不会运行到这里的,因为只在read的方法中才会使用,而read后面不会连接常数 } }