예제 #1
0
        public override IAstNode VisitAexprRecAccess(MicroCParser.AexprRecAccessContext context)
        {
            string recName     = context.name.Text;
            string fieldName   = context.field.Text;
            var    recSymbol   = _symbolTable.LookupSymbol(recName);
            var    fieldSymbol = recSymbol.Children.SingleOrDefault(f => f.Name == fieldName);

            if (fieldSymbol == null)
            {
                throw new ArgumentException($"Record: {recName} does not include a field: {fieldName}");
            }

            var recIdent   = new Identifier(recName, recSymbol.Type, recSymbol.Id);
            var fieldIdent = new Identifier(fieldName, fieldSymbol.Type, fieldSymbol.Id);

            return(new RecordAccess(recIdent, fieldIdent));
        }
예제 #2
0
 /// <summary>
 /// Exit a parse tree produced by the <c>aexprRecAccess</c>
 /// labeled alternative in <see cref="MicroCParser.a_expr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitAexprRecAccess([NotNull] MicroCParser.AexprRecAccessContext context)
 {
 }
예제 #3
0
 /// <summary>
 /// Visit a parse tree produced by the <c>aexprRecAccess</c>
 /// labeled alternative in <see cref="MicroCParser.a_expr"/>.
 /// <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 VisitAexprRecAccess([NotNull] MicroCParser.AexprRecAccessContext context)
 {
     return(VisitChildren(context));
 }