public static void converter(List <ThreeAddress> addressCodes) { Console.WriteLine(" ||\tOperator\t||\tArg1\t||\tArg2\t"); for (int i = 0; i < addressCodes.Count; i++) { ThreeAddress addressCode = addressCodes[i]; string arg1 = addressCode.Arg1; string arg2 = addressCode.Arg2; if ((arg1 != "") && (arg1[0] == 'T') && (arg1.Length > 1)) { int index = int.Parse(arg1[1].ToString()) - 1; arg1 = string.Format("({0})", index); } if ((arg2 != "") && (arg2[0] == 'T') && (arg2.Length > 1)) { int index = int.Parse(arg2[1].ToString()) - 1; arg2 = string.Format("({0})", index); } if (addressCode.Result == "Y") { arg1 = "Y"; } Console.WriteLine((i) + " ||\t\t{0}\t||\t{1}\t||\t{2}\t", addressCode.Op, arg1, arg2); } }
public static List <ThreeAddress> converter(List <string> postfix) { List <ThreeAddress> addressCodes = new List <ThreeAddress>(); int tempValues = 1; while (postfix.Count > 2) { for (int i = (postfix.Count - 1); i >= 1; i--) { if (!operators.Contains(postfix[i])) { continue; } if ((postfix[i] == "~") && (!operators.Contains(postfix[i - 1]))) { string result = "T" + tempValues; tempValues++; string arg2 = postfix[i - 1]; string op = postfix[i]; string arg1 = ""; ThreeAddress t1 = new ThreeAddress(result, arg1, op, arg2); addressCodes.Add(t1); postfix[i] = result; postfix.RemoveAt(i - 1); break; } else if ((!operators.Contains(postfix[i - 1])) && (!operators.Contains(postfix[i - 2]))) { string result = "T" + tempValues; tempValues++; string arg1 = postfix[i - 2]; string arg2 = postfix[i - 1]; string op = postfix[i]; ThreeAddress t1 = new ThreeAddress(result, arg1, op, arg2); addressCodes.Add(t1); postfix[i] = result; postfix.RemoveAt(i - 1); postfix.RemoveAt(i - 2); break; } } } ThreeAddress t2 = new ThreeAddress("Y", "", ":=", postfix[0]); addressCodes.Add(t2); return(addressCodes); }
public static void converter(List <ThreeAddress> addressCodes) { Console.WriteLine(" ||\tOperator\t||\tArg1\t||\tArg2\t||\tResult"); for (int i = 0; i < addressCodes.Count; i++) { ThreeAddress addressCode = addressCodes[i]; Console.WriteLine((i + 1) + " ||\t\t{0}\t||\t{1}\t||\t{2}\t||\t{3}", addressCode.Op, addressCode.Arg1, addressCode.Arg2, addressCode.Result); } }