예제 #1
0
        public static void Closure(LRConfigSet ConfigSet)
        {
            LRConfigSet setB = new LRConfigSet();
            short       num3 = (short)(ConfigSet.Count() - 1);

            for (short i = 0; i <= num3; i = (short)(i + 1))
            {
                LRConfig           config2 = ConfigSet[i];
                LookaheadSymbolSet set     = TotalLookahead(config2);
                SymbolBuild        build   = config2.NextSymbol(0);
                if ((build != null) && (build.Type == SymbolType.Nonterminal))
                {
                    LRConfigSet partialClosure = build.PartialClosure;
                    short       num4           = (short)(partialClosure.Count() - 1);
                    for (short j = 0; j <= num4; j = (short)(j + 1))
                    {
                        LRConfig config = partialClosure[j];
                        LRConfig item   = new LRConfig(config.Parent, 0, config.LookaheadSet);
                        if (config.InheritLookahead)
                        {
                            item.LookaheadSet.UnionWith(set);
                        }
                        setB.Add(item);
                    }
                }
            }
            ConfigSet.UnionWith(setB);
        }
예제 #2
0
        private static void ComputeLRState(LRStateBuild State)
        {
            short       num2;
            SymbolBuild build2;
            short       num3 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);

            for (num2 = 0; num2 <= num3; num2 = (short)(num2 + 1))
            {
                GotoList[num2] = null;
            }
            short num4 = (short)(State.ConfigSet.Count() - 1);

            for (num2 = 0; num2 <= num4; num2 = (short)(num2 + 1))
            {
                LRConfig config = State.ConfigSet[num2];
                build2 = config.NextSymbol(0);
                if (build2 != null)
                {
                    short tableIndex = build2.TableIndex;
                    if (GotoList[tableIndex] == null)
                    {
                        GotoList[tableIndex] = new LRConfigSet();
                    }
                    LRConfig item = new LRConfig(config.Parent, config.Position + 1, config.LookaheadSet);
                    GotoList[tableIndex].Add(item);
                }
            }
            short num5 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);

            for (num2 = 0; num2 <= num5; num2 = (short)(num2 + 1))
            {
                if (GotoList[num2] == null)
                {
                    continue;
                }
                build2 = BuilderApp.BuildTables.Symbol[num2];
                Closure(GotoList[num2]);
                LRStateBuild state = new LRStateBuild
                {
                    ConfigSet = GotoList[num2]
                };
                switch (build2.Type)
                {
                case SymbolType.Nonterminal:
                {
                    State.Add(new LRAction(build2, LRActionType.Goto, CreateLRState(state)));
                    Notify.Analyzed++;
                    continue;
                }

                case SymbolType.End:
                {
                    State.Add(new LRAction(build2, LRActionType.Accept));
                    continue;
                }
                }
                State.Add(new LRAction(build2, LRActionType.Shift, CreateLRState(state)));
                Notify.Analyzed++;
            }
        }
예제 #3
0
 // Properties
 public int this[LRConfigSet Key]
 {
     get
     {
         int index = ItemIndex(Key);
         if (index != -1)
         {
             return(m_List[index].TableIndex);
         }
         return(-1);
     }
 }
예제 #4
0
        private static int InsertIndex(LRConfigSet Key)
        {
            if (m_Count == 0)
            {
                return(0);
            }
            if (Key.IsLessThan(m_List[0].Key))
            {
                return(0);
            }
            if (Key.IsGreaterThan(m_List[m_Count - 1].Key))
            {
                return(m_Count);
            }
            int  num5 = m_Count - 1;
            int  num3 = 0;
            int  num  = -1;
            bool flag = false;

            do
            {
                int index = (int)Math.Round((double)(((double)(num3 + num5)) / 2.0));
                if (num3 > num5)
                {
                    num  = num3;
                    flag = true;
                }
                else if (m_List[index].Key.IsEqualTo(Key))
                {
                    num  = -1;
                    flag = true;
                }
                else if (m_List[index].Key.IsLessThan(Key))
                {
                    num3 = index + 1;
                }
                else
                {
                    num5 = index - 1;
                }
            }while (!flag);
            return(num);
        }
예제 #5
0
        // Methods
        public static void Add(LRConfigSet Key, int TableIndex = 0)
        {
            int index = InsertIndex(Key);

            if (index != -1)
            {
                ConfigSetLookupItem item;
                item.Key        = Key;
                item.TableIndex = TableIndex;
                m_Count++;
                m_List = (ConfigSetLookupItem[])Utils.CopyArray((Array)m_List, new ConfigSetLookupItem[(m_Count - 1) + 1]);
                int num3 = index + 1;
                for (int i = m_Count - 1; i >= num3; i += -1)
                {
                    m_List[i] = m_List[i - 1];
                }
                m_List[index] = item;
            }
        }
예제 #6
0
        private static LRConfigSet GetClosureConfigSet(SymbolBuild Sym)
        {
            bool            flag;
            LRConfig        config;
            short           num2;
            SymbolBuild     build;
            LRConfig        config2;
            ProductionBuild build2;
            LRConfigSet     setB = new LRConfigSet();
            LRConfigSet     set  = new LRConfigSet();
            short           num3 = (short)(BuilderApp.BuildTables.Production.Count() - 1);
            short           num  = 0;

            while (num <= num3)
            {
                build2 = BuilderApp.BuildTables.Production[num];
                if (build2.Head.IsEqualTo(Sym))
                {
                    config2 = new LRConfig
                    {
                        Position         = 0,
                        Modified         = true,
                        LookaheadSet     = new LookaheadSymbolSet(),
                        Parent           = build2,
                        InheritLookahead = true
                    };
                    set.Add(config2);
                }
                num = (short)(num + 1);
            }
            do
            {
                setB.Clear();
                flag = false;
                short num4 = (short)(set.Count() - 1);
                num2 = 0;
                while (num2 <= num4)
                {
                    config = set[num2];
                    if (!config.IsComplete() & config.Modified)
                    {
                        build = config.NextSymbol(0);
                        if (build.Type == SymbolType.Nonterminal)
                        {
                            short num5 = (short)(BuilderApp.BuildTables.Production.Count() - 1);
                            num = 0;
                            while (num <= num5)
                            {
                                build2 = BuilderApp.BuildTables.Production[num];
                                if (build2.Head.IsEqualTo(build))
                                {
                                    config2 = new LRConfig(build2, 0, TotalLookahead(config));
                                    setB.Add(config2);
                                }
                                num = (short)(num + 1);
                            }
                        }
                        set[num2].Modified = false;
                    }
                    num2 = (short)(num2 + 1);
                }
            }while (set.UnionWith(setB));
            do
            {
                flag = false;
                short num6 = (short)(set.Count() - 1);
                for (num2 = 0; num2 <= num6; num2 = (short)(num2 + 1))
                {
                    config = set[num2];
                    build  = config.NextSymbol(0);
                    if ((build != null) && ((config.InheritLookahead & PopulateLookahead(config)) & (build.Type == SymbolType.Nonterminal)))
                    {
                        short num7 = (short)(set.Count() - 1);
                        for (num = 0; num <= num7; num = (short)(num + 1))
                        {
                            config = set[num];
                            if (((config.Position == 0) & config.Parent.Head.IsEqualTo(build)) & !config.InheritLookahead)
                            {
                                config.InheritLookahead = true;
                                flag = true;
                            }
                        }
                    }
                }
            }while (flag);
            return(set);
        }