Пример #1
0
        public static void PopulateStubs(
            Scope globalScope,
            PParser.ProgramContext context,
            ParseTreeProperty <IPDecl> nodesToDeclarations)
        {
            DeclarationStubVisitor visitor = new DeclarationStubVisitor(globalScope, nodesToDeclarations);

            visitor.Visit(context);
        }
Пример #2
0
        private static Scope BuildGlobalScope(ITranslationErrorHandler handler, PParser.ProgramContext[] programUnits)
        {
            var globalScope         = Scope.CreateGlobalScope(handler);
            var nodesToDeclarations = new ParseTreeProperty <IPDecl>();

            // Add built-in events to the table.
            globalScope.Put("null", (PParser.EventDeclContext)null);
            globalScope.Put("halt", (PParser.EventDeclContext)null);

            // Step 1: Create mapping of names to declaration stubs
            foreach (var programUnit in programUnits)
            {
                DeclarationStubVisitor.PopulateStubs(globalScope, programUnit, nodesToDeclarations);
            }

            // Step 2: Validate declarations and fill with types
            foreach (var programUnit in programUnits)
            {
                DeclarationVisitor.PopulateDeclarations(handler, globalScope, programUnit, nodesToDeclarations);
            }

            return(globalScope);
        }