/// <summary> /// 判断临时变量表中的成员是不是real类型(如果是real,返回true) /// </summary> /// <returns>返回判断结果</returns> private bool isReal() { try { TempIDtable LStmp = (TempIDtable)TempIDtablelist[0]; if (LStmp.Type != "real") { return(false); } } catch { try { TempSZtable LZtmp = (TempSZtable)LZtablelist[0]; if (LZtmp.Type != "real") { return(false); } } catch { return(true); } } return(true); }
/// <summary> /// 给变量赋值的时候,将其在变量表中的valued改为true /// </summary> private bool toValueSM(int n) { string next = getToken(ref n); try { int index = IDlist.IndexOf(next); IDtable tmpBS = (IDtable)IDtablelist[index]; tmpBS.Valued = true; return(true); } catch { try { int index = TempIDlist.IndexOf(next); TempIDtable tmpLS = (TempIDtable)TempIDtablelist[index]; tmpLS.Valued = true; return(true); } catch { return(false); } } }
/// <summary> /// 此方法修改result对应的所在表的value值,为change /// </summary> /// <param name="result">需要重新赋值的对象</param> /// <param name="change">所赋的值</param> public void retSetValue(string result, string change) { string a = getValue(result); switch (ARG) { case "VARG": int indexID = IDlist.IndexOf(IN_1); IDtable BStmp = (IDtable)IDtablelist[indexID]; BStmp.Value = change; break; case "TARG": int indexTempID = TempIDlist.IndexOf(IN_1); TempIDtable LStmp = (TempIDtable)TempIDtablelist[indexTempID]; LStmp.Value = change; break; case "SARG": if (!Regex.IsMatch(IN_2, pattern)) //如果数组下标为常数 { int indexBS1 = IDlist.IndexOf(IN_2); IDtable BStmp1 = (IDtable)IDtablelist[indexBS1]; IN_2 = BStmp1.Value; } int indexSZ = SZlist.IndexOf(IN_1); SZtable SZtmp = (SZtable)SZtablelist[indexSZ]; SZtmp.element[Convert.ToInt32(IN_2)] = change; break; default: break; } }
/// <summary> /// 把临时变量表中的成员加入到IDtable中 /// </summary> private void toBS() { IDlist.Add(TempIDlist[0]); TempIDtable LStmp = (TempIDtable)TempIDtablelist[0]; IDtablelist.Add(new IDtable(LStmp.Name, LStmp.Type, LStmp.Level, LStmp.Valued)); clsLS(); }
/// <summary> /// 此方法返回result对应的所在表的value值 /// </summary> /// <param name="sth">需要返回值的对象</param> /// <returns></returns> public string getValue(string result) { IN_1 = find_Table_Kind(result); switch (ARG) { case "VARG": //标识符 int indexID = IDlist.IndexOf(IN_1); IDtable BStmp = (IDtable)IDtablelist[indexID]; return(BStmp.Value); case "TARG": //临时变量 int indexTempID = TempIDlist.IndexOf(IN_1); TempIDtable LStmp = (TempIDtable)TempIDtablelist[indexTempID]; return(LStmp.Value); case "SARG": //数组 try //如果数组出界,返回一个空值null { if (!Regex.IsMatch(IN_2, pattern)) //如果数组下标为常数 { int indexBS1 = IDlist.IndexOf(IN_2); IDtable BStmp1 = (IDtable)IDtablelist[indexBS1]; IN_2 = BStmp1.Value; //得到数组下标的值 } int indexSZ = SZlist.IndexOf(IN_1); SZtable SZtmp = (SZtable)SZtablelist[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); //如果为常数,得到常数的值 } }
/// <summary> /// 判断是不是条件expression comparison-op expression /// </summary> /// <returns>返回判断结果</returns> private bool isCondition() { if (isExpression()) { n = n - 2; next = getToken(ref n); toLS(next, n); try { TempIDtable LStmp = (TempIDtable)TempIDtablelist[0]; LStmp.Type = "real"; } catch { SZtable SZtmp = (SZtable)SZtablelist[0]; SZtmp.Type = "real"; } next = getToken(ref n); switch (next) { case "<>": case "==": case "<": next = getToken(ref n); break; } if (isExpression()) { clsLS(); return(true); } } errAdd("错误代码: 判断条件有错误", getLine(n - 1)); return(false); }
/// <summary> /// 此方法返回result在对应的符号表中的类型 /// </summary> /// <param name="result">需要返回类型的对象</param> /// <returns></returns> public string getType(string result) { IN_1 = find_Table_Kind(result); switch (ARG) { case "VARG": //标识符 int indexID = IDlist.IndexOf(IN_1); IDtable BStmp = (IDtable)IDtablelist[indexID]; return(BStmp.Type); case "TARG": //临时变量 int indexTempID = TempIDlist.IndexOf(IN_1); TempIDtable LStmp = (TempIDtable)TempIDtablelist[indexTempID]; return(LStmp.Type); case "SARG": //数组 int indexSZ = SZlist.IndexOf(IN_1); SZtable SZtmp = (SZtable)SZtablelist[indexSZ]; return(SZtmp.Type); default: return("real"); //理论上是不会运行到这里的,因为只在read的方法中才会使用,而read后面不会连接常数 } }
/// <summary> /// 等号两边的变量类型是否相同(相同为true)(等号左边为real时,肯定为true) /// </summary> /// <param name="next">要判断的变量</param> /// <param name="n">变量所在位置</param> /// <returns>返回判断结果</returns> private bool isType(int n) { if (TempIDlist.Count == 0 && LZlist.Count == 0) { return(true); } try //变量——变量 { TempIDtable LStmp = (TempIDtable)TempIDtablelist[0]; int indexID = IDlist.IndexOf(getToken(ref n)); IDtable BStmp = (IDtable)IDtablelist[indexID]; if (LStmp.Type == BStmp.Type) { return(true); } else if (LStmp.Type == "real") { return(true); } } catch { try //数组——数组 { n--; TempSZtable LZtmp = (TempSZtable)LZtablelist[0]; int indexSZ = SZlist.IndexOf(getToken(ref n)); SZtable SZtmp = (SZtable)SZtablelist[indexSZ]; if (LZtmp.Type == SZtmp.Type) { return(true); } else if (LZtmp.Type == "real") { return(true); } } catch { try //变量——数组 { n--; TempIDtable LStmp = (TempIDtable)TempIDtablelist[0]; int indexSZ = SZlist.IndexOf(getToken(ref n)); SZtable SZtmp = (SZtable)SZtablelist[indexSZ]; if (LStmp.Type == SZtmp.Type) { return(true); } else if (LStmp.Type == "real") { return(true); } } catch { try //数组——变量 { n++; TempSZtable LZtmp = (TempSZtable)LZtablelist[0]; int indexID = IDlist.IndexOf(getToken(ref n)); IDtable BStmp = (IDtable)IDtablelist[indexID]; if (LZtmp.Type == BStmp.Type) { return(true); } else if (LZtmp.Type == "real") { return(true); } } catch { } } } } return(false); }
/// <summary> /// 给变量赋值的时候,将其在变量表中的valued改为true /// </summary> private void toValue() { TempIDtable LStmp = (TempIDtable)TempIDtablelist[0]; LStmp.Valued = true; }