private StringBuilder DescribeState(MutableDotItemSet state, StringBuilder output, string indent)
        {
            foreach (var item in state)
            {
                output.Append(indent);
                DescribeItem(item, output).AppendLine();
            }

            return(output);
        }
示例#2
0
        private MutableDotItemSet GoTo(IEnumerable <DotItem> itemSet, int token)
        {
            var result = new MutableDotItemSet();

            foreach (var item in itemSet)
            {
                if (item.NextToken == token)
                {
                    result.Add(item.CreateNextItem());
                }
            }

            return(ClosureLr0(result));
        }
示例#3
0
        // TODO: Separate Closure from the lookahead closuring to get cached closure item sets
        private MutableDotItemSet ClosureLr0(MutableDotItemSet itemSet)
        {
            var result = new MutableDotItemSet();

            result.AddRange(itemSet);

            bool modified;

            do
            {
                modified = false;

                // result may grow during iterations
                for (int i = 0; i != result.Count; ++i)
                {
                    var item = result[i];

                    if (!item.IsReduce && !grammar.IsTerminal(item.NextToken))
                    {
                        int X = item.NextToken;

                        foreach (var childProd in grammar.GetProductions(X))
                        {
                            var newItem = new DotItem(childProd, 0)
                            {
                                LA = TokenSet.Mutable()
                            };

                            var index = result.IndexOf(newItem);
                            if (index < 0)
                            {
                                result.Add(newItem);
                                modified = true;
                            }
                            else
                            {
                                var existing = result[index];
                                existing.LA.AddAll(newItem.LA);
                            }
                        }
                    }
                }
            }while (modified);

            return(result);
        }
示例#4
0
        private MutableDotItemSet GoTo(IEnumerable<DotItem> itemSet, int token)
        {
            var result = new MutableDotItemSet();

            foreach (var item in itemSet)
            {
                if (item.NextToken == token)
                {
                    result.Add(item.CreateNextItem());
                }
            }

            return ClosureLr0(result);
        }
示例#5
0
        // TODO: Separate Closure from the lookahead closuring to get cached closure item sets
        private MutableDotItemSet ClosureLr0(MutableDotItemSet itemSet)
        {
            var result = new MutableDotItemSet();
            result.AddRange(itemSet);

            bool modified;

            do
            {
                modified = false;

                // result may grow during iterations
                for (int i = 0; i != result.Count; ++i)
                {
                    var item = result[i];

                    if (!item.IsReduce && !grammar.IsTerminal(item.NextToken))
                    {
                        int X = item.NextToken;

                        foreach (var childProd in grammar.GetProductions(X))
                        {
                            var newItem = new DotItem(childProd, 0)
                            {
                                LA = TokenSet.Mutable()
                            };

                            var index = result.IndexOf(newItem);
                            if (index < 0)
                            {
                                result.Add(newItem);
                                modified = true;
                            }
                            else
                            {
                                var existing = result[index];
                                existing.LA.AddAll(newItem.LA);
                            }
                        }
                    }
                }
            }
            while (modified);

            return result;
        }