public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont) { SYMBOL_INFO val = exp1.Evaluate(cont); cont.TABLE.Assign(variable, val); return(null); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="cont"></param> /// <returns></returns> public override SYMBOL_INFO Evaluate(RUNTIME_CONTEXT cont) { SYMBOL_INFO eval_left = ex1.Evaluate(cont); SYMBOL_INFO eval_right = ex2.Evaluate(cont); if (eval_left.Type == TYPE_INFO.TYPE_BOOL && eval_right.Type == TYPE_INFO.TYPE_BOOL) { SYMBOL_INFO ret_val = new SYMBOL_INFO(); ret_val.Type = TYPE_INFO.TYPE_BOOL; ret_val.SymbolName = ""; if (m_op == TOKEN.TOK_AND) { ret_val.bol_val = (eval_left.bol_val && eval_right.bol_val); } else if (m_op == TOKEN.TOK_OR) { ret_val.bol_val = (eval_left.bol_val || eval_right.bol_val); } else { return(null); } return(ret_val); } return(null); }
public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont) { Console.Write("console.log("); exp1.GenerateJS(cont); Console.Write(");\r\n"); return(null); }
/// <summary> /// Here we are calling Console.WriteLine to emit /// an additional new line . /// </summary> /// <param name="con"></param> /// <returns></returns> public override bool Execute(RUNTIME_CONTEXT con) { double a = _ex.Evaluate(con); Console.WriteLine(a.ToString()); return(true); }
/// <summary> /// /// </summary> /// <param name="cont"></param> /// <returns></returns> public override SYMBOL_INFO Evaluate(RUNTIME_CONTEXT cont) { SYMBOL_INFO eval_left = exp1.Evaluate(cont); SYMBOL_INFO eval_right = exp2.Evaluate(cont); if (eval_left.Type == TYPE_INFO.TYPE_STRING && eval_right.Type == TYPE_INFO.TYPE_STRING) { SYMBOL_INFO ret_val = new SYMBOL_INFO(); ret_val.str_val = eval_left.str_val + eval_right.str_val; ret_val.Type = TYPE_INFO.TYPE_STRING; ret_val.SymbolName = ""; return(ret_val); } else if (eval_left.Type == TYPE_INFO.TYPE_NUMERIC && eval_right.Type == TYPE_INFO.TYPE_NUMERIC) { SYMBOL_INFO ret_val = new SYMBOL_INFO(); ret_val.dbl_val = eval_left.dbl_val + eval_right.dbl_val; ret_val.Type = TYPE_INFO.TYPE_NUMERIC; ret_val.SymbolName = ""; return(ret_val); } else { throw new Exception("Type mismatch"); } }
/// <summary> /// /// </summary> /// <param name="cont"></param> /// <returns></returns> public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont) { Test: SYMBOL_INFO m_cond = cond.Evaluate(cont); if (m_cond == null || m_cond.Type != TYPE_INFO.TYPE_BOOL) { return(null); } if (m_cond.bol_val != true) { return(null); } SYMBOL_INFO tsp = null; foreach (Stmt rst in stmnts) { tsp = rst.Execute(cont); if (tsp != null) { return(tsp); } } goto Test; }
public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont) { SYMBOL_INFO val = exp1.Evaluate(cont); Console.WriteLine((val.Type == TYPE_INFO.TYPE_NUMERIC) ? val.dbl_val.ToString() : (val.Type == TYPE_INFO.TYPE_STRING) ? val.str_val : val.bol_val ? "TRUE" : "FALSE"); return(null); }
public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont) { foreach (Stmt stmt in m_statements) { stmt.Execute(cont); } return(null); }
public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont) { Console.Write("\treturn "); m_e1.GenerateJS(cont); Console.Write(";\r\n"); return(null); }
public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont, ArrayList actuals) { Procedure p = Find("Main"); if (p != null) { return(p.Execute(cont, actuals)); } return(null); }
/// <summary> /// To Evaluate a variable , we just need to do a lookup /// in the Symbol table ( of RUNTIME_CONTEXT ) /// </summary> /// <param name="st"></param> /// <param name="glb"></param> /// <returns></returns> public override SYMBOL_INFO Evaluate(RUNTIME_CONTEXT cont) { if (cont.TABLE == null) { return(null); } else { SYMBOL_INFO a = cont.TABLE.Get(m_name); return(a); } }
/// <summary> /// While evaluating a numeric constant , return the _value /// </summary> /// <param name="cont"></param> /// <returns></returns> public override double Evaluate(RUNTIME_CONTEXT cont) { switch (_op) { case OPERATOR.PLUS: return(_ex1.Evaluate(cont)); case OPERATOR.MINUS: return(-_ex1.Evaluate(cont)); } return(Double.NaN); }
/// <summary> /// Interpret the if statement /// </summary> /// <param name="cont"></param> /// <returns></returns> public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont) { // // Evaluate the Condition // SYMBOL_INFO m_cond = cond.Evaluate(cont); // // if cond is not boolean..or evaluation failed // if (m_cond == null || m_cond.Type != TYPE_INFO.TYPE_BOOL) { return(null); } SYMBOL_INFO ret = null; if (m_cond.bol_val == true) { // // if cond is true foreach (Stmt rst in stmnts) { ret = rst.Execute(cont); if (ret != null) { return(ret); } } } else if (else_part != null) { // if cond is false and there is // else statement ..! foreach (Stmt rst in else_part) { ret = rst.Execute(cont); if (ret != null) { return(ret); } } } return(null); }
public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont) { Console.Write("\twhile ( "); cond.GenerateJS(cont); Console.Write(") { \r\n"); foreach (Stmt rst in stmnts) { rst.GenerateJS(cont); } Console.Write("\t\r\n}\r\n"); return(null); }
public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont) { Console.Write("\t if ( "); // // Evaluate the Condition // //SYMBOL_INFO m_cond = cond.Evaluate(cont); cond.GenerateJS(cont); Console.Write(" ) { \r\n "); // // if cond is not boolean..or evaluation failed // //if (m_cond == null || // m_cond.Type != TYPE_INFO.TYPE_BOOL) // return null; //SYMBOL_INFO ret = null; //if (m_cond.bol_val == true) // { // // if cond is true foreach (Stmt rst in stmnts) { rst.GenerateJS(cont); } if (else_part != null) { Console.Write("\t } \t\r\n else { \r\n "); foreach (Stmt rst in else_part) { rst.GenerateJS(cont); } } Console.Write("\r\n\t } \r\n \r\n "); return(null); }
/// <summary> /// /// </summary> /// <param name="cont"></param> /// <returns></returns> public override SYMBOL_INFO Evaluate(RUNTIME_CONTEXT cont) { SYMBOL_INFO eval_left = ex1.Evaluate(cont); if (eval_left.Type == TYPE_INFO.TYPE_BOOL) { SYMBOL_INFO ret_val = new SYMBOL_INFO(); ret_val.Type = TYPE_INFO.TYPE_BOOL; ret_val.SymbolName = ""; ret_val.bol_val = !eval_left.bol_val; return(ret_val); } else { return(null); } }
/// <summary> /// /// </summary> /// <param name="cont"></param> /// <returns></returns> public override SYMBOL_INFO Evaluate(RUNTIME_CONTEXT cont) { if (m_proc != null) { // // This is a Ordinary Function Call // // RUNTIME_CONTEXT ctx = new RUNTIME_CONTEXT(cont.GetProgram()); ArrayList lst = new ArrayList(); foreach (Exp ex in m_actuals) { lst.Add(ex.Evaluate(cont)); } return(m_proc.Execute(ctx, lst)); } else { // Recursive function call...by the time we // reach here..whole program has already been // parsed. Lookup the Function name table and // resolve the Address // // m_proc = cont.GetProgram().Find(_procname); RUNTIME_CONTEXT ctx = new RUNTIME_CONTEXT(cont.GetProgram()); ArrayList lst = new ArrayList(); foreach (Exp ex in m_actuals) { lst.Add(ex.Evaluate(cont)); } return(m_proc.Execute(ctx, lst)); } }
public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont, ArrayList formals) { //Procedure p = Find("Main"); Console.Write("//--- invoke the main method ... \r\n\r\n\r\n"); Console.Write("//---- Generated JavaScript from SLANG Script\r\n"); //if (p != null) // { // p.GenerateJS(cont, formals); // } foreach (Procedure p in m_procs) { p.GenerateJS(cont, formals); } Console.Write("//----End Generated JavaScript \r\n"); return(null); }
public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont) { //cont.TABLE.Add(m_inf); //var = new Variable(m_inf); //return null; // cont.TABLE.Add(m_inf); if (m_inf.Type != TYPE_INFO.TYPE_MAP && m_inf.Type != TYPE_INFO.TYPE_ARRAY) { Console.Write("var " + m_inf.SymbolName + ";\r\n"); } else if (m_inf.Type == TYPE_INFO.TYPE_ARRAY) { Console.Write("var " + m_inf.SymbolName + " = new Array( " + m_inf.a_info.bound + ") ;\r\n"); } else if (m_inf.Type == TYPE_INFO.TYPE_MAP) { Console.Write("var " + m_inf.SymbolName + " = {} ;\r\n"); } return(null); }
public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont) { //SYMBOL_INFO val = exp1.Evaluate(cont); //cont.TABLE.Assign(variable, val); //return null; // TYPE_INFO tp = variable.get_type(); if (tp != TYPE_INFO.TYPE_MAP && tp != TYPE_INFO.TYPE_ARRAY) { Console.Write(variable.Name + "="); exp1.GenerateJS(cont); Console.Write(";\r\n"); } else { // Console.Write(variable..Name + "[" ); variable.GenerateJS(cont); Console.Write(" = "); exp1.GenerateJS(cont); Console.Write(";\r\n"); } return(null); }
/// <summary> /// While evaluating a numeric constant , return the _value /// </summary> /// <param name="cont"></param> /// <returns></returns> public override double Evaluate(RUNTIME_CONTEXT cont) { return(_value); }
public abstract double Evaluate(RUNTIME_CONTEXT cont);
/// <summary> /// Evaluation of boolean will given the value /// </summary> /// <param name="local"></param> /// <param name="global"></param> /// <returns></returns> public override SYMBOL_INFO Evaluate(RUNTIME_CONTEXT cont) { return(info); }
public abstract SYMBOL_INFO Evaluate(RUNTIME_CONTEXT cont);
public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont) { exp.GenerateJS(cont); return(null); }
// //public abstract SYMBOL_INFO Execute(RUNTIME_CONTEXT cont); // The above stuff is extended with Formal parameter list // addition in STEP 7 public abstract SYMBOL_INFO Execute(RUNTIME_CONTEXT cont, ArrayList formals);
public abstract SYMBOL_INFO Execute(RUNTIME_CONTEXT cont);
public abstract bool Execute(RUNTIME_CONTEXT con);
/// <summary> /// /// </summary> /// <param name="cont"></param> /// <returns></returns> public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont) { cont.TABLE.Add(m_inf); var = new Variable(m_inf); return(null); }