bool CheckAllDataType() { token4check xxx = (token4check)MatchDataType[0]; for (int i = 1; i < MatchDataType.Count; i++) { token4check yyy = (token4check)MatchDataType[i]; if (xxx.type == yyy.type) { xxx.type = yyy.type; } else if (xxx.type == "ANY" || yyy.type == "ANY") { xxx.type = yyy.type; } else { Console.Error.WriteLine("Variable not match"); return(false); } } string asd = ""; foreach (token4check a in MatchDataType) { if (a.type != "ANY") { asd = a.type; } } Variable yay = new Variable(); foreach (token4check a in MatchDataType) { if (a.type == "ANY") { int ppp = 999; bool qqq = false; int ooo = 0; foreach (Variable b in GlobalArray) { ooo++; if (a.word == b.token.word) { yay.token.word = b.token.word; yay.token.clss = b.token.clss; yay.type = asd; ppp = ooo; qqq = true; } } if (qqq) { GlobalArray.Insert(ppp, yay); GlobalArray.RemoveAt(ppp - 1); } ppp = 999; qqq = false; ooo = 0; foreach (Variable c in LocalArray) { ooo++; if (now.word == c.token.word) { yay.token.word = c.token.word; yay.token.clss = c.token.clss; yay.type = asd; LocalArray.Insert(ooo, yay); ppp = ooo; qqq = true; } } if (qqq) { LocalArray.Insert(ppp, yay); LocalArray.RemoveAt(ppp - 1); } } } MatchDataType = new ArrayList(); return(true); }
token4check CheckDataType(token now) { token4check qwer = new token4check(); if (now.clss == "INT_CONST") { qwer.word = now.word; qwer.type = "INT"; return(qwer); } if (now.clss == "FLOAT_CONST") { qwer.word = now.word; qwer.type = "FLOAT"; return(qwer); } if (now.clss == "STRING_CONST") { qwer.word = now.word; qwer.type = "FLOAT"; return(qwer); } if (now.clss == "ID") { if (checkStruct() == true) { foreach (Variable a in StructArray) { if (this.now.word == a.token.word) { qwer.word = now.word; qwer.type = a.type; return(qwer); } } return(qwer); } else { foreach (Variable b in GlobalArray) { if (now.word == b.token.word) { qwer.word = now.word; qwer.type = b.type; return(qwer); } } } foreach (Variable c in LocalArray) { if (now.word == c.token.word) { qwer.word = now.word; qwer.type = c.type; return(qwer); } } Console.Error.WriteLine("Variable not Declare : {0}", now.word); return(qwer); } Console.Error.WriteLine("Variable not Declare : {0}", now.word); return(qwer); }