Пример #1
0
        private static void GetLl2SymbolSets()
        {
            lock (_lookupTablesLock)
            {
                if (_definitionContextSet1 != null)
                {
                    return;
                }

                Network setAnalysisNetwork = NetworkBuilder <JavaSimplifiedAtnBuilder> .GetOrBuildNetwork();

                JavaSimplifiedAtnBuilder setAnalysisBuilder = (JavaSimplifiedAtnBuilder)setAnalysisNetwork.Builder;

                _definitionSourceSet = setAnalysisBuilder.DefinitionSourceSet;
                _referenceSourceSet  = setAnalysisBuilder.ReferenceSourceSet;
                _definitionFollowSet = setAnalysisBuilder.DefinitionFollowSet;
                _referenceFollowSet  = setAnalysisBuilder.ReferenceFollowSet;

                _definitionOnlySourceSet = setAnalysisBuilder.DefinitionOnlySourceSet;
                _referenceOnlySourceSet  = setAnalysisBuilder.ReferenceOnlySourceSet;
                _definitionOnlyFollowSet = setAnalysisBuilder.DefinitionOnlyFollowSet;
                _referenceOnlyFollowSet  = setAnalysisBuilder.ReferenceOnlyFollowSet;

                _definitionContextSet1 = new Dictionary <int, IntervalSet>();
                _referenceContextSet1  = new Dictionary <int, IntervalSet>();
                _definitionSourceSet2  = new Dictionary <int, IntervalSet>();
                _referenceSourceSet2   = new Dictionary <int, IntervalSet>();
                _definitionFollowSet2  = new Dictionary <int, IntervalSet>();
                _referenceFollowSet2   = new Dictionary <int, IntervalSet>();

                var sharedSourceTokens = setAnalysisBuilder.DefinitionSourceSet.Intersect(setAnalysisBuilder.ReferenceSourceSet);
                foreach (var sharedSourceToken in sharedSourceTokens)
                {
                    CommonTokenStream analysisTokenStream = new CommonTokenStream(new ArrayTokenSource(sharedSourceToken, Java2Lexer.IDENTIFIER));
                    analysisTokenStream.Fill();
                    analysisTokenStream.Seek(1);

                    // definition context set
                    NetworkInterpreter ll2analyzer = new NetworkInterpreter(setAnalysisNetwork, analysisTokenStream);
                    ll2analyzer.ExcludedStartRules.Add(setAnalysisNetwork.GetRule(JavaAtnBuilder.RuleNames.SymbolReferenceIdentifier));
                    ll2analyzer.TryStepForward();
                    ll2analyzer.TryStepBackward();
                    _definitionContextSet1[sharedSourceToken] = ll2analyzer.GetFollowSet();
                    _definitionSourceSet2[sharedSourceToken]  = ll2analyzer.GetSourceSet();

                    // reference context set
                    ll2analyzer = new NetworkInterpreter(setAnalysisNetwork, analysisTokenStream);
                    ll2analyzer.ExcludedStartRules.Add(setAnalysisNetwork.GetRule(JavaAtnBuilder.RuleNames.SymbolDefinitionIdentifier));
                    ll2analyzer.TryStepForward();
                    ll2analyzer.TryStepBackward();
                    _referenceContextSet1[sharedSourceToken] = ll2analyzer.GetFollowSet();
                    _referenceSourceSet2[sharedSourceToken]  = ll2analyzer.GetSourceSet();
                }

                var sharedFollowTokens = setAnalysisBuilder.DefinitionFollowSet.Intersect(setAnalysisBuilder.ReferenceFollowSet);
                foreach (var sharedFollowToken in sharedFollowTokens)
                {
                    CommonTokenStream analysisTokenStream = new CommonTokenStream(new ArrayTokenSource(Java2Lexer.IDENTIFIER, sharedFollowToken));
                    analysisTokenStream.Fill();
                    analysisTokenStream.Seek(0);

                    // definition follow set
                    NetworkInterpreter ll2analyzer = new NetworkInterpreter(setAnalysisNetwork, analysisTokenStream);
                    ll2analyzer.ExcludedStartRules.Add(setAnalysisNetwork.GetRule(JavaAtnBuilder.RuleNames.SymbolReferenceIdentifier));
                    ll2analyzer.TryStepForward();
                    ll2analyzer.TryStepBackward();
                    _definitionFollowSet2[sharedFollowToken] = ll2analyzer.GetFollowSet();

                    // reference follow set
                    ll2analyzer = new NetworkInterpreter(setAnalysisNetwork, analysisTokenStream);
                    ll2analyzer.ExcludedStartRules.Add(setAnalysisNetwork.GetRule(JavaAtnBuilder.RuleNames.SymbolDefinitionIdentifier));
                    ll2analyzer.TryStepForward();
                    ll2analyzer.TryStepBackward();
                    _referenceFollowSet2[sharedFollowToken] = ll2analyzer.GetFollowSet();
                }
            }
        }