/// <summary> /// /// </summary> /// <param name="cont"></param> /// <param name="actuals"></param> /// <returns></returns> public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont, ArrayList actuals) { ArrayList vars = new ArrayList(); int i = 0; FRAME ft = new FRAME(); if (m_formals != null && actuals != null) { i = 0; foreach (SYMBOL_INFO b in m_formals) { SYMBOL_INFO inf = actuals[i] as SYMBOL_INFO; inf.SymbolName = b.SymbolName; cont.TABLE.Add(inf); i++; } } foreach (Stmt e1 in m_statements) { return_value = e1.Execute(cont); if (return_value != null) { return(return_value); } } return(null); }
public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont, ArrayList formals) { ArrayList vars = new ArrayList(); int i = 0; FRAME ft = new FRAME(); Console.Write("function " + m_name + "( "); if (m_formals != null) { i = 0; foreach (SYMBOL_INFO b in m_formals) { // SYMBOL_INFO inf = m_formals[i] as SYMBOL_INFO; // inf.SymbolName = b.SymbolName; if (i == m_formals.Count - 1) { Console.Write(b.SymbolName + ""); } else { Console.Write(b.SymbolName + ","); } // cont.TABLE.Add(inf); i++; } } Console.Write(" ) {\r\n"); /////////////////////// // // The flag given below detects whether there // is a return value at the top most level // (also called topmost block ) bool return_found = false; //////////////////////////// // Iterate through the statements list and // Generate Code.... // foreach (Stmt e1 in m_statements) { /////////////////////////// // // Found a return value , set the flag to // true. // if (e1 is ReturnStatement) { return_found = true; } e1.GenerateJS(cont); } if (return_found == false) { Console.Write("\r\n//---- Translator installed return\r\n "); if (this.TYPE == TYPE_INFO.TYPE_BOOL) { Console.Write("return false; \r\n"); } else if (this.TYPE == TYPE_INFO.TYPE_NUMERIC) { Console.Write("return 0;\r\n"); } else if (this.TYPE == TYPE_INFO.TYPE_STRING) { Console.Write("return \"\";\r\n"); } } Console.Write("\r\n } \r\n"); return(null); }