예제 #1
0
        public override object Evaluate(MyContext context)
        {
            MyFunctionDecleration func = context.GetFunctionRVD(Name);

            MyContext ctx = new MyContext();

            ctx.functionsRVD = context.functionsRVD;

            for (int i = 0; i < func.Params.Count ; i++)
            {
                IConvertible value = (IConvertible) Args[i].Evaluate(context);
                string param = func.Params[i];
                ctx.AddVariable(param, value);

                if (i < func.Params.Count - 1)
                {
                    context.AddLog(", ");
                }

                //Debug.WriteLine(Name + "," + param + "=" + value);

                context.AddLog(value.ToString());
            }

            object o = func.Statements.Evaluate(ctx);

            object returnValue = ctx.returnValue;
            ctx.returned = false;

            //Debug.WriteLine(Name + ".returnValue =" + returnValue);

            context.AddLog(ctx.sb.ToString());

            return returnValue;
        }
예제 #2
0
        public override object Evaluate(MyContext context)
        {
            IConvertible o = (IConvertible) Op.Evaluate(context);

            switch (o.GetTypeCode())
            {
                case TypeCode.Char:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                    return -(Convert.ToInt32(o));

                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:

                case TypeCode.Single:
                case TypeCode.Double:
                    return - Convert.ToDouble(o);

                case TypeCode.Decimal:
                    return - ((decimal) o);

                default:
                    return o;
            }
        }
예제 #3
0
 public override void List(MyContext context)
 {
     VariableNode.List(context);
     context.ListLog.Append(" := ");
     ValueNode.List(context);
     context.ListLog.Append(";");
 }
예제 #4
0
        public override object DoStatement(MyContext context)
        {
            context.AddLog("if cond: ");

            bool cond = (bool)Condition.Evaluate(context);

            context.AddLog(Environment.NewLine);

            object o = null;

            if (cond)
            {
                context.AddLog("then: ");
                o = ThenPart.Evaluate(context);
                context.AddLog(Environment.NewLine);
            }
            else
            {

                if (ElsePart != null)
                {
                    context.AddLog("else: ");
                    o = ElsePart.Evaluate(context);
                    context.AddLog(Environment.NewLine);
                }
                else
                {
                    context.AddLog("nothing: ");
                    context.AddLog("end-if");
                }
            }

            return o;
        }
예제 #5
0
 public override void List(MyContext context)
 {
     context.ListLog.Append(" ( ");
     Left.List(context);
     context.ListLog.Append(" ").Append(Symbol).Append(" ");
     Right.List(context);
     context.ListLog.Append(" ) ");
 }
예제 #6
0
        public override object Evaluate(MyContext context)
        {
            IConvertible value = (IConvertible) context.GetVariable(Name);

            context.AddLog(" $" + Name + "[" + value + "] ");

            return value;
        }
예제 #7
0
        public override object DoStatement(MyContext context)
        {
            context.AddLog("returning: ");
            object o = ReturnExpression.Evaluate(context);

            context.returnValue = o;
            context.returned = true;
            //Debug.WriteLine("returning: " + o);

            return o;
        }
예제 #8
0
 public override void List(MyContext context)
 {
     context.ListLog.Append("{");
     context.ListLog.NewLine();
     context.ListLog.StepDown();
     foreach (var statementNode in statements)
     {
         statementNode.List(context);
         context.ListLog.NewLine();
     }
     context.ListLog.StepUp();
     context.ListLog.Append("}");
 }
예제 #9
0
        public override void List(MyContext context)
        {
            context.ListLog.Append("if (");
            Condition.List(context);
            context.ListLog.Append(") then").NewLine();

            ThenPart.List(context);

            if (ElsePart != null)
            {
                context.ListLog.NewLine().Append("else").NewLine();
                ElsePart.List(context);
            }
        }
예제 #10
0
        public override void List(MyContext context)
        {
            context.ListLog.Append("call ").Append(Name).Append("(");

            for (int i = 0; i < Args.Count; i++)
            {
                Args[i].List(context);
                if (i < Args.Count - 1)
                {
                    context.ListLog.Append(", ");
                }
            }

            context.ListLog.Append(")");
        }
예제 #11
0
        public override object Evaluate(MyContext context)
        {
            context.AddLog(" ( ");

            context.AddLog(Symbol + " ");

            IConvertible left = (IConvertible)Left.Evaluate(context);
            IConvertible right = (IConvertible)Right.Evaluate(context);

            context.AddLog(" ) ");

            IConvertible result = DoBinOp(left, right);

            return result;
        }
예제 #12
0
        public override void List(MyContext context)
        {
            context.ListLog.Append("declare program: ").Append(Name).NewLine().Append("{").NewLine();

            context.ListLog.StepDown();
            foreach (var func in Funcs)
            {
                func.List(context);
                context.ListLog.NewLine();
            }

            Statements.List(context);

            context.ListLog.StepUp();
            context.ListLog.NewLine().Append("}").NewLine();
        }
예제 #13
0
        public override object Evaluate(MyContext context)
        {
            context.AddLog("declaring program: " + Name);
            context.AddLog(Environment.NewLine);

            MyContext ctx = new MyContext();

            List(ctx);

            context.AddLog(ctx.ListLog.ToString());

            context.AddLog(Environment.NewLine);

            context.AddProgram(Name, this);
            return 0;
        }
예제 #14
0
        public override object DoStatement(MyContext context)
        {
            object o = 0;

            foreach (var statementNode in statements)
            {
                o = statementNode.Evaluate(context);
                context.AddLog(Environment.NewLine);

                if (context.returned)
                {
                    return o;
                }
            }

            return o;
        }
예제 #15
0
        public override object DoStatement(MyContext context)
        {
            context.AddLog(VariableNode.Name + " := ");

            IConvertible value = (IConvertible)ValueNode.Evaluate(context);

            if (!context.ContainsVariable(VariableNode.Name))
            {
                context.AddVariable(VariableNode.Name, value);
            }
            else
            {
                context.SetVariable(VariableNode.Name, value);
            }

            return value;
        }
예제 #16
0
        public override void List(MyContext context)
        {
            context.ListLog.Append("declare function: ").Append(Name).Append("( ");

            for (int i = 0; i < Params.Count; i++)
            {
                context.ListLog.Append("@").Append(Params[i]);

                if (i < Params.Count - 1)
                {
                    context.ListLog.Append(", ");
                }
            }

            context.ListLog.Append(" )").NewLine();

            Statements.List(context);

            context.ListLog.NewLine();
        }
예제 #17
0
 public override void List(MyContext context)
 {
     context.ListLog.Append("-");
     Op.List(context);
 }
예제 #18
0
 private void button2_Click(object sender, EventArgs e)
 {
     textBox1.Clear();
     textBox2.Clear();
     textBox3.Clear();
     _context = new MyContext();
 }
예제 #19
0
        private void button7_Click(object sender, EventArgs e)
        {
            if (_context.programs.ContainsKey(_currentProgram.Name))
            {
                _context = new MyContext();
            }

            textBox2.AppendText(Environment.NewLine);
            textBox2.AppendText("evaluation prog " + _currentProgram.Name);

            _currentProgram.Evaluate(_context);

            textBox2.AppendText(Environment.NewLine);
            textBox2.AppendText(_currentProgram.Name + " loaded");
        }
예제 #20
0
 private void Form1_Load(object sender, EventArgs e)
 {
     var c = new MyContext();
 }
예제 #21
0
 public override object Evaluate(MyContext context)
 {
     object o = DoStatement(context);
     return o;
 }
예제 #22
0
 public override void List(MyContext context)
 {
     context.ListLog.Append("return ");
     ReturnExpression.List(context);
     context.ListLog.Append(";");
 }
예제 #23
0
 public override object Evaluate(MyContext context)
 {
     context.AddLog(Value.ToString() + " ");
     return Value;
 }
예제 #24
0
 public override void List(MyContext context)
 {
     context.ListLog.Append(Value.ToString()).Append(" ");
 }
예제 #25
0
 public override void List(MyContext context)
 {
     context.ListLog.Append("$").Append(Name);
 }