コード例 #1
0
        public void TestScope()
        {
            var test = @"
                        void foo(int p){
                            p = 1;    
                        }
                        int z = 5;
                        while(z > 0){
                            z = z + 1;
                            foo();
                        }
                        ";

            var ast = new LanguageParser(new Lexers.Lexer(test)).Parse();

            var visitor = new ScopeBuilderVisitor();

            visitor.Start(ast);
        }
コード例 #2
0
        public void TestTypeResolutionUserDefined()
        {
            var test = @"
                        int x = 100 + 1;
                        T y;
                        var z = 1 > 2;";

            var ast = new LanguageParser(new Lexers.Lexer(test)).Parse() as ScopeDeclr;

            var scopeBuilder = new ScopeBuilderVisitor();

            scopeBuilder.Start(ast);

            var typeResolver = new ScopeBuilderVisitor(true);

            typeResolver.Start(ast);

            Assert.IsTrue(ast.ScopedStatements[0].AstSymbolType is BuiltInType);
            Assert.IsTrue(ast.ScopedStatements[1].AstSymbolType is UserDefinedType);
            Assert.IsTrue(ast.ScopedStatements[2].AstSymbolType is BuiltInType);
            Assert.IsTrue((ast.ScopedStatements[2].AstSymbolType as BuiltInType).ExpressionType == ExpressionTypes.Boolean);
        }