Ejemplo n.º 1
0
        public override ASTNode VisitDeclaration([NotNull] DeclarationContext ctx)
        {
            switch (ctx.children.First().GetText())
            {
            case "declare":
                var      declSpecs = new DeclSpecsNode(ctx.Start.Line, GetTypeName());
                var      name      = new IdNode(ctx.Start.Line, ctx.NAME().GetText());
                DeclNode decl;
                if (ctx.type().typename().children.Count > 1)
                {
                    switch (ctx.type().typename().children.Last().GetText())
                    {
                    case "array":
                    case "list":
                    case "set":
                        if (ctx.exp() is { })
                        {
                            ExprNode init = this.Visit(ctx.exp()).As <ExprNode>();
                            decl = new ArrDeclNode(ctx.Start.Line, name, init);
                        }
                        else
                        {
                            decl = new ArrDeclNode(ctx.Start.Line, name);
                        }
                        break;

                    default:
                        throw new SyntaxErrorException("Invalid complex type");
                    }
                }
 public static DeclaredSymbol From(DeclSpecsNode specs, DeclNode decl)
 {
     return(decl switch
     {
         VarDeclNode var => new DeclaredVariableSymbol(decl.Identifier, specs, var, var.Initializer),
         ArrDeclNode arr => new DeclaredArraySymbol(decl.Identifier, specs, arr, arr.SizeExpression, arr.Initializer),
         FuncDeclNode f => new DeclaredFunctionSymbol(decl.Identifier, specs, f),
         _ => throw new NotImplementedException("Declarator node type not yet implemented"),
     });
Ejemplo n.º 3
0
 public virtual TResult Visit(ArrDeclNode node) => this.VisitChildren(node);
 public DeclaredArraySymbol(string name, DeclSpecsNode specs, ArrDeclNode decl, ExprNode?size = null, ArrInitExprNode?init = null)
     : base(name, specs, decl)
 {
     this.ArrayDeclarator = decl;
     if (size is { })