コード例 #1
0
        public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont)
        {
            SYMBOL_INFO val = exp1.Evaluate(cont);

            cont.TABLE.Assign(variable, val);
            return(null);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
 public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont)
 {
     Console.Write("console.log(");
     exp1.GenerateJS(cont);
     Console.Write(");\r\n");
     return(null);
 }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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");
            }
        }
コード例 #7
0
        /// <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;
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont)
        {
            foreach (Stmt stmt in m_statements)
            {
                stmt.Execute(cont);
            }

            return(null);
        }
コード例 #10
0
        public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont)
        {
            Console.Write("\treturn ");


            m_e1.GenerateJS(cont);
            Console.Write(";\r\n");
            return(null);
        }
コード例 #11
0
        public override SYMBOL_INFO Execute(RUNTIME_CONTEXT cont, ArrayList actuals)
        {
            Procedure p = Find("Main");

            if (p != null)
            {
                return(p.Execute(cont, actuals));
            }

            return(null);
        }
コード例 #12
0
 /// <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);
     }
 }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        /// <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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        /// <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);
            }
        }
コード例 #18
0
        /// <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));
            }
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
 /// <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);
 }
コード例 #23
0
 public abstract double Evaluate(RUNTIME_CONTEXT cont);
コード例 #24
0
 /// <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);
 }
コード例 #25
0
 public abstract SYMBOL_INFO Evaluate(RUNTIME_CONTEXT cont);
コード例 #26
0
 public override SYMBOL_INFO GenerateJS(RUNTIME_CONTEXT cont)
 {
     exp.GenerateJS(cont);
     return(null);
 }
コード例 #27
0
 //
 //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);
コード例 #28
0
 public abstract SYMBOL_INFO Execute(RUNTIME_CONTEXT cont);
コード例 #29
0
 public abstract bool Execute(RUNTIME_CONTEXT con);
コード例 #30
0
 /// <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);
 }