Exemple #1
0
        private object AssignTuple(Environment env, TupleNode left, string op, object rvalue)
        {
            if (left == null)
            {
                throw new ArgumentNullException(nameof(left), "null left tuple");
            }

            Tuple right = rvalue as Tuple;

            if (right != null)
            {
                object result = 0;

                int count = 0;
                foreach (IAstNode node in left)
                {
                    if (count >= right.Count)
                    {
                        break;
                    }

                    TupleNode tuple = node as TupleNode;

                    if (node != null)
                    {
                        result = AssignTuple(env, tuple, op, right[count++]);
                    }
                    else
                    {
                        FactorNode factor = node as FactorNode;

                        if (factor == null || !factor.IsAssignable)
                        {
                            throw new LepException("bad assignment", this);
                        }

                        PrimaryNode primary = factor.Operand as PrimaryNode;
                        if (primary == null)
                        {
                            throw new LepException("bad assignment", this);
                        }

                        if (((NameNode)primary.Operand).IsAnonymous)
                        {
                            ++count;
                        }
                        else
                        {
                            result = Assign(env, primary, op, right[count++], factor.AssignType);
                        }
                    }
                }

                return(result);
            }
            else
            {
                throw new LepException("bad assignment", this);
            }
        }
Exemple #2
0
 public ArgumentNode(TupleNode tuple) : base(new Collection <IAstNode>())
 {
     if (tuple == null)
     {
         throw new ArgumentNullException(nameof(tuple), "null tuple");
     }
     foreach (IAstNode node in tuple)
     {
         Add(node);
     }
 }
Exemple #3
0
        private object ComputeAssignment(Environment env, string op, object rvalue)
        {
            TupleNode tuple = Left as TupleNode;

            if (tuple != null)
            {
                return(AssignTuple(env, tuple, op, rvalue));
            }

            FactorNode factor = Left as FactorNode;

            if (factor != null && factor.IsAssignable)
            {
                return(Assign(env, (PrimaryNode)factor.Operand, op, rvalue, factor.AssignType));
            }

            throw new LepException("bad assignment", this);
        }
Exemple #4
0
 public ParameterNode(TupleNode tuple)
     : base(new Collection<IAstNode>())
 {
     if (tuple == null) throw new ArgumentNullException(nameof(tuple), "null tuple");
     foreach (IAstNode node in tuple) Add(node);
 }
Exemple #5
0
        private object AssignTuple(Environment env, TupleNode left, string op, object rvalue)
        {
            if (left == null) throw new ArgumentNullException(nameof(left), "null left tuple");

            Tuple right = rvalue as Tuple;
            if (right != null)
            {
                object result = 0;

                int count = 0;
                foreach (IAstNode node in left)
                {
                    if (count >= right.Count) break;

                    TupleNode tuple = node as TupleNode;

                    if (node != null) result = AssignTuple(env, tuple, op, right[count++]);
                    else
                    {
                        FactorNode factor = node as FactorNode;

                        if (factor == null || !factor.IsAssignable) throw new LepException("bad assignment", this);

                        PrimaryNode primary = factor.Operand as PrimaryNode;
                        if (primary == null) throw new LepException("bad assignment", this);

                        if (((NameNode)primary.Operand).IsAnonymous) ++count;
                        else result = Assign(env, primary, op, right[count++], factor.AssignType);
                    }
                }

                return result;
            }
            else throw new LepException("bad assignment", this);
        }