Пример #1
0
        bool IProductionVisitor <bool, bool> .VisitConcatenation <T1, T2, TR>(ConcatenationProduction <T1, T2, TR> concatenationProduction, bool IsChanged)
        {
            var p1 = concatenationProduction.ProductionLeft;
            var p2 = concatenationProduction.ProductionRight;

            var info  = concatenationProduction.Info;
            var info1 = p1.Info;
            var info2 = p2.Info;

            IsChanged = info.First.UnionCheck(info1.First) || IsChanged;

            if (info1.IsNullable)
            {
                IsChanged = info.First.UnionCheck(info2.First) || IsChanged;
            }

            if (info2.IsNullable)
            {
                IsChanged = info1.Follow.UnionCheck(info.Follow) || IsChanged;
            }

            IsChanged = info2.Follow.UnionCheck(info.Follow) || IsChanged;
            IsChanged = info1.Follow.UnionCheck(info2.First) || IsChanged;

            bool isNullable = info1.IsNullable && info2.IsNullable;

            if (info.IsNullable != isNullable)
            {
                IsChanged       = true;
                info.IsNullable = isNullable;
            }

            return(IsChanged);
        }
Пример #2
0
        bool IProductionVisitor <ClosureInfo, bool> .VisitConcatenation <T1, T2, TR>(ConcatenationProduction <T1, T2, TR> concatenationProduction, ClosureInfo arg)
        {
            switch (arg.DotLocation)
            {
            case 0:
                if (!concatenationProduction.ProductionLeft.IsTerminal)
                {
                    arg.IsChanged = arg.LR0ItemSet.Add(new LR0Item(concatenationProduction.ProductionLeft.Info.Index, 0)) || arg.IsChanged;
                }
                break;

            case 1:
                if (!concatenationProduction.ProductionRight.IsTerminal)
                {
                    arg.IsChanged = arg.LR0ItemSet.Add(new LR0Item(concatenationProduction.ProductionRight.Info.Index, 0)) || arg.IsChanged;
                }
                break;

            default:
                //no symbol at position
                break;
            }

            return(arg.IsChanged);
        }
Пример #3
0
        string IProductionVisitor <int, string> .VisitConcatenation <T1, T2, TR>(ConcatenationProduction <T1, T2, TR> concatenationProduction, int DotLocation)
        {
            switch (DotLocation)
            {
            case 0:
                return(String.Format("{0} ::=.{1} {2}", concatenationProduction.DebugName,
                                     concatenationProduction.ProductionLeft.DebugName,
                                     concatenationProduction.ProductionRight.DebugName));

            case 1:
                return(String.Format("{0} ::= {1}.{2}", concatenationProduction.DebugName,
                                     concatenationProduction.ProductionLeft.DebugName,
                                     concatenationProduction.ProductionRight.DebugName));

            default:
                return(concatenationProduction.ToString() + '.');
            }
        }
Пример #4
0
        IReadOnlyList <IProduction> IProductionVisitor <int, IReadOnlyList <IProduction> > .VisitConcatenation <T1, T2, TR>(ConcatenationProduction <T1, T2, TR> concatenationProduction, int DotLocation)
        {
            switch (DotLocation)
            {
            case 0:
                return(new IProduction[1] {
                    concatenationProduction.ProductionLeft
                });

            case 1:
                return(new IProduction[1] {
                    concatenationProduction.ProductionRight
                });

            default:
                return(s_empty);
            }
        }
Пример #5
0
        bool IProductionVisitor <Tuple <int, bool, ISet <LR0Item> >, bool> .VisitConcatenation <T1, T2, TR>(ConcatenationProduction <T1, T2, TR> concatenationProduction, Tuple <int, bool, ISet <LR0Item> > arg)
        {
            int            DotLocation = arg.Item1;
            bool           IsChanged   = arg.Item2;
            ISet <LR0Item> LR0ItemSet  = arg.Item3;

            switch (DotLocation)
            {
            case 0:
                if (!concatenationProduction.ProductionLeft.IsTerminal)
                {
                    IsChanged = LR0ItemSet.Add(new LR0Item(concatenationProduction.ProductionLeft.Info.Index, 0)) || IsChanged;
                }
                break;

            case 1:
                if (!concatenationProduction.ProductionRight.IsTerminal)
                {
                    IsChanged = LR0ItemSet.Add(new LR0Item(concatenationProduction.ProductionRight.Info.Index, 0)) || IsChanged;
                }
                break;

            default:
                //no symbol at position
                break;
            }

            return(IsChanged);
        }
Пример #6
0
        List <IProduction> IProductionVisitor <List <IProduction>, List <IProduction> > .VisitConcatenation <T1, T2, TR>(ConcatenationProduction <T1, T2, TR> concatenationProduction, List <IProduction> Productions)
        {
            if (concatenationProduction.Info != null)
            {
                return(Productions);
            }

            concatenationProduction.Info = new ProductionInfo();

            concatenationProduction.ProductionLeft.Accept(this, Productions);
            concatenationProduction.ProductionRight.Accept(this, Productions);

            concatenationProduction.Info.Index       = Productions.Count;
            concatenationProduction.Info.SymbolCount = 2;
            Productions.Add(concatenationProduction);

            return(Productions);
        }