Esempio n. 1
0
 public void AddRowState(RowState row)
 {
     if (!RowStates.Contains(row))
     {
         RowStates.Add(row);
     }
 }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            if (obj is State state)
            {
                var result = RowStates.SetEquals(state.RowStates);
                return(result);
            }

            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// the order is horrible. I did this to support Recursive LL(1) Grammers
        /// Error :Collection was modified.
        /// </summary>
        public void AddClosures()
        {
            bool changed;

            do
            {
                changed = false;
                foreach (RowState state in RowStates.ToList())
                {
                    if (state.GetSymbolInPosition() is Variable variable)
                    {
                        var defaultLookAhead = state.LookAhead;
                        // if there is no B,
                        if (_isClr && state.HasSymbolAfterPosition())
                        {
                            //first (B{PreviousLookAhead})
                            var symbolsAfterPosition = state.GetSymbolsAfterPosition().ToList();
                            //symbolsAfterPosition.AddRange(defaultLookAhead);
                            defaultLookAhead = _preprocessor.FirstSet(new List <IEnumerable <ISymbol> > {
                                symbolsAfterPosition
                            });
                            if (defaultLookAhead.Contains(Terminal.Epsilon))
                            {
                                defaultLookAhead.Remove(Terminal.Epsilon);
                                defaultLookAhead.AddRange(state.LookAhead);
                            }
                        }
                        variable.RuleSet.Definitions
                        .ForEach(rule =>
                        {
                            RowState rowState = new RowState(variable, rule);
                            if (_isClr)
                            {
                                rowState = new RowState(variable, rule, defaultLookAhead);
                            }
                            if (!RowStates.Contains(rowState))
                            {
                                RowStates.Add(rowState);
                                changed = true;
                            }
                        });
                    }
                }
            } while (changed);
        }