Esempio n. 1
0
        public override void EnterVarMultiAssignment(FlyParser.VarMultiAssignmentContext context)
        {
            var ids    = context.arrOrVar();
            var values = context._values;

            // Check if valid multi assignment:
            // Either one value and multiple ids or the same amount of values and ids
            if (ids.Length == values.Count)
            {
                for (int i = 0; i < ids.Length; i++)
                {
                    EnterExpression(values[i]);
                    if (ids[i].index != null)
                    {
                        EnterExpression(ids[i].index);
                        Code.GetVar(ids[i].ID().GetText());
                        Code.ArraySet();
                    }
                    else
                    {
                        Code.SetVar(ids[i].ID().GetText());
                    }
                    Code.Instructions.Add(OpCode.POP);
                }
            }
            else if (values.Count == 1)
            {
                EnterExpression(values[0]);
                foreach (var id in ids)
                {
                    if (id.index != null)
                    {
                        EnterExpression(id.index);
                        Code.GetVar(id.ID().GetText());
                        Code.ArraySet();
                    }
                    else
                    {
                        Code.SetVar(id.ID().GetText());
                    }
                }
                Code.Instructions.Add(OpCode.POP);
            }
            else
            {
                throw new InvalidOperationException(
                          $"The multi var assignment has a invalid amount of variable names / expressions.");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="FlyParser.varMultiAssignment"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitVarMultiAssignment([NotNull] FlyParser.VarMultiAssignmentContext context)
 {
 }