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); }
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 }
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); }
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 }