Exemple #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");
                    }
                }