Esempio n. 1
0
        static void TestAST()
        {
            var program = new AST.CompilationUnit(new List <AST.Declaration> {
                new AST.ClassDeclaration(
                    new List <AST.Modifier> {
                    AST.Modifier.Public
                },
                    ("Helloworld"),
                    new List <AST.Declaration> {
                    new AST.MethodDeclaration(
                        new List <AST.Modifier> {
                        AST.Modifier.Public, AST.Modifier.Static
                    },
                        new AST.NamedType("void"),
                        "main",
                        new List <AST.FormalParameterDeclaration> {
                        new AST.FormalParameterDeclaration(
                            new AST.ArrayType(new AST.NamedType("String")),
                            "args"
                            )
                    },


                        new AST.Block(
                            new List <AST.Statement> {
                        new AST.VariableDeclarationStatement(new AST.PrimitiveType(AST.Primitive.Int), new List <AST.VariableDeclarator> {
                            new AST.VariableDeclarator("x", null)
                        }),
                        new AST.VariableDeclarationStatement(new AST.PrimitiveType(AST.Primitive.Int), new List <AST.VariableDeclarator> {
                            new AST.VariableDeclarator("y", null)
                        }),
                        new AST.ExpressionStatement(
                            new AST.AssignmentExpression(
                                new AST.IdentifierExpression("x"),
                                "=",
                                new AST.IntegerLiteralExpression(42)         //42 is changed to "42"

                                )
                            ),
                        new AST.ExpressionStatement(new AST.AssignmentExpression(new AST.IdentifierExpression("y"), "=", new AST.BinaryExpression(new AST.IdentifierExpression("x"), "+", new AST.IntegerLiteralExpression(1))))
                    }
                            )
                        )
                })
            }
                                                  );

            program.ResolveNames(null);
            program.DumpValue(0);
        }
Esempio n. 2
0
        static void TestAST()
        {
            var program = new AST.CompilationUnit(
                /* Null is for PackageDec and ImportDec*/
                null,
                null,
                new List <AST.TypeDeclaration>
            {
                new AST.ClassDeclaration(

                    new List <AST.ClassModifier> {
                    AST.ClassModifier.Public
                },
                    "HelloWorld",
                    new List <AST.ClassBodyDeclaration>
                {
                    new AST.MethodDeclaration(
                        new List <AST.MethodModifier> {
                        AST.MethodModifier.Public, AST.MethodModifier.Static
                    },
                        new AST.MethodHeader(AST.Type.VOID,
                                             new AST.MethodDeclarator(
                                                 "main",
                                                 new List <AST.FormalParameter>
                    {
                        new AST.FormalParameter(
                            new AST.ArrayType(new AST.NamedType("String")), "args")
                    })),
                        new AST.MethodBody(
                            new List <AST.Statement>
                    {
                        new AST.LocalVariableDeclarationStatement(new AST.PrimitiveType(AST.Primitive.Int), "x"),

                        new AST.ExpressionStatement(
                            new AST.AssignmentExpression(
                                "x",
                                "=",
                                new AST.IntExpression("42")
                                )
                            )
                    }
                            )
                        )
                }
                    )
            }
                );

            program.DumpValue(0);
        }