Пример #1
0
        public override IVecValue VisitArrayAccess([NotNull] VectorizeParser.ArrayAccessContext context)
        {
            var name  = context.ID().GetText();
            var value = CurrentScope[name];
            var idxV  = context.expression().Accept(this);

            if (value is IVecContainer container)
            {
                if (idxV is VecInt idx)
                {
                    return(container.Get(idx.Value));
                }
                else
                {
                    throw new InvalidOperationException($"Index must be a int! Was: {idxV.Type}");
                }
            }
            else
            {
                throw new InvalidOperationException($"Variable '{name}' must be an array to use indexing!");
            }
        }
Пример #2
0
 /// <summary>
 /// Exit a parse tree produced by the <c>ArrayAccess</c>
 /// labeled alternative in <see cref="VectorizeParser.expression"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitArrayAccess([NotNull] VectorizeParser.ArrayAccessContext context)
 {
 }
Пример #3
0
 /// <summary>
 /// Visit a parse tree produced by the <c>ArrayAccess</c>
 /// labeled alternative in <see cref="VectorizeParser.expression"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitArrayAccess([NotNull] VectorizeParser.ArrayAccessContext context)
 {
     return(VisitChildren(context));
 }