Ejemplo n.º 1
0
        private static LookaheadSymbolSet TotalLookahead(LRConfig Config)
        {
            bool flag;
            LookaheadSymbolSet set = new LookaheadSymbolSet();

            for (int i = 0; (i < Config.CheckaheadCount()) & !flag; i++)
            {
                short offset = (short)i;
                i = offset;
                SymbolBuild       build  = Config.Checkahead(offset);
                ConfigTrackSource source = (ConfigTrackSource)Conversions.ToInteger(Interaction.IIf(build.Type == SymbolType.Nonterminal, ConfigTrackSource.First, ConfigTrackSource.Config));
                int num4 = build.First.Count() - 1;
                for (int j = 0; j <= num4; j++)
                {
                    LookaheadSymbol item = new LookaheadSymbol(build.First[j]);
                    if (item.Parent.Type != SymbolType.Nonterminal)
                    {
                        item.Configs.Add(new ConfigTrack(Config, source));
                        set.Add(item);
                    }
                }
                flag = !build.Nullable;
            }
            if (!flag)
            {
                set.UnionWith(Config.LookaheadSet);
            }
            return(set);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private static void RecomputeLRState(LRStateBuild State)
        {
            short num2 = (short)(State.Count - 1);

            for (short i = 0; i <= num2; i = (short)(i + 1))
            {
                LRAction action = State[i];
                switch (((int)action.Type()))
                {
                case 1:
                case 3:
                {
                    Symbol      symbol    = action.Symbol;
                    SymbolBuild theSymbol = (SymbolBuild)symbol;
                    symbol = theSymbol;
                    LRStateBuild build  = GotoSymbol(State, theSymbol);
                    LRStateBuild build2 = BuilderApp.BuildTables.LALR[action.Value()];
                    if (build.ConfigSet.CompareCore(build2.ConfigSet) == LRConfigCompare.EqualCore)
                    {
                        build2.ConfigSet.UnionWith(build.ConfigSet);
                        build2.Modified = true;
                    }
                    Notify.Analyzed++;
                    break;
                }
                }
            }
        }
Ejemplo n.º 4
0
        private static void SetupNullableTable()
        {
            bool  flag;
            short num3 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);
            short num  = 0;

            while (num <= num3)
            {
                BuilderApp.BuildTables.Symbol[num].Nullable = false;
                num = (short)(num + 1);
            }
            do
            {
                flag = false;
                short num4 = (short)(BuilderApp.BuildTables.Production.Count() - 1);
                for (num = 0; num <= num4; num = (short)(num + 1))
                {
                    ProductionBuild build = BuilderApp.BuildTables.Production[num];
                    bool            flag2 = true;
                    for (short i = 0; (i < build.Handle().Count()) & flag2; i = (short)(i + 1))
                    {
                        SymbolBuild build2 = build.Handle()[i];
                        if (!build2.Nullable)
                        {
                            flag2 = false;
                        }
                    }
                    if (flag2 & !build.Head.Nullable)
                    {
                        build.Head.Nullable = true;
                        flag = true;
                    }
                }
            }while (flag);
        }
Ejemplo n.º 5
0
        private static void ComputePartialClosures()
        {
            short num2;
            short num3 = 0;
            short num4 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);

            for (num2 = 0; num2 <= num4; num2 = (short)(num2 + 1))
            {
                if (BuilderApp.BuildTables.Symbol[num2].Type == SymbolType.Nonterminal)
                {
                    num3 = (short)(num3 + 1);
                }
            }
            short num  = 0;
            short num5 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);

            for (num2 = 0; num2 <= num5; num2 = (short)(num2 + 1))
            {
                SymbolBuild sym = BuilderApp.BuildTables.Symbol[num2];
                if (sym.Type == SymbolType.Nonterminal)
                {
                    num                = (short)(num + 1);
                    Notify.Text        = Conversions.ToString((int)num) + " of " + Conversions.ToString((int)num3);
                    sym.PartialClosure = GetClosureConfigSet(sym);
                }
            }
        }
Ejemplo n.º 6
0
        public static void CreateNFAStates(SymbolBuild Sym)
        {
            short target = (short)AddState();
            short num3   = (short)AddState();
            short num4   = (short)(Sym.RegularExp.Count() - 1);

            for (short i = 0; i <= num4; i = (short)(i + 1))
            {
                RegExpSeq    seq  = Sym.RegularExp[i];
                AutomataType type = CreateAutomataSeq(seq);
                NFA[target].AddLambdaEdge(type.Head);
                NFA[type.Tail].AddLambdaEdge(num3);
                NFA[type.Tail].AcceptList.Add(Sym.TableIndex, seq.Priority);
            }
            NFA[Root].AddLambdaEdge(target);
        }
Ejemplo n.º 7
0
        private static LRStateBuild CreateInitialState(Symbol StartSymbol)
        {
            ProductionBuild rule        = new ProductionBuild();
            SymbolBuild     nonTerminal = new SymbolBuild
            {
                Type = SymbolType.Nonterminal,
                Name = "S'"
            };

            rule.SetHead(nonTerminal);
            rule.Handle().Add((SymbolBuild)StartSymbol);
            rule.Handle().Add((SymbolBuild)BuilderApp.BuildTables.Symbol.GetFirstOfType(SymbolType.End));
            LRConfig     item   = new LRConfig(rule);
            LRStateBuild build3 = new LRStateBuild();

            build3.ConfigSet.Add(item);
            build3.Expanded = false;
            Closure(build3.ConfigSet);
            return(build3);
        }
Ejemplo n.º 8
0
        private static LRStateBuild GotoSymbol(LRStateBuild State, SymbolBuild TheSymbol)
        {
            LRStateBuild build2 = new LRStateBuild();
            short        num2   = (short)(State.ConfigSet.Count() - 1);

            for (short i = 0; i <= num2; i = (short)(i + 1))
            {
                LRConfig config = State.ConfigSet[i];
                Symbol   symbol = config.NextSymbol(0);
                if ((symbol != null) && symbol.IsEqualTo(TheSymbol))
                {
                    LRConfig item = new LRConfig(config.Parent, config.Position + 1, config.LookaheadSet);
                    build2.ConfigSet.Add(item);
                }
            }
            if (build2.ConfigSet.Count() >= 1)
            {
                Closure(build2.ConfigSet);
            }
            return(build2);
        }
Ejemplo n.º 9
0
        private bool LoadVer1(SimpleDB.Reader CGT)
        {
            int  num3;
            bool flag2 = true;

            while (!(CGT.EndOfFile() | !flag2))
            {
                int num7;
                int num8;
                int num10;
                int num14;
                int num15;
                CGT.GetNextRecord();
                switch (CGT.RetrieveByte())
                {
                case 0x43:
                {
                    int num5 = CGT.RetrieveInt16();
                    CharacterSetBuild build5 = new CharacterSetBuild(CGT.RetrieveString())
                    {
                        TableIndex = num5
                    };
                    base.m_CharSet[num5] = build5;
                    continue;
                }

                case 0x44:
                {
                    FAState state = new FAState();
                    num10 = CGT.RetrieveInt16();
                    bool flag3 = CGT.RetrieveBoolean();
                    int  num9  = CGT.RetrieveInt16();
                    CGT.RetrieveEntry();
                    if (!flag3)
                    {
                        goto Label_02DC;
                    }
                    base.m_DFA[num10] = new FAStateBuild((SymbolBuild)base.m_Symbol[num9]);
                    goto Label_0337;
                }

                case 0x49:
                {
                    base.m_DFA.InitialState  = (short)CGT.RetrieveInt16();
                    base.m_LALR.InitialState = (short)CGT.RetrieveInt16();
                    continue;
                }

                case 0x4c:
                    num14 = CGT.RetrieveInt16();
                    CGT.RetrieveEntry();
                    base.m_LALR[num14] = new LRStateBuild();
                    goto Label_03BA;

                case 80:
                {
                    base.m_Properties["Name"].Value           = CGT.RetrieveString();
                    base.m_Properties["Version"].Value        = CGT.RetrieveString();
                    base.m_Properties["Author"].Value         = CGT.RetrieveString();
                    base.m_Properties["About"].Value          = CGT.RetrieveString();
                    base.m_Properties["Case Sensitive"].Value = Conversions.ToString(CGT.RetrieveBoolean());
                    num3 = CGT.RetrieveInt16();
                    continue;
                }

                case 0x52:
                {
                    num7 = CGT.RetrieveInt16();
                    int num6 = CGT.RetrieveInt16();
                    CGT.RetrieveEntry();
                    base.m_Production[num7] = new ProductionBuild((SymbolBuild)base.m_Symbol[num6], (short)num7);
                    goto Label_0272;
                }

                case 0x53:
                {
                    int        tableIndex = CGT.RetrieveInt16();
                    string     name       = CGT.RetrieveString();
                    SymbolType type       = (SymbolType)CGT.RetrieveInt16();
                    base.m_Symbol[tableIndex] = new SymbolBuild(name, type, tableIndex);
                    continue;
                }

                case 0x54:
                {
                    base.m_Symbol     = new SymbolBuildList(CGT.RetrieveInt16());
                    base.m_CharSet    = new CharacterSetBuildList(CGT.RetrieveInt16());
                    base.m_Production = new ProductionBuildList(CGT.RetrieveInt16());
                    base.m_DFA        = new FAStateBuildList(CGT.RetrieveInt16());
                    base.m_LALR       = new LRStateBuildList(CGT.RetrieveInt16());
                    continue;
                }

                default:
                    goto Label_03CB;
                }
Label_0244:
                num8 = CGT.RetrieveInt16();
                base.m_Production[num7].Handle().Add(base.m_Symbol[num8]);
Label_0272:
                if (!CGT.RecordComplete())
                {
                    goto Label_0244;
                }
                continue;
Label_02DC:
                base.m_DFA[num10] = new FAStateBuild();
Label_0337:
                while (!CGT.RecordComplete())
                {
                    int num11  = CGT.RetrieveInt16();
                    int target = CGT.RetrieveInt16();
                    CGT.RetrieveEntry();
                    base.m_DFA[num10].AddEdge(new FAEdgeBuild((CharacterSetBuild)base.m_CharSet[num11], target));
                }
                continue;
Label_0370:
                num15 = CGT.RetrieveInt16();
                int num13 = CGT.RetrieveInt16();
                int num16 = CGT.RetrieveInt16();
                CGT.RetrieveEntry();
                base.m_LALR[num14].Add(new LRAction(base.m_Symbol[num15], (LRActionType)num13, (short)num16));
Label_03BA:
                if (!CGT.RecordComplete())
                {
                    goto Label_0370;
                }
                continue;
Label_03CB:
                flag2 = false;
            }
            this.StartSymbol = base.m_Symbol[num3];
            SymbolBuild build3 = null;
            SymbolBuild build2 = null;
            SymbolBuild build  = null;
            int         num19  = base.m_Symbol.Count() - 1;

            for (int i = 0; i <= num19; i++)
            {
                SymbolBuild build4 = (SymbolBuild)base.m_Symbol[i];
                switch (((int)build4.Type))
                {
                case 2:
                    if (build == null)
                    {
                        build = build4;
                    }
                    break;

                case 4:
                    build3 = build4;
                    break;

                case 5:
                    build2 = build4;
                    break;
                }
            }
            if (build3 != null)
            {
                GroupBuild item  = new GroupBuild();
                int        num17 = base.m_Group.Add(item);
                item.TableIndex = 0;
                item.Name       = "Comment Block";
                item.Container  = build;
                item.Nesting.Add(item.TableIndex);
                item.Advance      = AdvanceMode.Token;
                item.Ending       = EndingMode.Closed;
                item.Start        = build3;
                item.End          = build2;
                item.Start.Group  = item;
                item.End.Group    = item;
                item.NestingNames = "All";
            }
            return(flag2);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        private static void ComputeReductions()
        {
            LRConflictItem[] itemArray = new LRConflictItem[BuilderApp.BuildTables.Symbol.Count() + 1];
            short            num4      = (short)(BuilderApp.BuildTables.LALR.Count - 1);

            for (short i = 0; i <= num4; i = (short)(i + 1))
            {
                LRConflict   shiftReduce;
                LRStateBuild build = BuilderApp.BuildTables.LALR[i];
                short        num5  = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);
                short        index = 0;
                while (index <= num5)
                {
                    itemArray[index] = new LRConflictItem(BuilderApp.BuildTables.Symbol[index]);
                    index            = (short)(index + 1);
                }
                short num6 = (short)(build.ConfigSet.Count() - 1);
                short num2 = 0;
                while (num2 <= num6)
                {
                    short    num7;
                    LRConfig item = build.ConfigSet[num2];
                    switch (((int)item.NextAction()))
                    {
                    case 1:
                        itemArray[item.NextSymbol(0).TableIndex].Shifts.Add(item);
                        goto Label_0137;

                    case 2:
                        num7  = (short)(item.LookaheadSet.Count() - 1);
                        index = 0;
                        goto Label_012D;

                    default:
                        goto Label_0137;
                    }
Label_0100:
                    itemArray[item.LookaheadSet[index].Parent.TableIndex].Reduces.Add(item);
                    index = (short)(index + 1);
Label_012D:
                    if (index <= num7)
                    {
                        goto Label_0100;
                    }
Label_0137:
                    num2 = (short)(num2 + 1);
                }
                short num8 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);
                index = 0;
                while (index <= num8)
                {
                    if ((itemArray[index].Shifts.Count() >= 1) & (itemArray[index].Reduces.Count() >= 1))
                    {
                        short num9 = (short)(itemArray[index].Shifts.Count() - 1);
                        num2 = 0;
                        while (num2 <= num9)
                        {
                            itemArray[index].Shifts[num2].Status = LRStatus.Warning;
                            num2 = (short)(num2 + 1);
                        }
                        short num10 = (short)(itemArray[index].Reduces.Count() - 1);
                        num2 = 0;
                        while (num2 <= num10)
                        {
                            itemArray[index].Reduces[num2].Status = LRStatus.Warning;
                            num2 = (short)(num2 + 1);
                        }
                        build.Status = LRStatus.Warning;
                        build.Note   = "Shift-Reduce Conflict";
                        build.ConflictList.Add(new LRConflictItem(itemArray[index], LRConflict.ShiftReduce));
                        shiftReduce = LRConflict.ShiftReduce;
                        BuilderApp.Log.Add(SysLogSection.LALR, SysLogAlert.Warning, "A Shift-Reduce Conflict was fixed", BuilderApp.BuildTables.Symbol[index].Text(false) + " can follow a completed rule and also be shifted." + GetConflictResolvedDesc(shiftReduce), Conversions.ToString((int)i));
                    }
                    index = (short)(index + 1);
                }
                short num11 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);
                for (index = 0; index <= num11; index = (short)(index + 1))
                {
                    if ((itemArray[index].Reduces.Count() == 1) & (itemArray[index].Shifts.Count() == 0))
                    {
                        SymbolBuild theSymbol = BuilderApp.BuildTables.Symbol[index];
                        build.Add(new LRAction(theSymbol, LRActionType.Reduce, itemArray[index].Reduces[0].Parent.TableIndex));
                    }
                    else if (itemArray[index].Reduces.Count() > 1)
                    {
                        short num12 = (short)(itemArray[index].Reduces.Count() - 1);
                        for (num2 = 0; num2 <= num12; num2 = (short)(num2 + 1))
                        {
                            itemArray[index].Reduces[num2].Status = LRStatus.Critical;
                        }
                        build.Status = LRStatus.Critical;
                        build.Note   = "Reduce-Reduce Conflict";
                        build.ConflictList.Add(new LRConflictItem(itemArray[index], LRConflict.ReduceReduce));
                        shiftReduce = LRConflict.ReduceReduce;
                        BuilderApp.Log.Add(SysLogSection.LALR, SysLogAlert.Critical, "Reduce-Reduce Conflict", BuilderApp.BuildTables.Symbol[index].Text(false) + " can follow more than one completed rule. " + GetConflictDesc(shiftReduce), Conversions.ToString((int)i));
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public static void Build()
        {
            short tableIndex = BuilderApp.BuildTables.StartSymbol.TableIndex;

            if (tableIndex == -1)
            {
                BuilderApp.Log.Add(SysLogSection.LALR, SysLogAlert.Critical, "Start symbol is invalid or missing");
            }
            else
            {
                Notify.Started("Computing LALR Tables");
                SymbolBuild build = BuilderApp.BuildTables.Symbol[tableIndex];
                BuilderApp.BuildTables.LALR.Clear();
                SetupTempTables();
                if (build.First.Count() >= 1)
                {
                    short        count;
                    bool         flag;
                    int          num2;
                    LRStateBuild build2;
                    BuilderApp.Mode = BuilderApp.ProgramMode.BuildingLALR;
                    Symbol startSymbol = build;
                    build = (SymbolBuild)startSymbol;
                    CreateLRState(CreateInitialState(startSymbol));
                    do
                    {
                        flag  = true;
                        count = (short)BuilderApp.BuildTables.LALR.Count;
                        int num4 = count - 1;
                        num2 = 0;
                        while (num2 <= num4)
                        {
                            build2 = BuilderApp.BuildTables.LALR[num2];
                            if (!build2.Expanded)
                            {
                                flag            = false;
                                build2.Expanded = true;
                                ComputeLRState(build2);
                            }
                            num2++;
                        }
                    }while (!flag);
                    do
                    {
                        flag  = true;
                        count = (short)BuilderApp.BuildTables.LALR.Count;
                        int num5 = count - 1;
                        for (num2 = 0; num2 <= num5; num2++)
                        {
                            build2 = BuilderApp.BuildTables.LALR[num2];
                            if (build2.Modified)
                            {
                                flag            = false;
                                build2.Modified = false;
                                RecomputeLRState(build2);
                            }
                        }
                    }while (!flag);
                    ComputeReductions();
                    Notify.Completed("LALR Tables Completed");
                }
                else
                {
                    BuilderApp.Log.Add(SysLogSection.LALR, SysLogAlert.Critical, "Rule <" + build.Name + "> does not produce any terminals.");
                }
                ClearTempTables();
            }
        }
Ejemplo n.º 13
0
        private static void CheckErrorsDFA()
        {
            short        num2;
            FAStateBuild build;
            bool         flag = false;

            if (!flag && (BuilderApp.BuildTables.DFA[StartState].AcceptList.Count() > 0))
            {
                short num3 = (short)(BuilderApp.BuildTables.DFA[StartState].AcceptList.Count() - 1);
                for (num2 = 0; num2 <= num3; num2 = (short)(num2 + 1))
                {
                    BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Critical, "The terminal '" + BuilderApp.BuildTables.Symbol[BuilderApp.BuildTables.DFA[StartState].AcceptList[num2].SymbolIndex].Name + "' can be zero length", "The definition of this terminal allows it to contain no characters.", "");
                }
                flag = true;
            }
            if (!flag)
            {
                short num4 = (short)(BuilderApp.BuildTables.DFA.Count - 1);
                for (num2 = 0; num2 <= num4; num2 = (short)(num2 + 1))
                {
                    build = BuilderApp.BuildTables.DFA[num2];
                    if (build.AcceptList.Count() >= 2)
                    {
                        string title = "DFA State " + Conversions.ToString((int)num2) + ": Cannot distinguish between: ";
                        short  num5  = (short)(build.AcceptList.Count() - 1);
                        for (short i = 0; i <= num5; i = (short)(i + 1))
                        {
                            title = title + BuilderApp.BuildTables.Symbol[build.AcceptList[i].SymbolIndex].Name + " ";
                        }
                        BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Critical, title, ConflictDesc(), Conversions.ToString((int)num2));
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                short num6 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);
                for (num2 = 0; num2 <= num6; num2 = (short)(num2 + 1))
                {
                    BuilderApp.BuildTables.Symbol[num2].Accepted = false;
                }
                short num7 = (short)(BuilderApp.BuildTables.DFA.Count - 1);
                for (num2 = 0; num2 <= num7; num2 = (short)(num2 + 1))
                {
                    build = BuilderApp.BuildTables.DFA[num2];
                    if (build.AcceptList.Count() != 0)
                    {
                        BuilderApp.BuildTables.Symbol[build.AcceptList[0].SymbolIndex].Accepted = true;
                    }
                }
                short num8 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);
                for (num2 = 0; num2 <= num8; num2 = (short)(num2 + 1))
                {
                    SymbolBuild build2 = BuilderApp.BuildTables.Symbol[num2];
                    if (!build2.Accepted & build2.UsesDFA)
                    {
                        BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Critical, "Unaccepted terminal: " + build2.Name, "The terminal " + build2.Name + " cannot be accepted by the DFA.", "");
                    }
                    build2 = null;
                }
            }
            if (!flag)
            {
                BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Success, "The DFA State Table was successfully created", "The table contains a total of " + Conversions.ToString(BuilderApp.BuildTables.DFA.Count) + " states", "");
            }
        }
Ejemplo n.º 14
0
        public static void Build()
        {
            short     num3;
            NumberSet nFAList = new NumberSet(new int[0]);
            NumberSet set2    = new NumberSet(new int[0]);

            Notify.Started("Computing DFA States");
            SetupForNFA();
            BuilderApp.Mode = BuilderApp.ProgramMode.BuildingNFA;
            short num5 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);

            for (num3 = 0; num3 <= num5; num3 = (short)(num3 + 1))
            {
                SymbolBuild sym = BuilderApp.BuildTables.Symbol[num3];
                if (sym.UsesDFA)
                {
                    Notify.Text = sym.Name;
                    CreateNFAStates(sym);
                }
            }
            BuilderApp.Mode = BuilderApp.ProgramMode.NFAClosure;
            short num6 = (short)(NFA.Count - 1);

            for (num3 = 0; num3 <= num6; num3 = (short)(num3 + 1))
            {
                NumberSet reachable = new NumberSet(new int[0]);
                reachable.Add(new int[] { num3 });
                ClosureNFA(reachable);
                NFA[num3].NFAClosure = reachable;
            }
            BuilderApp.BuildTables.CharSet.Clear();
            if (NFA.Count <= 1)
            {
                BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Critical, "There are no terminals in the grammar");
            }
            else
            {
                short num2;
                BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Detail, "The initial Nondeterministic Finite Automata has " + Conversions.ToString(NFA.Count) + " states");
                BuilderApp.BuildTables.DFA.Clear();
                BuilderApp.Mode = BuilderApp.ProgramMode.NFACase;
                SetupMapCaseCharTables(BuilderApp.BuildTables.Properties["Case Sensitive"].Value.ToUpper() == "TRUE", BuilderApp.GetParamCharMapping());
                BuilderApp.Mode = BuilderApp.ProgramMode.BuildingDFA;
                nFAList.Add(new int[] { Root });
                StartState = BuildDFAState(nFAList);
                short num7 = (short)(BuilderApp.BuildTables.DFA.Count - 1);
                for (num3 = 0; num3 <= num7; num3 = (short)(num3 + 1))
                {
                    short num8 = (short)(BuilderApp.BuildTables.DFA[num3].Edges().Count() - 1);
                    num2 = 0;
                    while (num2 <= num8)
                    {
                        FAEdgeBuild       build3     = BuilderApp.BuildTables.DFA[num3].Edges()[num2];
                        CharacterSetBuild characters = build3.Characters;
                        build3.Characters = characters;
                        short num4 = BuilderApp.AddCharacterSet(characters);
                        BuilderApp.BuildTables.DFA[num3].Edges()[num2].Characters = BuilderApp.BuildTables.CharSet[num4];
                        num2 = (short)(num2 + 1);
                    }
                }
                short num9 = (short)(BuilderApp.BuildTables.DFA.Count - 1);
                for (num3 = 0; num3 <= num9; num3 = (short)(num3 + 1))
                {
                    FAStateBuild build = BuilderApp.BuildTables.DFA[num3];
                    if (build.AcceptList.Count() == 0)
                    {
                        build.Accept = null;
                    }
                    else if (build.AcceptList.Count() == 1)
                    {
                        build.Accept = BuilderApp.BuildTables.Symbol[build.AcceptList[0].SymbolIndex];
                    }
                    else
                    {
                        FAAccept accept = build.AcceptList[0];
                        set2.Clear();
                        set2.Add(new int[] { accept.SymbolIndex });
                        short priority = accept.Priority;
                        short num10    = (short)(build.AcceptList.Count() - 1);
                        num2 = 1;
                        while (num2 <= num10)
                        {
                            accept = build.AcceptList[num2];
                            if (accept.Priority == priority)
                            {
                                set2.Add(new int[] { accept.SymbolIndex });
                            }
                            else if (accept.Priority < priority)
                            {
                                set2.Clear();
                                set2.Add(new int[] { accept.SymbolIndex });
                                priority = accept.Priority;
                            }
                            num2 = (short)(num2 + 1);
                        }
                        build.AcceptList.Clear();
                        short num11 = (short)(set2.Count() - 1);
                        for (num2 = 0; num2 <= num11; num2 = (short)(num2 + 1))
                        {
                            build.AcceptList.Add((short)set2[num2], priority);
                        }
                        if (set2.Count() == 1)
                        {
                            build.Accept = BuilderApp.BuildTables.Symbol[set2[0]];
                        }
                    }
                }
                CheckErrorsDFA();
                Notify.Completed("DFA States Completed");
            }
        }
Ejemplo n.º 15
0
 public LookaheadSymbol(SymbolBuild Sym)
 {
     this.Parent  = Sym;
     this.Configs = new ConfigTrackSet();
 }
Ejemplo n.º 16
0
 public LookaheadSymbol(LookaheadSymbol Look)
 {
     this.Parent  = Look.Parent;
     this.Configs = new ConfigTrackSet();
     this.Configs.Copy(Look.Configs);
 }