示例#1
0
 /// <summary>
 /// return a new <seealso cref="Assignment"/> with Left and Right assigned.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 public Assignment WithOperands(LaxExpression left, LaxExpression right)
 {
     var op = new Assignment(this);
     op.Left = left;
     op.Right = right;
     op.CodeRange = CodeRange.Expand2(left).Expand2(right);
     return op;
 }
示例#2
0
        static LaxExpression EvaluateAssignment(Assignment s)
        {
            var val = Evaluate(s.Right);
            if (val == s.Right)
                return s; //no optimization

            return s.WithOperands(s.Left, val);
        }
示例#3
0
        Literal EvaluateAssignment(Assignment expr)
        {
            var identifier = expr.Left as Identifier;
            if (identifier == null)
                throw new SemanticError(expr.Left, "Expected identifier");

            if (variables.ContainsKey(identifier) == false)
                throw new SemanticError(expr.Left, "Undefined variable");

            var value = Evaluate(expr.Right);
            variables[identifier] = value;

            return value;
        }
示例#4
0
 string FormatAssignment(Assignment expr)
 {
     return Format(expr.Left) + " = " + Format(expr.Right);
 }
示例#5
0
        /// <summary>
        /// Asign 
        /// </summary>
        /// <param name="s"></param>
        void EvalAssignmentOperator(Assignment a)
        {
            var id = (Identifier)a.Left;
            var variable = block.Variables[id];

            Eval(a.Right);
            var t = a.Right.ValueType;
            a.Left.ValueType = t;

            //Make sure the variable is not assigned a value
            if (variable.ValueType != null)
            {
                if (variable.ValueType != t)
                    throw new SemanticError(a.Left, "Type mismatch");
            }

            variable.ValueType = t;
        }