public ParserTransition GetOrCreateTransition(IntermediateParserState source, GrammarElement element,
            IntermediateParserState destination)
        {
            var transition = source.OutgoingTransitions.Values.FirstOrDefault(x => x.Destination == destination);
            if (transition == null)
            {
                transition = new ParserTransition(source, element, destination);
                source.OutgoingTransitions.Add(element, transition);
                destination.IncomingTransitions.Add(transition);
            }

            return transition;
        }
        public AnnotatedGrammarElement GetOrCreateAnnotatedElement(GrammarElement element, ParserTransition transition)
        {
            // Compute a hashcode for quick look up.
            int elementHash = element.GetHashCode();
            int transitionHash = transition?.GetHashCode() ?? 0;

            AnnotatedGrammarElement annotatedElement = null;
            IDictionary<int, AnnotatedGrammarElement> annotatedElements;
            if (!_elementMapping.TryGetValue(elementHash, out annotatedElements)
                || !annotatedElements.TryGetValue(transitionHash, out annotatedElement))
            {
                if (annotatedElements == null)
                    _elementMapping.Add(elementHash, annotatedElements = new Dictionary<int, AnnotatedGrammarElement>());
                annotatedElements.Add(transitionHash, annotatedElement = new AnnotatedGrammarElement(element, transition));
            }

            return annotatedElement;
        }
Exemplo n.º 3
0
 public AnnotatedGrammarElement(GrammarElement element, ParserTransition transition)
 {
     Element = element;
     Transition = transition;
     Parents = new HashSet<AugmentedGrammarReduction>();
 }