/// <summary> /// Inserts a procedure with all necessary information /// </summary> private void insertProcedure() { token = getNextToken(); // proc token = getNextToken(); // proc name SymTab.entry ptr = st.lookUp(token.Trim(' ')); emit(token + "\t PROC"); emit("\tpush bp "); //push bp mov("bp", "sp"); // mov bp, sp SymTab.entry.function fptr = ptr as SymTab.entry.function; emit("\tsub sp, " + fptr.sizeOfLocal.ToString()); // sub sp, size of locals from symtab //TRANSLATED CODE emit(""); if (token != "endp") { token = getNextToken(); // get L } transCode(); //Last part of template emit("\tadd sp, " + fptr.sizeOfLocal.ToString()); emit("\tpop bp"); emit("\tret " + fptr.sizeOfParams); token = getNextToken(); // proc name emit(token + "\t endp"); }
/// <summary> /// Writes the contents of the table. Skips empty lists /// </summary> /// public void writeTable(int depth) { if (rdp.error == true) { return; } string output = ""; //string vOutput = String.Format("| {0,-10} {1,-10} {2, -10} {3, -5} {4, -20} {5, -20} \t\t\t |", "Entrytype ", "Token", "Type", "Depth", "Size", "Offset"); string fOutput = String.Format("| {0,-10} {1,-10} {2, -10} {3, -15} {4, -20} {5, -26} |", "Token", "Lexeme", "Depth", "Number of parameters", "Size of Locals", "Size of parameters"); // Console.WriteLine("Following symbols are at depth " + depth); Console.WriteLine("|---------------------------------------------------------------------------------------------------------|"); Console.WriteLine("|-------------------------------" + " Depth: " + depth + " ----------------------------------------------------------------|"); Console.WriteLine("|---------------------------------------------------------------------------------------------------------|"); int t = 0; for (int i = 0; i < hashTable.Length; i++) { /* * if(t>4) * { * Console.WriteLine("Press any key to continue..."); * Console.ReadKey(); * t = 0; * }*/ try { entry temp = hashTable[i].ElementAt(0); while (temp.Next != null) { if (temp.Next.depth == depth) { // t++; switch (temp.Next.typeOfEntry) { case (SymTab.entryType.functionEntry): SymTab.entry.function t1 = temp.Next as SymTab.entry.function; Console.WriteLine("| Procedure: \t\t\t\t\t\t\t\t\t\t\t\t\t |"); output = string.Format("| {0,-10} {1,-10} {2, -10} {3, -20} {4, -20} {5, -26} |", t1.token, t1.lexeme, t1.depth, t1.numberOfParams, t1.sizeOfLocal, t1.sizeOfParams); Console.WriteLine(fOutput); Console.WriteLine(output); Console.Write("| Parameters: "); if (t1.numberOfParams > 0) { for (int j = 1; j <= t1.paramList.Count; j++) { Console.Write(t1.paramList.ElementAt(j - 1).mode + " " + t1.paramList.ElementAt(j - 1).typeVar + " "); } } // Console.Write(t1.paramList.ElementAt(j-1)+ " " ); else { Console.WriteLine(" none"); } Console.WriteLine(); break; case (SymTab.entryType.constEntry): Console.WriteLine(); SymTab.entry.constant t2 = temp.Next as SymTab.entry.constant; switch (t2.typeOfConstant) { case (SymTab.varType.floatType): SymTab.entry.constant.floatConstant f1 = temp.Next as SymTab.entry.constant.floatConstant; Console.WriteLine("Constant: " + f1.lexeme + " With the following data: "); Console.WriteLine("Token: " + f1.token); Console.WriteLine("Type: " + f1.typeOfConstant); Console.WriteLine("Depth: " + f1.depth); Console.WriteLine("Size: " + f1.size); Console.WriteLine("Offset: " + f1.offset); break; case (SymTab.varType.intType): SymTab.entry.constant.intConstant i1 = temp.Next as SymTab.entry.constant.intConstant; Console.WriteLine("Constant: " + i1.lexeme + " With the following data: "); Console.WriteLine("Token: " + i1.token); Console.WriteLine("Type: " + i1.typeOfConstant); Console.WriteLine("Depth: " + i1.depth); Console.WriteLine("Size: " + i1.size); Console.WriteLine("Offset: " + i1.offset); break; } Console.WriteLine(); break; case (SymTab.entryType.varEntry): SymTab.entry.var t3 = temp.Next as SymTab.entry.var; Console.WriteLine(); Console.WriteLine("Variable: " + t3.lexeme + " With the following data: "); Console.WriteLine("Token: " + t3.token); Console.WriteLine("Type: " + t3.typeOfVar); Console.WriteLine("Depth: " + t3.depth); Console.WriteLine("Size: " + t3.size); Console.WriteLine("Offset: " + t3.offset); Console.WriteLine(); break; } } //Console.WriteLine(temp.Next.lexeme); //Console.WriteLine(temp.Next.typeOfEntry); if (temp.Next != null) { temp = temp.Next; } } } catch (NullReferenceException) { //Console.WriteLine("NULL REFERENCE!"); //Empty entry } } }