Esempio n. 1
0
        public ProductionInfoManager(IProduction root)
        {
            CodeContract.RequiresArgumentNotNull(root, "root");

            var aggregator = new ProductionAggregationVisitor();
            var productions = root.Accept(aggregator, new List<IProduction>());

            m_productions = productions.ToArray();
            RootProduction = root;

            var ffVisitor = new FirstFollowVisitor();

            bool isChanged;

            do
            {
                isChanged = false;

                foreach (var p in productions)
                {
                    isChanged = p.Accept(ffVisitor, isChanged);
                }

            } while (isChanged);
        }
Esempio n. 2
0
        public void Reduce(IProduction production, ReduceVisitor reducer, Lexeme lookahead)
        {
#if HISTORY
            var from = m_topStack.StateIndex;
#endif

            if (production == null)
            {
                //Accept
                Debug.Assert(m_topStack.PrevNode.StateIndex == 0);

                //TODO: accepted
                IsAccepted = true;
                return;
            }

            if (production.AggregatesAmbiguities)
            {
                AmbiguityAggregator = ((ProductionBase)production).CreateAggregator();
            }

            var reduceResult = production.Accept(reducer, m_topStack);

            m_topStack = reduceResult.NewTopStack;
            var reduceError = reduceResult.ReduceError;

            if (reduceError != null)
            {
                IncreaseErrorRecoverLevel();

                if (reduceError.ErrorPosition == null)
                {
                    reduceError = new ErrorRecord(reduceError.ErrorId, lookahead.Value.Span);
                }

                AddError(reduceError);
            }

#if HISTORY
            var to = m_topStack.StateIndex;
            History.Add(String.Format("R{0}:{1}", from, to));
#endif
        }
Esempio n. 3
0
        public ProductionInfoManager(IProduction root)
        {
            CodeContract.RequiresArgumentNotNull(root, "root");

            var aggregator  = new ProductionAggregationVisitor();
            var productions = root.Accept(aggregator, new List <IProduction>());

            m_productions  = productions.ToArray();
            RootProduction = root;

            var ffVisitor = new FirstFollowVisitor();

            bool isChanged;

            do
            {
                isChanged = false;

                foreach (var p in productions)
                {
                    isChanged = p.Accept(ffVisitor, isChanged);
                }
            } while (isChanged);
        }
Esempio n. 4
0
        public void Reduce(IProduction production, ReduceVisitor reducer, Lexeme lookahead)
        {
            #if HISTORY
            var from = m_topStack.StateIndex;
            #endif

            if (production == null)
            {
                //Accept
                Debug.Assert(m_topStack.PrevNode.StateIndex == 0);

                //TODO: accepted
                IsAccepted = true;
                return;
            }

            if (production.AggregatesAmbiguities)
            {
                AmbiguityAggregator = ((ProductionBase)production).CreateAggregator();
            }

            var reduceResult = production.Accept(reducer, m_topStack);

            m_topStack = reduceResult.NewTopStack;
            var reduceError = reduceResult.ReduceError;

            if (reduceError != null)
            {
                IncreaseErrorRecoverLevel();

                if (reduceError.ErrorPosition == null)
                {
                    reduceError = new ErrorRecord(reduceError.ErrorId, lookahead.Value.Span);
                }

                AddError(reduceError);
            }

            #if HISTORY
            var to = m_topStack.StateIndex;
            History.Add(String.Format("R{0}:{1}", from, to));
            #endif
        }
Esempio n. 5
0
        public void Reduce(IProduction production, ReduceVisitor reducer, Lexeme lookahead)
        {
            #if HISTORY
            var from = m_topStack.StateIndex;
            #endif

            if (production == null)
            {
                //Accept
                Debug.Assert(m_topStack.PrevNode.StateIndex == 0);

                //TODO: accepted
                IsAccepted = true;
                return;
            }

            if (Priority < production.Priority) Priority = production.Priority;

            var reduceResult = production.Accept(reducer, m_topStack);

            m_topStack = reduceResult.NewTopStack;
            var reduceError = reduceResult.ReduceError;

            if (reduceError != null)
            {
                IncreaseErrorRecoverLevel();

                if (reduceError.ErrorPosition == null)
                {
                    reduceError.ErrorPosition = lookahead.Span;
                }

                AddError(reduceError);
            }

            #if HISTORY
            var to = m_topStack.StateIndex;
            History.Add(String.Format("R{0}:{1}", from, to));
            #endif
        }